[ESS] How to improve ESS syntax high-lighting and shortcuts
Richard M. Heiberger
rmh at temple.edu
Wed Jun 20 18:44:33 CEST 2007
This is the comment.dwim from newcomment.el in GNU Emacs.
Does it work on Xemacs? If so, you can bind it to the M-; key.
(defun comment-dwim (arg)
"Call the comment command you want (Do What I Mean).
If the region is active and `transient-mark-mode' is on, call
`comment-region' (unless it only consists of comments, in which
case it calls `uncomment-region').
Else, if the current line is empty, insert a comment and indent it.
Else if a prefix ARG is specified, call `comment-kill'.
Else, call `comment-indent'."
(interactive "*P")
(comment-normalize-vars)
(if (and mark-active transient-mark-mode)
(comment-or-uncomment-region (region-beginning) (region-end) arg)
(if (save-excursion (beginning-of-line) (not (looking-at "\\s-*$")))
;; FIXME: If there's no comment to kill on this line and ARG is
;; specified, calling comment-kill is not very clever.
(if arg (comment-kill (and (integerp arg) arg)) (comment-indent))
(let ((add (if arg (prefix-numeric-value arg)
(if (= (length comment-start) 1) comment-add 0))))
;; Some modes insist on keeping column 0 comment in column 0
;; so we need to move away from it before inserting the comment.
(indent-according-to-mode)
(insert (comment-padright comment-start add))
(save-excursion
(unless (string= "" comment-end)
(insert (comment-padleft comment-end add)))
(indent-according-to-mode))))))
More information about the ESS-help
mailing list