Is there a way to make a spell check of comments in C++ codes using emacs?
The lisp-snippet below in .emacs got it to work for me on Ubuntu Linux
(add-hook 'c-mode-common-hook 'flyspell-prog-mode)
There exist alternative setups. But I think you can find them by googling flyspell-prog-mode.
To spell check comments already in the file:
M-x ispell-comments-and-strings
To spell check comments as you type:
M-x flyspell-prog-mode
and the .emacs hooks kindahero suggested.
as mirk said flyspell-prog-mode is the obvious way.
To share my config,
;;; for prog modes turn on flyspell-prog-mode (checks spell only in comments)
(dolist (hook '(lisp-mode-hook
emacs-lisp-mode-hook
ruby-mode-hook
yaml-mode
python-mode-hook
shell-mode-hook
php-mode-hook
css-mode-hook
nxml-mode-hook
crontab-mode-hook
perl-mode-hook
javascript-mode-hook
LaTeX-mode-hook))
(add-hook hook 'flyspell-prog-mode))
Remove those modes you don't use/want.
Edit -> Spelling -> Ispell -> Spell-Check Comments
Related
I'm trying to add a C++ mode hook to add C++11 keywords to the appropriate keyword lists (which are defined in lisp/progmodes/cc-langs.el in the Emacs source code). As a minimal example, I started with c-modifier-kwds and tried adding the following to my .emacs file:
(add-hook 'c++-mode-hook
(lambda ()
(c-lang-defconst c-modifier-kwds
c++
(append '("thread_local" "noexcept")
(c-lang-const c-modifier-kwds))))
t)
(I copied the c-lang-defconst statement from this C++11 mode implementation. However, I don't want to create a whole new mode, I just want to add to the regular C++ mode.)
That didn't work (I didn't really expect it to, either). I also tried the following:
(add-hook 'c++-mode-hook
(lambda ()
(setq (c-lang-defconst c-modifier-kwds)
(append '("thread_local" "noexcept")
(c-lang-const c-modifier-kwds))))
t)
That didn't work either.
What's the right way to do this?
If there is no right way, what's a good hackish way to do this?
I am seeking a plugin to do autocompletion popup for c++ development in emacs. what I have tried are Cedet Semantics and the Autocompletion mode, they are pretty neat in terms of completing the variable and function names as long as I have a few words already. For example, I have a class named foo and a function that returns an integer 1
class foo{
int getInt(){return 1};
};
In the main method, so long as I started typing this
int main(){
foo bar;
bar.get...
}
the plugins have no problem popping up suggestions like bar.getInt(). However, what I am really looking for is something like in Eclipse, as soon as I press the "dot", possible choices could be generated for me. Is that possible in Emacs? Thanks
It depends on your settings of auto-complete & CEDET. It looks like that auto-complete is setup to show possible completions only after several characters will be typed. You can check value of the ac-auto-start variable - if this is a number, then auto-complete will be called after this number of characters.
Another important thing is a what is in your ac-sources variable - for work with CEDET you need to use ac-source-semantic-raw or ac-source-semantic completion source.
To automatic completion after . or -> you can try to use Semantic's built-in completion with something like:
(defun my-c-mode-cedet-hook ()
(local-set-key "." 'semantic-complete-self-insert)
(local-set-key ">" 'semantic-complete-self-insert))
(add-hook 'c-mode-common-hook 'my-c-mode-cedet-hook)
P.S. Had you seen my article on CEDET & C++?
I have found that cedet is really underwhelming, especially under cmake projects.
I would recommend using
https://github.com/Andersbakken/rtags
It underlines errors as you type as well as using smart completions. Just add this to your init file after obtaining the required emacs packages
(require 'rtags)
(require 'popup)
(require 'rtags-ac)
(setq rtags-completions-enabled t)
(rtags-enable-standard-keybindings c-mode-base-map)
(add-hook 'c++-mode-hook
(lambda ()
(setq ac-sources '(ac-source-rtags)
)))
I would like to use the semantic code folding from the cedet package (emacs). I installed the 1.1 version and added the following lines to .emacs:
(load-file "~/software/cedet-1.1/common/cedet.el")
(require 'semantic-tag-folding)
(defun c-folding-hook ()
(global-semantic-tag-folding-mode 1)
(local-set-key (kbd "C-c <left>") 'semantic-tag-folding-fold-block)
(local-set-key (kbd "C-c <right>") 'semantic-tag-folding-show-block)
)
(add-hook 'c-mode-common-hook 'c-folding-hook)
Okay, when I now load a c oder c++ file, nothing happens when using the key bindings or directly running the corresponding commands. What's going wrong? Have I forgotten something?
First, you don't need to have (global-semantic-tag-folding-mode 1) inside defun - it's better to run this command once...
But I think, that main problem is that you hadn't enabled any Semantic feature (see this section in my article) - at least you need to call (semantic-load-enable-minimum-features) after loading of CEDET.
P.S. you code is working for me (I use semantic-load-enable-excessive-code-helpers in my setup)
try adding following line in your emacs config file after (load-file "~/software/cedet-1.1/common/cedet.el") line;
(semantic-load-enable-code-helpers) ; Enable prototype help and smart completion
Does anybody know how to inhibit emacs from indenting the name of functions or classes after a template clause?
Currenty the result is:
template <typename T>
class A {
/* ... */
};
where I would like to have:
template <typename T>
class A {
/* ... */
};
Thank you very much for your help.
EDIT 1
I'm using c++-mode with java as indent style for c++. I customized the c-offset-alist in this way:
(custom-set-variables
;;
'(c-offsets-alist (quote ((case-label . +) (innamespace . 0))))
Go to the class line and hit TAB to perform the (unsolicited) indentation.
Then press Control-CControl-Oto display the indent mode fortopmost-intro-cont`
Press ENTER, then you can change the indent number (3 to 0 for instance).
At the end of your .emacs you can set permanently that instruction:
(c-set-offset 'topmost-intro-cont 0 nil)
There are different styles for indentation for Emacs' C++ mode. Quoting EmacsWiki:
A partial list of the better known C styles:
“gnu”: The default style for GNU projects
“k&r”: What Kernighan and Ritchie, the authors of C used in their book
“bsd”: What BSD developers use, aka “Allman style” after Eric Allman.
“stroustrup”: What Stroustrup, the author of C++ used in his book
“linux”: What the Linux developers use for kernel development
“python”: What Python developers use for extension modules
“java”: The default style for java-mode (see below)
“user”: When you want to define your own style
The c-default-style variable is what you need to change. Perhaps one of them will be what you need. Don't have Emacs right now, so I can't check them out.
I don't know, but I imagine your mode makes a difference. In what mode are you editing? I assume c++-mode cause you have c++ as a tag.
For me, in c++-mode, it turned out like this:
template <typename T>
class A {
/* ... */
};
With the comments indented, but class A not indented.
A couple of different things to check:
I've seen similar issues when editing C++ .h files in C-mode instead of C++-mode. By default, .h files are C-mode, not C++-mode. [You can check this by looking for "C++" or "C" in parenthesis at the bottom of your window.] You can setup emacs to always open .h files as C++ by using the following in your .emacs
(setq auto-mode-alist (append '(("\\.h\\'" . c++-mode)
)
auto-mode-alist
))
The other thing to check is how you have setup your c-default-style. The info page for "CC Mode" goes into a lot more detail on all of the possibilities.
I have played with a lot of code in a repl console, how can I clear it? I would like a fresh one without restarting it. Can that be done?
If you want to clear the current namespace of all temporary variables and functions you declared you can use this one liner (or make a function of it) :
(map #(ns-unmap *ns* %) (keys (ns-interns *ns*)))
or
(ns myutil)
(defn ns-clean
"Remove all internal mappings from a given name space or the current one if no parameter given."
([] (ns-clean *ns*))
([ns] (map #(ns-unmap ns %) (keys (ns-interns ns)))))
(ns mytest)
... make loads of junk ...
(myutil/ns-clean)
... great!!! I can now make all new junk ...
It does not claim to give you a squeaky clean namespace, just one with less of the junk which usually accumulates in a typical repl session.
Use with caution : do not pull the rug from under your feet!
If you are running the repl through a terminal window (eg: Terminal.app on MacOS or xterm/aterm/urxvt etc on linux) then you can type Control-L and it should clear the terminal window and give you a new repl prompt. However all macros/atoms you previously defined are still going to be in memory, so this is just a "Cosmetic" clear.
In EMACS/slime REPLs
C-c C-o clears the last output (in case you've typed something that gave a very long answer)
C-c M-o clears the whole thing
In GNOME terminals, you've got a menu option Terminal/Reset and Clear
The shorcut to clean the whole buffer : C-u C-c C-o
The shortcut to clean the last output : C-c C-o
Note, the old way was : C-c M-o
Also, cider-repl-clear-buffer (which is bound to C-ENTER s-c on my machine)
If you are using Emacs + nREPL, you can either:
Run Mx nrepl-clear-buffer or
Run Cc Mo
If the key binding is not enabled, run Mxnrepl-interaction-mode to enable it. You can find other useful shortcuts in nrepl.el and/or customize the key bindings to fit your needs.
Note: you can find all nREPL's key bindings in your system by running M-x v nrepl-mode-map and following the nrepl.el link.
I use the Emacs command cider-repl-clear-buffer via M-x. One might also use cider-repl-clear-output with a prefix argument: C-u C-c C-o.
It depends what you mean by 'clean'. To remove all namespaces within a 'package' you can use:
(mapv remove-ns
(map symbol
(filter #(.startsWith % "org.mycompany")
(map str (all-ns)))))
For users of the Cursive IDE plugin for IntelliJ IDEA who end up here, like me:
You can "cosmetically" clear the REPL (keeping your def'd symbols etc.) by clicking on this icon at the top of the REPL frame:
There's no default key binding for this, but you can easily add one by opening your preferences, navigating to Keymap > Plugins > Cursive, and adding a binding for "Clear output for current REPL".
Alternatively, you can right-click in the editor and access "Clear output for current REPL" via the REPL commands.