diff options
| author | Lute Kamstra | 2003-05-23 10:08:34 +0000 |
|---|---|---|
| committer | Lute Kamstra | 2003-05-23 10:08:34 +0000 |
| commit | c7dff41d3f1d1268ac61fbe7f3a025bb1fa985e9 (patch) | |
| tree | cc11e28bfa018e9ebe6966b502d3614aa2cbd97d | |
| parent | ac902a0103097303e91b198a72a1098fe622f6b3 (diff) | |
| download | emacs-c7dff41d3f1d1268ac61fbe7f3a025bb1fa985e9.tar.gz emacs-c7dff41d3f1d1268ac61fbe7f3a025bb1fa985e9.zip | |
Make the description of the library more
accurate.
(lm-any-header): New user option.
(lm-section-start): New function; rewrite of `lm-section-mark'.
(lm-section-mark): Make alias of `lm-section-start'.
(lm-section-end): New function.
(lm-code-start): New function; rewrite of `lm-code-mark'.
(lm-code-mark): Make alias of `lm-code-start'.
(lm-commentary-start): New function; rewrite of
`lm-commentary-mark'.
(lm-commentary-mark): Make alias of `lm-commentary-start'.
(lm-commentary-end): New function.
(lm-history-start): New function; rewrite of `lm-history-mark'.
(lm-history-mark): Make alias of `lm-history-start'.
(lm-commentary): Use `lm-commentary-end' to find the end of the
commentary section.
| -rw-r--r-- | lisp/emacs-lisp/lisp-mnt.el | 97 |
1 files changed, 66 insertions, 31 deletions
diff --git a/lisp/emacs-lisp/lisp-mnt.el b/lisp/emacs-lisp/lisp-mnt.el index bdd174a024f..dfa12f970f7 100644 --- a/lisp/emacs-lisp/lisp-mnt.el +++ b/lisp/emacs-lisp/lisp-mnt.el | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | ;;; lisp-mnt.el --- minor mode for Emacs Lisp maintainers | 1 | ;;; lisp-mnt.el --- utility functions for Emacs Lisp maintainers |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1992, 1994, 1997, 2000, 2001 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 1992, 1994, 1997, 2000, 2001, 2003 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | ;; Author: Eric S. Raymond <esr@snark.thyrsus.com> | 5 | ;; Author: Eric S. Raymond <esr@snark.thyrsus.com> |
| 6 | ;; Maintainer: FSF | 6 | ;; Maintainer: FSF |
| @@ -27,7 +27,7 @@ | |||
| 27 | 27 | ||
| 28 | ;;; Commentary: | 28 | ;;; Commentary: |
| 29 | 29 | ||
| 30 | ;; This minor mode adds some services to Emacs-Lisp editing mode. | 30 | ;; This library adds some services to Emacs-Lisp editing mode. |
| 31 | ;; | 31 | ;; |
| 32 | ;; First, it knows about the header conventions for library packages. | 32 | ;; First, it knows about the header conventions for library packages. |
| 33 | ;; One entry point supports generating synopses from a library directory. | 33 | ;; One entry point supports generating synopses from a library directory. |
| @@ -79,7 +79,7 @@ | |||
| 79 | ;; in this file is mildly bogus because the maintainer line is redundant. | 79 | ;; in this file is mildly bogus because the maintainer line is redundant. |
| 80 | ;; The idea behind these two fields is to be able to write a Lisp function | 80 | ;; The idea behind these two fields is to be able to write a Lisp function |
| 81 | ;; that does "send mail to the author" without having to mine the name out by | 81 | ;; that does "send mail to the author" without having to mine the name out by |
| 82 | ;; hand. Please be careful about surrounding the network address with <> if | 82 | ;; hand. Please be careful about surrounding the network address with <> if |
| 83 | ;; there's also a name in the field. | 83 | ;; there's also a name in the field. |
| 84 | ;; | 84 | ;; |
| 85 | ;; * Created line --- optional, gives the original creation date of the | 85 | ;; * Created line --- optional, gives the original creation date of the |
| @@ -124,7 +124,7 @@ | |||
| 124 | ;;; Variables: | 124 | ;;; Variables: |
| 125 | 125 | ||
| 126 | (defgroup lisp-mnt nil | 126 | (defgroup lisp-mnt nil |
| 127 | "Minor mode for Emacs Lisp maintainers." | 127 | "Utility functions for Emacs Lisp maintainers." |
| 128 | :prefix "lm-" | 128 | :prefix "lm-" |
| 129 | :group 'maint) | 129 | :group 'maint) |
| 130 | 130 | ||
| @@ -156,6 +156,11 @@ Leading comment characters and whitespace should be in regexp group 1." | |||
| 156 | :type 'integer | 156 | :type 'integer |
| 157 | :group 'lisp-mnt) | 157 | :group 'lisp-mnt) |
| 158 | 158 | ||
| 159 | (defcustom lm-any-header ".*" | ||
| 160 | "Regexp which matches start of any section." | ||
| 161 | :type 'regexp | ||
| 162 | :group 'lisp-mnt) | ||
| 163 | |||
| 159 | (defcustom lm-commentary-header "Commentary\\|Documentation" | 164 | (defcustom lm-commentary-header "Commentary\\|Documentation" |
| 160 | "Regexp which matches start of documentation section." | 165 | "Regexp which matches start of documentation section." |
| 161 | :type 'regexp | 166 | :type 'regexp |
| @@ -188,30 +193,65 @@ return section regexp instead." | |||
| 188 | (match-end 1))) | 193 | (match-end 1))) |
| 189 | (match-string-no-properties 1)))) | 194 | (match-string-no-properties 1)))) |
| 190 | 195 | ||
| 191 | (defun lm-section-mark (header &optional after) | 196 | (defun lm-section-start (header &optional after) |
| 192 | "Return the buffer location of a given section start marker. | 197 | "Return the buffer location of a given section start marker. |
| 193 | The HEADER is the section mark string to search for. | 198 | The HEADER is the section mark string to search for. |
| 194 | If AFTER is non-nil, return the location of the next line." | 199 | If AFTER is non-nil, return the location of the next line. |
| 200 | If the given section does not exist, return nil." | ||
| 195 | (save-excursion | 201 | (save-excursion |
| 196 | (let ((case-fold-search t)) | 202 | (let ((case-fold-search t)) |
| 197 | (goto-char (point-min)) | 203 | (goto-char (point-min)) |
| 198 | (if (re-search-forward (lm-get-header-re header 'section) nil t) | 204 | (if (re-search-forward (lm-get-header-re header 'section) nil t) |
| 199 | (progn | 205 | (line-beginning-position (if after 2)))))) |
| 200 | (beginning-of-line) | 206 | (defalias 'lm-section-mark 'lm-section-start) |
| 201 | (if after (forward-line 1)) | 207 | |
| 202 | (point)))))) | 208 | (defun lm-section-end (header) |
| 203 | 209 | "Return the buffer location of the end of a given section. | |
| 204 | (defsubst lm-code-mark () | 210 | The HEADER is the section string marking the beginning of the |
| 211 | section. If the given section does not exist, return nil. | ||
| 212 | |||
| 213 | The end of the section is defined as the beginning of the next | ||
| 214 | section of the same level or lower. The function | ||
| 215 | `lisp-outline-level' is used to compute the level of a section. | ||
| 216 | If no such section exists, return the end of the buffer." | ||
| 217 | (let ((start (lm-section-start header))) | ||
| 218 | (when start | ||
| 219 | (save-excursion | ||
| 220 | (goto-char start) | ||
| 221 | (let ((level (lisp-outline-level)) | ||
| 222 | (case-fold-search t) | ||
| 223 | next-section-found) | ||
| 224 | (beginning-of-line 2) | ||
| 225 | (while (and (setq next-section-found | ||
| 226 | (re-search-forward | ||
| 227 | (lm-get-header-re lm-any-header 'section) | ||
| 228 | nil t)) | ||
| 229 | (> (save-excursion | ||
| 230 | (beginning-of-line) | ||
| 231 | (lisp-outline-level)) | ||
| 232 | level))) | ||
| 233 | (if next-section-found | ||
| 234 | (line-beginning-position) | ||
| 235 | (point-max))))))) | ||
| 236 | |||
| 237 | (defsubst lm-code-start () | ||
| 205 | "Return the buffer location of the `Code' start marker." | 238 | "Return the buffer location of the `Code' start marker." |
| 206 | (lm-section-mark "Code")) | 239 | (lm-section-start "Code")) |
| 240 | (defalias 'lm-code-mark 'lm-code-start) | ||
| 207 | 241 | ||
| 208 | (defsubst lm-commentary-mark () | 242 | (defsubst lm-commentary-start () |
| 209 | "Return the buffer location of the `Commentary' start marker." | 243 | "Return the buffer location of the `Commentary' start marker." |
| 210 | (lm-section-mark lm-commentary-header)) | 244 | (lm-section-start lm-commentary-header)) |
| 245 | (defalias 'lm-commentary-mark 'lm-commentary-start) | ||
| 246 | |||
| 247 | (defsubst lm-commentary-end () | ||
| 248 | "Return the buffer location of the `Commentary' section end." | ||
| 249 | (lm-section-end lm-commentary-header)) | ||
| 211 | 250 | ||
| 212 | (defsubst lm-history-mark () | 251 | (defsubst lm-history-start () |
| 213 | "Return the buffer location of the `History' start marker." | 252 | "Return the buffer location of the `History' start marker." |
| 214 | (lm-section-mark lm-history-header)) | 253 | (lm-section-start lm-history-header)) |
| 254 | (defalias 'lm-history-mark 'lm-history-start) | ||
| 215 | 255 | ||
| 216 | (defsubst lm-copyright-mark () | 256 | (defsubst lm-copyright-mark () |
| 217 | "Return the buffer location of the `Copyright' line." | 257 | "Return the buffer location of the `Copyright' line." |
| @@ -219,8 +259,7 @@ If AFTER is non-nil, return the location of the next line." | |||
| 219 | (let ((case-fold-search t)) | 259 | (let ((case-fold-search t)) |
| 220 | (goto-char (point-min)) | 260 | (goto-char (point-min)) |
| 221 | (if (re-search-forward lm-copyright-prefix nil t) | 261 | (if (re-search-forward lm-copyright-prefix nil t) |
| 222 | (point)))) | 262 | (point))))) |
| 223 | ) | ||
| 224 | 263 | ||
| 225 | (defun lm-header (header) | 264 | (defun lm-header (header) |
| 226 | "Return the contents of the header named HEADER." | 265 | "Return the contents of the header named HEADER." |
| @@ -431,18 +470,14 @@ distribution." | |||
| 431 | 470 | ||
| 432 | (defun lm-commentary (&optional file) | 471 | (defun lm-commentary (&optional file) |
| 433 | "Return the commentary in file FILE, or current buffer if FILE is nil. | 472 | "Return the commentary in file FILE, or current buffer if FILE is nil. |
| 434 | The value is returned as a string. In the file, the commentary starts | 473 | Return the value as a string. In the file, the commentary |
| 435 | with the tag `Commentary' or `Documentation' and ends with one of the | 474 | section starts with the tag `Commentary' or `Documentation' and |
| 436 | tags `Code', `Change Log' or `History'." | 475 | ends just before the next section. If the commentary section is |
| 476 | absent, return nil." | ||
| 437 | (lm-with-file file | 477 | (lm-with-file file |
| 438 | (let ((commentary (lm-commentary-mark)) | 478 | (let ((start (lm-commentary-start))) |
| 439 | (change-log (lm-history-mark)) | 479 | (when start |
| 440 | (code (lm-code-mark))) | 480 | (buffer-substring-no-properties start (lm-commentary-end)))))) |
| 441 | (cond | ||
| 442 | ((and commentary change-log) | ||
| 443 | (buffer-substring-no-properties commentary change-log)) | ||
| 444 | ((and commentary code) | ||
| 445 | (buffer-substring-no-properties commentary code)))))) | ||
| 446 | 481 | ||
| 447 | ;;; Verification and synopses | 482 | ;;; Verification and synopses |
| 448 | 483 | ||