comparison lisp/emacs-lisp/lisp-mode.el @ 50001:745c2428aae8

(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.
author Matthew Swift <swift@alum.mit.edu>
date Sun, 02 Mar 2003 16:18:36 +0000
parents 0d8b17d428b5
children b4b69a752c69
comparison
equal deleted inserted replaced
50000:8b7db04f3672 50001:745c2428aae8
1053 (indent-sexp endmark) 1053 (indent-sexp endmark)
1054 (set-marker endmark nil)))) 1054 (set-marker endmark nil))))
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))
1081 1111
1082 (defun indent-code-rigidly (start end arg &optional nochange-regexp) 1112 (defun indent-code-rigidly (start end arg &optional nochange-regexp)