I\'m just starting to get a feel for emacs, but I am frustrated with it\'s tendency to not indent when I press the return key. I know if I press C-j it will do it, but I can\'t
copying: move to start, CTRL-space, move to end, ALT-W
pasting: CTRL-y
on unix: left mouse to copy, right mouse to paste
I set the return key to globally act as a new-line-and-intent in my ~/.emacs
file:
(global-set-key "\C-m" 'newline-and-indent)
Works for me.
Try [enter], (kbd "enter") or (read-kbd-macro "enter"), they all do subtly different things ;)
Also, for me copy/pasting just works. Can you try running emacs -q, and see if it works? If it does, it may be a problem with your .emacs.
I also have:
(when window-system
;; use extended compound-text coding for X clipboard
(set-selection-coding-system 'compound-text-with-extensions))
but that might do something else ;)
Have a look at emacswiki - autoindent
As suggested there, put following code in your .emacs
(defun set-newline-and-indent ()
(local-set-key (kbd "RET") 'newline-and-indent))
(add-hook 'c-mode-hook 'set-newline-and-indent)
You can customize the variable C Default Styl. In your emacs go to Options->Customize Emacs->Specific Option, then type c-default-style and set to your choice. By doing this, you don't need to hit TAB. Type from start of the line and as you hit ";" , it will be automatically indented.
Hope this helps
The easy way to do that is to use electric-indent-mode
. If you want to enable it manually, just do
M-x electric-indent-mode
In order to enable it automatically, say the following in your .emacs
:
(electric-indent-mode)
This will be the default in Emacs 24.4.
If you want to indent the whole c/c++ file, you just do
That, btw, works also for xml, python code and other types.