Skip to content

Commit 887d468

Browse files
author
Gabor Melis
committed
Add lisp-fill-string-by-source-column
With lisp-fill-string-by-source-column nil (the previous default behaviour): (defgeneric foo () (:documentation "The first line of this indented docstring is roughly as long as the rest. Using this option makes sense to ensure that docstrings are preformatted.")) With lisp-fill-string-by-source-column t: (defgeneric foo () (:documentation "The line of this indented docstring is as roughly as long as long as rest. Use this option to make source code look nice."))
1 parent 65735ce commit 887d468

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

Diff for: lisp/emacs-lisp/lisp-mode.el

+23-8
Original file line numberDiff line numberDiff line change
@@ -1435,6 +1435,16 @@ Any non-integer value means do not use a different value of
14351435
:safe (lambda (x) (or (eq x t) (integerp x)))
14361436
:group 'lisp)
14371437

1438+
(defcustom lisp-fill-string-by-source-column t
1439+
"When true, `lisp-fill-paragraph' fills strings in `lisp-mode' in
1440+
such a way that the resulting source code respects `fill-column'.
1441+
Else, the lines of the string are filled as if the string started
1442+
in column 0. For function docstrings, which are typically
1443+
indented by 3 characters, the difference between the two is
1444+
small."
1445+
:type 'boolean
1446+
:group 'lisp)
1447+
14381448
(defun lisp-fill-paragraph (&optional justify)
14391449
"Like \\[fill-paragraph], but handle Emacs Lisp comments and docstrings.
14401450
If any of the current line is a comment, fill the comment or the
@@ -1501,14 +1511,19 @@ and initial semicolons."
15011511
;; statements that follow the string.
15021512
(when (ppss-string-terminator ppss)
15031513
(goto-char (ppss-comment-or-string-start ppss))
1504-
;; The string may be unterminated -- in that case, don't
1505-
;; narrow.
1506-
(when (ignore-errors
1507-
(progn
1508-
(forward-sexp 1)
1509-
t))
1510-
(narrow-to-region (1+ (ppss-comment-or-string-start ppss))
1511-
(1- (point)))))
1514+
(let ((beginning (save-excursion
1515+
(if lisp-fill-string-by-source-column
1516+
(progn
1517+
(beginning-of-line)
1518+
(point))
1519+
(1+ (point))))))
1520+
;; The string may be unterminated -- in that case, don't
1521+
;; narrow.
1522+
(when (ignore-errors
1523+
(progn
1524+
(forward-sexp 1)
1525+
t))
1526+
(narrow-to-region beginning (1- (point))))))
15121527
;; Move back to where we were.
15131528
(goto-char start)
15141529
;; We should fill the first line of a string

0 commit comments

Comments
 (0)