In emacs, when I type this:
if(true)
{
I get this:
if(true)
{
So then I have to press the left arrow to move back one space, then delete the two extra spaces to get the expected result. Any ideas on how to fix this?
Check what the RET key is bound to in the current mode. Bind it to something else, such as newline.
Or just turn off electric-indent-mode, by putting this in your init file:
(electric-indent-mode -1)
That turns off having RET (the Enter key) automatically indent, in most programming modes.
Related
Even the basic things seem to be hidden behind weird shortcut-combinations.
How can I (hopefully without too many c-m-x-c combinations) create a simple new line?
return evaluates the current line
With C-j. That said, if you have paredit enabled, it should do all the newlines you need automatically.
In my case it was M-j.
I'm currently trying out SpaceMacs, not sure if that has anything to do with it.
Even the basic things seem to be hidden behind weird shortcut-combinations.
If you don't want RET to have contextual behaviour, you can M-x customize-option RET ielm-dynamic-return.
How can I ... create a simple new line?
Only a newline? C-qC-j is the normal way to enter a newline in places where RET does something else. (More generally you can use C-q to insert any character that isn't self-inserting for the current buffer.)
If you want newline + indentation (which is what RET does when contextually appropriate), then M-j will do that (noting that if you are in a comment at the time then the new line will also default to a comment).
Everything is indented normally in my .cpp file until the moment I press the semicolon ; on the following lines --- at which point emacs indents all the way to the full length of the last line typed...
This oddly doesn't happen if I remove the access modifier and declare vars int x and int y for any class or struct..
class Blah {
private int x;
private int y;
private int z;
};
If I highlight the whole field and press < TAB >, Emacs views this as the proper indent for the region. Can't seem to find anything else related on this besides other qs on indent customization
Additional details:
C-h k ; yields this description, so it might have to do with this feature ---- though I don't understand because the indentation described appears to refer to the immediate next newline not the current the cursor is on.
; runs the command c-electric-semi&comma (found in c++-mode-map),
which is an interactive compiled Lisp function in ‘cc-cmds.el’.
It is bound to ,, ;.
(c-electric-semi&comma ARG)
Insert a comma or semicolon.
If ‘c-electric-flag’ is non-nil, point isn’t inside a literal and a
numeric ARG hasn’t been supplied, the command performs several electric
actions:
(a) When the auto-newline feature is turned on (indicated by "/la" on
the mode line) a newline might be inserted. See the variable
‘c-hanging-semi&comma-criteria’ for how newline insertion is determined.
(b) Any auto-newlines are indented. The original line is also
reindented unless ‘c-syntactic-indentation’ is nil.
(c) If auto-newline is turned on, a comma following a brace list or a
semicolon following a defun might be cleaned up, depending on the
settings of ‘c-cleanup-list’.
; is one of many keys that triggers the "correct this line's indentation" command. There's nothing special about ; here, it's just that Emacs normally keeps your indentation right according to the style defined for the file.
As 0x5453 says in a comment, your C++ file is syntactically invalid, and the indenter is trying its best to come up with a reasonable indentation for this incorrect file. If you fix your code to be legal, the indentation will also be resolved.
emacs version "emacs-24.3" on linux
If I am at the start of this line...
a b
(where single spaces are the spaces between the letters)
When I use ctrl-s and then hit the space bar to get the next space, it jumps to the space just before the 'b' instead of the space right after the a. It doesn't behave like this for other characters. It looks like someone went to great lengths to enable this behavior as some sort of feature. But I find it very annoying. How can I shut this off? How can I make it treat spaces like any other character when searching for characters/strings ?
my ~/.emacs does nothing except define keys. inhibit splash and startup screens and change fg/bg colors.
If you press C-h k C-s, you will see the help text for isearch-forward. It contains this section:
Type M-s SPC to toggle whitespace matching.
In incremental searches, a space or spaces normally matches any whitespace
defined by the variable search-whitespace-regexp; see also the variables
isearch-lax-whitespace and isearch-regexp-lax-whitespace.
Use
(customize-set-variable 'search-whitespace-regexp nil)
or use customize to set the variable to nil.
Emacs highlights closing paren when the cursor is on it, and highlights the opening paren when the cursor is after it. That seems to be some sort of "global" behaviour - functions like C-M-b and C-M-f follow the same pattern.
That is ugly (to my taste) and ambiguous: when you read some hairy code and meet smth like ( ... ){ ... } with no space in between - you can't highlight the } by putting the cursor on { and have to jump with C-M-f or put a selection with C-M-space.
Is there a way to change that behaviour?
Try http://www.emacswiki.org/emacs/mic-paren.el, it will highlight both parenthesis. For example:
( ... )<cursor>{ ... }
Here, both ( and } will be highlighted.
Provided a toolset whose forward-commands put cursor at the last visible character of a form.
Where forward-word would stop after
foo bar baz
^ ^
ar-forward-word-atpt would stop
foo bar baz
^ ^ ^
Same with lists.
See also ar-highlight-paren-atpt-mode
Everthing still under construction...
Maybe get the trunk via
bzr branch lp:s-x-emacs-werkstatt
https://launchpad.net/s-x-emacs-werkstatt/
Noob to emacs. I would like to create a shortcut in emacs to insert 4 space from current cursor position and remove 4 white spaces from current cursor position.
May be map it to C > and C <
Can somebody help me with this ?
Thanks in advance
zer0 0ne
You can replicate any key as many times as you want by adding a numeric prefix:
ESC <number> <key>
so you can do:
ESC 4 SPACE
or
ESC 4 BACKSPACE
if you want to make it permanent, define a macro for each and name it, and then assign it to a keystroke. see this for more details:
http://emacswiki.org/emacs/KeyboardMacros
or you make a function, but for this purpose is an overkill, I feel.
-dmg
You can easily map a key or keys to insert or delete spaces if you really want to, but that's not the Emacs Way. Customize c-mode to indent the way you want it to, and then you'll never have to manually tweak indentation again (and when you are looking at someone else's code and want to reindent it the way you like you just have to mark the whole buffer and type M-x indent-region--oh, the power!).
Emacs manual on customizing C mode
Emacs Wiki