I'm using python-mode.el, and when I try to indent comments, it always wants to put them all the way to the left. I want them indented in line with the rest of the code. Is there an easy way to achieve this?
Recent python-mode.el comes with a customizable variable
py-indent-comments
When t, comment lines are indented.
get it from
http://launchpad.net/python-mode
Also running python-mode.el and when I tab a comment it cycles through the indentation levels. What version of emacs are you using?
edit getting the behavior you describe if there is a non-space immediately following the #. I always put a space after, but it sounds like a bug to me. I'd ask on the python-mode.el list.
Related
I'm using the most recent version of Emacs on Windows 7. Let's say I type the following code in my .emacs:
;test|
| means the cursor position. Now if I press Enter, the text will be moved to the right and it will look like:
;test
How to disable this feature?
This is done in accordance with the Emacs Lisp style guide:
Comments that start with a single semicolon, ';', should all be aligned to the same column on the right of the source code. Such comments usually explain how the code on that line does its job. For example:
(setq base-version-list ; There was a base
(assoc (substring fn 0 start-vn) ; version to which
file-version-assoc-list)) ; this looks like
; a subversion.
If you use two or more semicolons you will see other behaviour:
Comments that start with two semicolons, ';;', should be aligned to the same level of indentation as the code. Such comments usually describe the purpose of the following lines or the state of the program at that point.
...
Comments that start with three semicolons, ';;;', should start at the left margin. We use them for comments which should be considered a “heading” by Outline minor mode.
...
Comments that start with four semicolons, ';;;;', should be aligned to the left margin and are used for headings of major sections of a program.
The automatic indentation is done by electric-indent-mode. If you wish to disable it entirely, put something like
(electric-indent-mode -1)
in your init file. You could also disable it for specific modes using something like
(electric-indent-local-mode -1)
in the appropriate init hooks.
Simply using two semi-colons as suggested by the style guide should also prevent the behaviour, which will let you benefit from electric-indent-mode on other code.
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)
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.
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.
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.