diff options
| author | Matthew Swift | 2003-03-02 16:18:36 +0000 |
|---|---|---|
| committer | Matthew Swift | 2003-03-02 16:18:36 +0000 |
| commit | 3e8737bf4c73679b1be235f3be4dcd77c3b39e0c (patch) | |
| tree | 07725d1c83b5bce6e92f68658399e5496223b37e | |
| parent | 58e91b7793c62879973a58009c0dff61bd0545a7 (diff) | |
| download | emacs-3e8737bf4c73679b1be235f3be4dcd77c3b39e0c.tar.gz emacs-3e8737bf4c73679b1be235f3be4dcd77c3b39e0c.zip | |
(emacs-lisp-docstring-fill-column): New custom variable.
(lisp-fill-paragraph): Use it. Add ?, to `paragraph-separate' so
that first docstring lines ending with a comma are respected. Add
"`(" to same so that function and macro bodies beginning with a
backquote do not get disturbed. Revise the comments.
| -rw-r--r-- | lisp/emacs-lisp/lisp-mode.el | 54 |
1 files changed, 42 insertions, 12 deletions
diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el index 171f059d09f..5b348169e0f 100644 --- a/lisp/emacs-lisp/lisp-mode.el +++ b/lisp/emacs-lisp/lisp-mode.el | |||
| @@ -1055,26 +1055,56 @@ ENDPOS is encountered." | |||
| 1055 | 1055 | ||
| 1056 | ;;;; Lisp paragraph filling commands. | 1056 | ;;;; Lisp paragraph filling commands. |
| 1057 | 1057 | ||
| 1058 | (defcustom emacs-lisp-docstring-fill-column 65 | ||
| 1059 | "Value of `fill-column' to use when filling a docstring. | ||
| 1060 | Any non-integer value means do not use a different value of | ||
| 1061 | `fill-column' when filling docstrings." | ||
| 1062 | :type '(choice (integer) | ||
| 1063 | (const :tag "Use the current `fill-column'" t)) | ||
| 1064 | :group 'lisp) | ||
| 1065 | |||
| 1058 | (defun lisp-fill-paragraph (&optional justify) | 1066 | (defun lisp-fill-paragraph (&optional justify) |
| 1059 | "Like \\[fill-paragraph], but handle Emacs Lisp comments. | 1067 | "Like \\[fill-paragraph], but handle Emacs Lisp comments and docstrings. |
| 1060 | If any of the current line is a comment, fill the comment or the | 1068 | If any of the current line is a comment, fill the comment or the |
| 1061 | paragraph of it that point is in, preserving the comment's indentation | 1069 | paragraph of it that point is in, preserving the comment's indentation |
| 1062 | and initial semicolons." | 1070 | and initial semicolons." |
| 1063 | (interactive "P") | 1071 | (interactive "P") |
| 1064 | (or (fill-comment-paragraph justify) | 1072 | (or (fill-comment-paragraph justify) |
| 1065 | ;; `paragraph-start' is set here (not in the buffer-local | 1073 | ;; Point is on a program line (a line no comment); we are interested |
| 1066 | ;; variable so that `forward-paragraph' et al work as | 1074 | ;; particularly in docstring lines. |
| 1067 | ;; expected) so that filling (doc) strings works sensibly. | 1075 | ;; |
| 1068 | ;; Adding the opening paren to avoid the following sexp being | 1076 | ;; We bind `paragraph-start' and `paragraph-separate' temporarily. They |
| 1069 | ;; filled means that sexps generally aren't filled as normal | 1077 | ;; are buffer-local, but we avoid changing them so that they can be set |
| 1070 | ;; text, which is probably sensible. The `;' and `:' stop the | 1078 | ;; to make `forward-paragraph' and friends do something the user wants. |
| 1071 | ;; filled para at following comment lines and keywords | 1079 | ;; |
| 1072 | ;; (typically in `defcustom'). | 1080 | ;; `paragraph-start': The `(' in the character alternative and the |
| 1081 | ;; left-singlequote plus `(' sequence after the \\| alternative prevent | ||
| 1082 | ;; sexps and backquoted sexps that follow a docstring from being filled | ||
| 1083 | ;; with the docstring. This setting has the consequence of inhibiting | ||
| 1084 | ;; filling many program lines that are not docstrings, which is sensible, | ||
| 1085 | ;; because the user probably asked to fill program lines by accident, or | ||
| 1086 | ;; expecting indentation (perhaps we should try to do indenting in that | ||
| 1087 | ;; case). The `;' and `:' stop the paragraph being filled at following | ||
| 1088 | ;; comment lines and at keywords (e.g., in `defcustom'). Left parens are | ||
| 1089 | ;; escaped to keep font-locking, filling, & paren matching in the source | ||
| 1090 | ;; file happy. | ||
| 1091 | ;; | ||
| 1092 | ;; `paragraph-separate': A clever regexp distinguishes the first line of | ||
| 1093 | ;; a docstring and identifies it as a paragraph separator, so that it | ||
| 1094 | ;; won't be filled. (Since the first line of documentation stands alone | ||
| 1095 | ;; in some contexts, filling should not alter the contents the author has | ||
| 1096 | ;; chosen.) Only the first line of a docstring begins with whitespace | ||
| 1097 | ;; and a quotation mark and ends with a period or (rarely) a comma. | ||
| 1098 | ;; | ||
| 1099 | ;; The `fill-column' is temporarily bound to | ||
| 1100 | ;; `emacs-lisp-docstring-fill-column' if that value is an integer. | ||
| 1073 | (let ((paragraph-start (concat paragraph-start | 1101 | (let ((paragraph-start (concat paragraph-start |
| 1074 | "\\|\\s-*[\(;:\"]")) | 1102 | "\\|\\s-*\\([\(;:\"]\\|`\(\\)")) |
| 1075 | ;; Avoid filling the first line of docstring. | ||
| 1076 | (paragraph-separate | 1103 | (paragraph-separate |
| 1077 | (concat paragraph-separate "\\|\\s-*\".*\\.$"))) | 1104 | (concat paragraph-separate "\\|\\s-*\".*[,\\.]$")) |
| 1105 | (fill-column (if (integerp emacs-lisp-docstring-fill-column) | ||
| 1106 | emacs-lisp-docstring-fill-column | ||
| 1107 | fill-column))) | ||
| 1078 | (fill-paragraph justify)) | 1108 | (fill-paragraph justify)) |
| 1079 | ;; Never return nil. | 1109 | ;; Never return nil. |
| 1080 | t)) | 1110 | t)) |