Emacs Ruby Method Parameter Indentation

Emacs Ruby method parameter indentation

Dmitry Gutov has posted this fix, using advice, which seems to work:

(defadvice ruby-indent-line (after unindent-closing-paren activate)
(let ((column (current-column))
indent offset)
(save-excursion
(back-to-indentation)
(let ((state (syntax-ppss)))
(setq offset (- column (current-column)))
(when (and (eq (char-after) ?\))
(not (zerop (car state))))
(goto-char (cadr state))
(setq indent (current-indentation)))))
(when indent
(indent-line-to indent)
(when (> offset 0) (forward-char offset)))))

Emacs ruby-mode, indenting wildly inside parentheses?

http://compgroups.net/comp.emacs/Ruby-mode-indentation-of-continuation-lines

(setq ruby-deep-indent-paren nil)

Or temporarily, within the current session:

M-x set-variable RET ruby-deep-indent-paren RET nil RET

Inside of a parentheses it will now indent like it does everywhere else. There is still a minor bug in the case of what I posted above. It indents 2 spaces further than I want it to, because I'm confusing it with the combination of ( and {.

Emacs ruby-mode indent private

Private doesn't introduce a new scope, so indenting definitions under it is not technically correct. While there are several indentation styles for private/protected members, the only one supported by ruby-mode is the one that is semantically correct (doesn't introduce additional nesting). The "Ruby style guide" also recommends that style (not to mention a two 2 space indentation).

That all being said - there's no way to customize this aspect of ruby-mode.

Emacs ruby-mode: (not so) strange indentation for new Rails code conventions

This seems fixed in ruby HEAD

Indentation of groovy style method parameters in emacs

Groovy mode is treating these types of parameters as labels, like case statement labels and the rarely used feature inherited from Java that allows break statements to specify a target.

You can override the indentation by adding this to your hook:

(add-hook 'groovy-mode-hook
(lambda ()
(c-set-offset 'label 4)))

How do I determine why emacs indented a certain amount?

If you're using a mode based on cc-mode (e.g. c-mode, c++-mode, java-mode, etc.), you can hit C-c C-s and it'll tell you what syntactic category the line is. If you want to change it, hit C-c C-o and you'll be guided through the process. Check out the cc-mode docs on customization for more details: https://www.gnu.org/s/emacs/manual/html_node/ccmode/Customizing-Indentation.html

Wrong indentation of comments in Emacs

The major mode should take care of this properly. If not, consider filing an enhancement request or bug report to the maintainers. Of course, "properly" might be in the eye of the beholder. You can try to make your preferences known, however. And check whether the major-mode code might already have user options for this.

Beyond that, the function that is the value of variable comment-indent-function governs this. Normally, this is set by the major mode. You can set it to any function you want (e.g. on the mode hook, so that your definition overrides the one provided by the major-mode code).

It accepts no arguments, and it returns the column you want the comment to be indented to.

Here is code that indents a comment to column 0, for example:

(defun foo () (setq comment-indent-function (lambda () 0)))
(add-hook 'SOME-MODE-HOOK 'foo 'APPEND)

For Emacs-Lisp mode, for example, you would use (add-hook 'emacs-lisp-mode-hook 'foo 'APPEND).



Related Topics



Leave a reply



Submit