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

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.

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)

New to Emacs. When I type ", \" is automatically inserted

As the title states, I'm relatively new to Emacs. I tried out several starter kits but went with Prelude and changed a lot of things around.
Anyway, I've been getting a good handle on everything...until this morning I was working and I typed double-quotes. Normally Emacs would insert a second double quotes right after ("") due to the auto-completion, but I must have accidentally changed something with a keystroke and now when I type ", I get \"\".
Thoughts?
Thank you.
This seems to be an issue with smartparens which prelude installs by default (see the file prelude-programming.el. This behavior is described in detail on smartparens wiki. To ensure that smartparens is causing problems you can can do C-h k" this would print about the command acutally run when " is pressed, if the command is sp--self-insert-command then the following should work
Paste this (setq sp-autoescape-string-quote nil) to your *scratch* buffer, go to the closing parenthesis and do C-xC-e, this will disable the behavior for current emacs session.
To disable the behavior for all future emacs session, assuming that you are using prelude, you will need to add the following to your personal config (basically some file inside /path/to/prelude/personal/).
(setq sp-autoescape-string-quote nil)
This will disable the auto-escaping of the string quotes, completely. If you like this behavior and do not want to disable it completely you can do what #steckerhalter suggests C-q" will insert just one parenthesis.
If the above does not solve the issue then try providing following info in your question which may help us debug the issue,
1) The list minor modes active (this can be obtained by doing C-hm).
2) Output of C-hk"
Hope that helps
this sounds a lot like smartparens (https://github.com/Fuco1/smartparens) which is included in Prelude. usually when you are inside "" then it will escape the quotes:
"hahah \"\" bah"
if you want to get a normal " inside quotes you have to use C-q " or disable smartparens with M-x smartparens-mode
If, as you say in a comment, " is bound to self-insert-command, then when you type " what happens is that a (single, unescaped) " character is inserted.
However, I suspect you have some mode turned on that does something additional whenever a " char is inserted. You mention automatic insertion of a second ", for example. That kind of behavior comes from a mode such as is provided by library smart-parens or electric-pair.
And you mention Prelude.
To find out what part of your init file (~/.emacs) is causing the behavior you see, bisect your init file recursively (first comment-out half, to see which half is responsible, then 3/4, to see which quarter is responsible,...). Then, if you still have a question about the responsible code, ask here, providing that info.
When you describe your problem here, it is important to be specific: what Emacs version, what mode(s), what libraries have you loaded,... Whatever might be pertinent. But first narrow down the problem by bisecting your init file to find the culprit.

my emacs defaults stop working

Emacs was working fine, a few days ago some basic functions stopped working.
Alt+Ctrl+>, Alt+Ctrl+>
go to start/end buffer used to work but now I get an undefined error.
Alt+g+g goto line. It was worked, now I get an undefined error
I can't paste into the mini buffer on search with Alt+y, instead it paste the character that my cursor is on.
No one touched my .emacs file.
What is going on? I used emacs for along time and never had a problem with basic functions or pasting to the mini buffer.
Update:
Latest update on my problem is that everything is working when I use the Esc key instead of the Alt key. I don't know why or how it changes but it has nothing to do with my .emacs file or CapsLock or key pressing mistakes. Has anybody a clue why it changes and how to change it back?
Some things to check:
Is your .emacs file loading at all? Are any of the settings in your .emacs file taking effect? Alternately, try running emacs --load /path/to/your/.emacs. This will load the lisp code in your emacs file. If your settings get loaded now, then you need to move your .emacs into the right location so Emacs can pick it up.
Is another mode unbinding your keys? To check this, go to (for example) your *scratch* buffer, which should be in lisp-interaction-mode, and try a shortcut.
Is your .emacs file broken somehow? Try opening it, and commenting everything out but one binding. Then restart emacs and see what happens. If it works, keep uncommenting out sections (binary search is the way to go) to see what line breaks loading.
Are you sure you're pressing the right keys? Hit C-h c M-g g to run describe-key-briefly to see what keys you're pressing, and what they're currently bound to.
Is something wrong with the lisp code to bind the keys? I know this isn't likely, since it used to work, but try it anyway. Open up your .emacs and go to the line binding M-g g. Put your cursor after the closing parenthesis, then press C-x C-e to evaluate the s-expression containing the binding. Then, try the keyboard shortcut again. If it works, then something isn't loading your .emacs file correctly.
You can open your dot emacs and Alt-x eval-buffer. See if your dot emacs file works, or if there are any bugs.

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.

Make Emacs less aggressive about indentation

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.