Make Emacs less aggressive about indentation - emacs

Emacs reindents the current line whenever I type certain things, like ";" or "//". This is pretty annoying, since there are a whole lot of places where it isn't smart enough to indent correctly.
How do I disable this feature? I still want to be able to indent the line with TAB, but I don't want any source code I type to cause it to reindent.
(I'm using Dylan Moonfire's C# mode, but this probably applies to any cc-mode.)

Try running c-toggle-electric-state to turn off the electric action of these characters.
You can do this as part of a c-mode-common-hook, or toggle the state manually by hitting C-c C-l.

most likely caused by the inline-and-indent 'feature' of c-mode and derivatives. emacswiki has several solutions.

Related

Why is there blank space where there ought be line numbers in Emacs?

I'm using (global-linum-mode t) to present line numbers in Emacs.
This works just fine up-until I use the ctrl + up/down commands (forward-paragraph and backward-paragraph) to navigate a buffer, at which point some line numbers are rendered incorrectly (see attached image).
This occurs only when I use said commands to skip entire segments of code, and the issue immediately disappears (the line numbers are rendered correctly, that is) if I start navigating the buffer by other means.
The issue is present in both C and C++ modes (visualized), and I'm using Emacs 24.3.1 on x86-64 Fedora 19.
While the go-to-line command serves my purposes in terms of navigating compilation errors and warnings, I'd like to keep the line numbers as I find them to be helpful in terms of quickly approximating length of functions.
So far I've found no mention of this problem elsewhere, and I'm unsure of whether or not this is expected behavior of Emacs or if I'm to submit a bug report.
Has anyone encountered the issue or know anything of its origin?
Fix:
The problem may be resolved by invoking (linum-update-current), as portrayed by #lawlist in his answer below. An easy way of repeatedly doing this is to append the command to the execution of forward-paragraph, which may be done using the Emacs Lisp advice feature:
(defadvice forward-paragraph (after forward-paragraph-linum-update)
"Perform (linum-update-current) after jumping forward one
paragraph to ensure line numbers are being rendered
correctly."
(linum-update-current))
(ad-activate 'forward-paragraph)
A few of the lead members on the Emacs development team suggest that linum-mode be avoided for a variety of reasons, and instead they suggest using nlinum-mode: http://elpa.gnu.org/packages/nlinum.html
I personally use a modified version of linum-mode, and I have fixed a few bugs -- if you keep using linum-mode, you will likely need to do the same -- i.e., implement your own bug fixes as you find them. The quickest way to fix the bug you see is to follow your command with:
(linum-update-current)

Indentation in Emacs suddenly stopped working, how do I fix it?

I've been working on this source file for a while, and indenting it just fine, and now suddenly I cannot indent lines by any means (tab, M-x indent-region, etc). Restarting Emacs doesn't fix it, closing and reopening the file doesn't fix it, and the problem seems to be isolated to this particular file.
It's a cpp file if that matters. Yes, I am working in C++ mode. Yes, syntactic indentation is on.
Look at the last part of the file that you edited. Most likely Emacs is in fact indenting, but your source code is such that indenting at the position where you are trying to indent has no effect.
IOW, look at code that precedes the position where you are trying to indent. Look for syntax problems that might be making that position actually appear to be top-level. My guess is that a syntax problem is throwing off the indenting.
You can also narrow the buffer, using C-x n n, to particular parts of the buffer, to see just where indenting does what you expect and where it does not. That will help you find any syntax problems that might be interfering.

Emacs: font-lock explanation

I'm using Emacs since a long time and I've customized it quite a lot. I've even written simple ELisp functions and now I'm starting to use macros more and more. I'm not anywhere near a knowledgable Emacs user but I'm not either a complete beginner.
I'm using nxhtml, mumamo, dired, ido, custom keybindings and so many things I added throughout the years that I don't remember all of them ; )
But there's something I really never understood: what is the "font-lock" mode and why should I care?
For example, I've read that nxhtml and nxml, if I recall correctly, do not use font-locking. Maybe I didn't understand that part well but in either way: what does it change for me, as a user?
Or take for example this description about WhiteSpace:
Note that when WhiteSpace is turned on, WhiteSpace saves the
font-lock state, that is, if font-lock is on or off. And WhiteSpace
restores the font-lock state when it is turned off. So, if WhiteSpace
is turned on and font-lock is off, WhiteSpace also turns on the
font-lock to highlight blanks, but the font-lock will be turned off
when WhiteSpace is turned off. Thus, turn on font-lock before
WhiteSpace is on, if you want that font-lock continues on after
WhiteSpace is turned off.
OK, fine. I understand that. But what does it change if font-lock continues after or not?
Basically I just don't "get it", no matter how much I read about the subject.
Any example/explanation as to what "font-lock" is under Emacs and why it concerns me would be most welcome!
font-lock-mode == colorful syntax highligthing. global-font-lock-mode enables font-locking for each and every mode in Emacs. Older Emacs version required you to enable it manually, newer version (23+ I think) enable this by default. I can't imagine that many people would want to turn off this feature, since it makes some type of content (like source code) immensely more readable. Every mode that uses font-lock relies on a certain set of faces - a combination of font properties like size, bold, underline, italic and color. The basic faces that most modes use are:
font-lock-builtin-face
font-lock-comment-face
font-lock-comment-delimiter-face
font-lock-constant-face
font-lock-doc-face
font-lock-doc-string-face
font-lock-function-name-face
font-lock-keyword-face
font-lock-negation-char-face
font-lock-preprocessor-face
font-lock-string-face
font-lock-type-face
font-lock-variable-name-face
font-lock-warning-face
You can easily override their values if you'd like them (or use a different color-theme). Some modes happen to define additional faces as well.
It displays your code with all the different colors (red for comments, green for class names, etc). If it's off, you get black-and-white code instead. Open up some code and execute M-x font-lock-mode a couple times to watch it switch on and off.

emacs editing Rnw keep region highlighted when highlighting R chunk

When editing an Rnw file in Emacs, I often want to make the region cover a chunk of text that contains an R chunk. For a simple example:
ewr
<<>>=
#
wer
I use transient-mark-mode such that the region is highlighted. But, if I put the point on the first line and hit C-SPC, then use C-n to move the point down, the highlighting disappears when I try to advance the point past the <<. The region I want is still selected, but highlighting seems to fail when crossing the <<. How can I fix this?
Thanks and best regards
I find that your problem shows up when I do what you describe, but it goes away if you scroll down using C-down or C-M-n instead. I think you can even use C-down to get past the R chunk and then C-n to step past lines afterward.
I had the same problem and the solution suggested by fojtasek did not work for me because I had an additional configuration problem. I hope that this might be useful for you and other users. Make sure that if you are using ESS and Auctex that you have fully loaded Auctex. To be more specific, it turned out that when I had previously installed auctex 11.86, I did not correctly load the package. Because I am a novice emacs user, I only managed to load the first of the following two lines:
(load "auctex.el" nil t t)
(load "preview-latex.el" nil t t)
If you have not added the second line, you will only have an Auctex menu but NOT a preview-latex menu.
Thanks to Fojtasek for the C advice. I find C- with the arrow key will keep a contiguous highlight. C-down brings up a page that says "this confusing feature has been disabled by default".
In my opinion, this behavior that OP complained about is a flaw in Auctex, and the fact that Fojtasek has a way to avoid it is helpful, but still it is just a workaround. I don't want Auctex to to this and I don't really want to have to use my left hand for holding down C while scrolling. PITA.
If Auctex needs some special selection tool, they should have to use unusual keystrokes for that. Why impose it on the rest of us who just want to highlight big sections and move them around, whether or not they have <<>> in them.

Why isn't return bound to newline-and-indent by default on emacs

I have tried emacs on and off for a while now and every time I start emacs, I go through the same routine. Customizing. The first one is binding return to newline-and-indent. (g)Vim does this by default. Showing matching parenthesis is also done by default on (g)Vim. It is grea that I can customize emacs to my heart's content but why doesn't emacs have nice and easy defaults? For reference, I am now using Emacs 23 on a RHEL5 box.
Probably because RMS didn't want it, that and because changing long-standing defaults is just an issue of politics. Like vi, Emacs has a hard-core following and basic changes like these are minefields.
Note: if you saved your customizations, then you wouldn't have to re-do them every time...
To have those nice and easy defaults, install Emacs Starter Kit. It enables by default a bunch of useful and convenient features make even the advanced Emacs users more productive.
Otherwise, as TJ pointed out, Emacs Customization Mode (type M-x customize) allows you to save permanently any of the settings. You can even store them in a separate file from your dotemacs―(setq custom-file "~/.emacs-custom.el")―so you can use it in every computer you work on.
The title of your question doesn't really reflect what your question is (and has been answered by Trey and Torok), but I'll tell you why I like it being bound to just newline: useless whitespace. Say you are nested inside a conditional in a function etc. and hit return a couple times to leave a blank line. The blank line now has a bunch of space chars on it. Yes, you can (and I do) remove trailing whitespace before saving, but I also have visual whitespace mode on and I can see it there taunting me.