默认情况下,评论会出现缩进级别,这对我来说似乎很陌生。
(defun example ()
just
some
; a comment
words)
如何调整它以使第一个分号与常规Lisp形式垂直对齐?
(defun example ()
just
some
; a comment
words)
我能发现的是,默认机制的工作方式是将注释与固定列对齐(可通过M-x comment-set-column
查询),并且可以修改comment-indent-function
变量(将其设置为零部分)解决了我的问题)。
答案 0 :(得分:1)
您可以自定义comment-indent-function
而不是comment-indent-default使用您自己的函数。
通过替换最后一行`comment-column'来编写新的 (save-excursion(forward-line -1)(current-indentation))
应该提供一个起点。
答案 1 :(得分:1)
如果从lisp-indent-line
删除单个分号注释的大小写,它将按您的意愿运行。
我已将其删除,您可以将其添加到您的emacs配置中
(defun lisp-indent-line (&optional _whole-exp)
"Indent current line as Lisp code.
With argument, indent any additional lines of the same expression
rigidly along with this one.
Modified to indent single semicolon comments like double semicolon comments"
(interactive "P")
(let ((indent (calculate-lisp-indent)) shift-amt
(pos (- (point-max) (point)))
(beg (progn (beginning-of-line) (point))))
(skip-chars-forward " \t")
(if (or (null indent) (looking-at "\\s<\\s<\\s<"))
;; Don't alter indentation of a ;;; comment line
;; or a line that starts in a string.
;; FIXME: inconsistency: comment-indent moves ;;; to column 0.
(goto-char (- (point-max) pos))
(if (listp indent) (setq indent (car indent)))
(setq shift-amt (- indent (current-column)))
(if (zerop shift-amt)
nil
(delete-region beg (point))
(indent-to indent))
;; If initial point was within line's indentation,
;; position after the indentation. Else stay at same point in text.
(if (> (- (point-max) pos) (point))
(goto-char (- (point-max) pos))))))