Emacs Ess Mode - Tabbing for Comment Region

Emacs ESS Mode - Tabbing for Comment Region

Use '###' if you don't want the comments indented. According to the manual,

By default, comments beginning with
‘###’ are aligned to the beginning of
the line. Comments beginning with ‘##’
are aligned to the current level of
indentation for the block containing
the comment. Finally, comments
beginning with ‘#’ are aligned to a
column on the right (the 40th column
by default, but this value is
controlled by the variable
comment-column,) or just after the
expression on the line containing the
comment if it extends beyond the
indentation column.

Emacs ESS Mode TAB stops indenting

Try to add a space after "#".
I don't think ESS-mode handles # as a comment unless you have space after it.

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).

Fix undesirable EMACS tabbing behavior in ESS/Stata

You're right, ESS interprets the trailing / as an indication of line continuation. This is hard-coded into the function ess-continued-statement-p, so to modify the behaviour you have to rewrite the code. The following code (in your .emacs) works for your examples.

(eval-after-load 'ess-mode
'(defun ess-continued-statement-p ()
"this is modified code"
(let ((eol (point)))
(save-excursion
(cond ((memq (preceding-char) '(nil ?\, ?\; ?\} ?\{ ?\]))
nil)
;; ((bolp))
((= (preceding-char) ?\))
(forward-sexp -2)
(looking-at "if\\b[ \t]*(\\|function\\b[ \t]*(\\|for\\b[ \t]*(\\|while\\b[ \t]*("))
((progn (forward-sexp -1)
(and (looking-at "else\\b\\|repeat\\b")
(not (looking-at "else\\s_\\|repeat\\s_"))))
(skip-chars-backward " \t")
(or (bolp)
(= (preceding-char) ?\;)))
(t
(progn (goto-char eol)
(skip-chars-backward " \t")
(or (and (> (current-column) 1)
(save-excursion (backward-char 1)

;;;; Modified code starts here: ;;;;
(or (looking-at "[-:+*><=]")
(and (looking-at "/")
(save-excursion (backward-char 1)
(not (looking-at "*")))))))
;;;; End of modified code ;;;;

(and (> (current-column) 3)
(progn (backward-char 3)
(looking-at "%[^ \t]%")))))))))))

Emacs ESS indent after %%

It's not entirely clear what you want. If only want 2 spaces in continued statements such as those after a pipe, the following should work

(setq ess-offset-continued '(straight 2))

So, indentation would still be default of 4 spaces as set in the C++ style, eg. results would look like

worst <- flights_sml %>%
group_by(year, month, day)

f <- function(x) {
x
}

Otherwise, if you always want 2 space offsets

(setq ess-indent-offset 2)

You can customize these variables in your mode hook, eg.

(defun my-R-hook ()
(setq-local ess-style 'C++)
(setq-local ess-offset-continued '(straight 2)))

See the documentation for ess-offset-continued and ess-style-alist for further details.

emacs ess-indent-or-complete sends newline to R process

I think you solved it yourself, with your GH issue suggestion:
https://github.com/emacs-ess/ESS/issues/1198

I've changed things in my own version of ESS, and will commit after a few days of testing it.

Thank you VERY VERY much for persevering and (I think) finding the fault .. a simple typo inside the internal (ess--command-make-restore-function)

How to indent a buffer in ESS?

As stated by others you could mark the whole buffer C-x h and then indent the region with C-M-\

You could also put something along these lines in your .emacs file:

(defun my-indent-buffer()
(interactive)
(save-excursion
(indent-region (point-min) (point-max))))

(global-set-key "\C-cib" 'my-indent-buffer)

This has the benefit of remembering your point.



Related Topics



Leave a reply



Submit