lisp-mnt.el 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. ;;; lisp-mnt.el --- utility functions for Emacs Lisp maintainers
  2. ;; Copyright (C) 1992, 1994, 1997, 2000-2017 Free Software Foundation,
  3. ;; Inc.
  4. ;; Author: Eric S. Raymond <esr@snark.thyrsus.com>
  5. ;; Maintainer: emacs-devel@gnu.org
  6. ;; Created: 14 Jul 1992
  7. ;; Keywords: docs
  8. ;; X-Bogus-Bureaucratic-Cruft: Gruad will get you if you don't watch out!
  9. ;; This file is part of GNU Emacs.
  10. ;; GNU Emacs is free software: you can redistribute it and/or modify
  11. ;; it under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation, either version 3 of the License, or
  13. ;; (at your option) any later version.
  14. ;; GNU Emacs is distributed in the hope that it will be useful,
  15. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ;; GNU General Public License for more details.
  18. ;; You should have received a copy of the GNU General Public License
  19. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  20. ;;; Commentary:
  21. ;; This library adds some services to Emacs-Lisp editing mode.
  22. ;;
  23. ;; First, it knows about the header conventions for library packages.
  24. ;; One entry point supports generating synopses from a library directory.
  25. ;; Another can be used to check for missing headers in library files.
  26. ;;
  27. ;; Another entry point automatically addresses bug mail to a package's
  28. ;; maintainer or author.
  29. ;; This file can be loaded by your emacs-lisp-mode-hook. Have it
  30. ;; (require 'lisp-mnt)
  31. ;; This file is an example of the header conventions. Note the following
  32. ;; features:
  33. ;;
  34. ;; * Header line --- makes it possible to extract a one-line summary of
  35. ;; the package's uses automatically for use in library synopses, KWIC
  36. ;; indexes and the like.
  37. ;;
  38. ;; Format is three semicolons, followed by the filename, followed by
  39. ;; three dashes, followed by the summary. All fields space-separated.
  40. ;;
  41. ;; * A blank line
  42. ;;
  43. ;; * Copyright line, which looks more or less like this:
  44. ;;
  45. ;; ;; Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
  46. ;;
  47. ;; * A blank line
  48. ;;
  49. ;; * Author line --- contains the name and net address of at least
  50. ;; the principal author.
  51. ;;
  52. ;; If there are multiple authors, they should be listed on continuation
  53. ;; lines led by ;;<TAB>, like this:
  54. ;;
  55. ;; ;; Author: Ashwin Ram <Ram-Ashwin@cs.yale.edu>
  56. ;; ;; Dave Sill <de5@ornl.gov>
  57. ;; ;; David Lawrence <tale@pawl.rpi.edu>
  58. ;; ;; Noah Friedman <friedman@ai.mit.edu>
  59. ;; ;; Joe Wells <jbw@maverick.uswest.com>
  60. ;; ;; Dave Brennan <brennan@hal.com>
  61. ;; ;; Eric Raymond <esr@snark.thyrsus.com>
  62. ;;
  63. ;; * Maintainer line --- should be a single name/address as in the Author
  64. ;; line, or an address only. If there is no maintainer
  65. ;; line, the person(s) in the Author field are presumed to be it.
  66. ;; The idea behind these two fields is to be able to write a Lisp function
  67. ;; that does "send mail to the author" without having to mine the name out by
  68. ;; hand. Please be careful about surrounding the network address with <> if
  69. ;; there's also a name in the field.
  70. ;;
  71. ;; * Created line --- optional, gives the original creation date of the
  72. ;; file. For historical interest, basically.
  73. ;;
  74. ;; * Version line --- intended to give the reader a clue if they're looking
  75. ;; at a different version of the file than the one they're accustomed to. This
  76. ;; may be an RCS or SCCS header.
  77. ;;
  78. ;; * Adapted-By line --- this was used historically when some files
  79. ;; were added to Emacs. The person named in this field installed and
  80. ;; (possibly adapted) the package in the Emacs distribution.
  81. ;;
  82. ;; * Keywords line --- used by the finder code for finding Emacs
  83. ;; Lisp code related to a topic.
  84. ;;
  85. ;; * X-Bogus-Bureaucratic-Cruft line --- this is a joke and an example
  86. ;; of a comment header. Headers starting with `X-' should never be used
  87. ;; for any real purpose; this is the way to safely add random headers
  88. ;; without invoking the wrath of any program.
  89. ;;
  90. ;; * Commentary line --- enables Lisp code to find the developer's and
  91. ;; maintainers' explanations of the package internals.
  92. ;;
  93. ;; * Change log line --- optional, exists to terminate the commentary
  94. ;; section and start a change-log part, if one exists.
  95. ;;
  96. ;; * Code line --- exists so Lisp can know where commentary and/or
  97. ;; change-log sections end.
  98. ;;
  99. ;; * Footer line --- marks end-of-file so it can be distinguished from
  100. ;; an expanded formfeed or the results of truncation.
  101. ;;; Change Log:
  102. ;; Tue Jul 14 23:44:17 1992 ESR
  103. ;; * Created.
  104. ;;; Code:
  105. ;;; Variables:
  106. (defgroup lisp-mnt nil
  107. "Utility functions for Emacs Lisp maintainers."
  108. :prefix "lm-"
  109. :group 'maint)
  110. ;; At least some of these defcustoms should probably be defconsts,
  111. ;; since they define, or are defined by, the header format. -- fx
  112. (defcustom lm-header-prefix "^;+[ \t]+\\(@(#)\\)?[ \t]*\\$?"
  113. "Prefix that is ignored before the tag.
  114. For example, you can write the 1st line synopsis string and headers like this
  115. in your Lisp package:
  116. ;; @(#) package.el -- package description
  117. ;;
  118. ;; @(#) $Maintainer: Person Foo Bar $
  119. The @(#) construct is used by unix what(1) and
  120. then $identifier: doc string $ is used by GNU ident(1)"
  121. :type 'regexp
  122. :group 'lisp-mnt)
  123. (defcustom lm-copyright-prefix "^\\(;+[ \t]\\)+Copyright (C) "
  124. "Prefix that is ignored before the dates in a copyright.
  125. Leading comment characters and whitespace should be in regexp group 1."
  126. :type 'regexp
  127. :group 'lisp-mnt)
  128. (defcustom lm-comment-column 16
  129. "Column used for placing formatted output."
  130. :type 'integer
  131. :group 'lisp-mnt)
  132. (defcustom lm-any-header ".*"
  133. "Regexp which matches start of any section."
  134. :type 'regexp
  135. :group 'lisp-mnt)
  136. (defcustom lm-commentary-header "Commentary\\|Documentation"
  137. "Regexp which matches start of documentation section."
  138. :type 'regexp
  139. :group 'lisp-mnt)
  140. (defcustom lm-history-header "Change ?Log\\|History"
  141. "Regexp which matches the start of code log section."
  142. :type 'regexp
  143. :group 'lisp-mnt)
  144. ;;; Functions:
  145. ;; These functions all parse the headers of the current buffer
  146. (defun lm-get-header-re (header &optional mode)
  147. "Return regexp for matching HEADER.
  148. If called with optional MODE and with value `section',
  149. return section regexp instead."
  150. (if (eq mode 'section)
  151. (concat "^;;;;* \\(" header "\\):[ \t]*$")
  152. (concat lm-header-prefix "\\(" header "\\)[ \t]*:[ \t]*")))
  153. (defun lm-get-package-name ()
  154. "Return package name by looking at the first line."
  155. (save-excursion
  156. (goto-char (point-min))
  157. (if (and (looking-at (concat lm-header-prefix))
  158. (progn (goto-char (match-end 0))
  159. (looking-at "\\([^\t ]+\\)")
  160. (match-end 1)))
  161. (match-string-no-properties 1))))
  162. (defun lm-section-start (header &optional after)
  163. "Return the buffer location of a given section start marker.
  164. The HEADER is the section mark string to search for.
  165. If AFTER is non-nil, return the location of the next line.
  166. If the given section does not exist, return nil."
  167. (save-excursion
  168. (let ((case-fold-search t))
  169. (goto-char (point-min))
  170. (if (re-search-forward (lm-get-header-re header 'section) nil t)
  171. (line-beginning-position (if after 2))))))
  172. (defalias 'lm-section-mark 'lm-section-start)
  173. (defun lm-section-end (header)
  174. "Return the buffer location of the end of a given section.
  175. The HEADER is the section string marking the beginning of the
  176. section. If the given section does not exist, return nil.
  177. The section ends before the first non-comment text or the next
  178. section of the same level or lower; whatever comes first. The
  179. function `lisp-outline-level' is used to compute the level of
  180. a section."
  181. (require 'outline) ;; for outline-regexp.
  182. (let ((start (lm-section-start header)))
  183. (when start
  184. (save-excursion
  185. (goto-char start)
  186. (let ((level (lisp-outline-level))
  187. (case-fold-search t)
  188. next-section-found)
  189. (beginning-of-line 2)
  190. (while (and (setq next-section-found
  191. (re-search-forward
  192. (lm-get-header-re lm-any-header 'section)
  193. nil t))
  194. (> (save-excursion
  195. (beginning-of-line)
  196. (lisp-outline-level))
  197. level)))
  198. (min (if next-section-found
  199. (progn (beginning-of-line 0)
  200. (unless (looking-at " ")
  201. (beginning-of-line 2))
  202. (point))
  203. (point-max))
  204. (progn (goto-char start)
  205. (while (forward-comment 1))
  206. (point))))))))
  207. (defsubst lm-code-start ()
  208. "Return the buffer location of the `Code' start marker."
  209. (lm-section-start "Code"))
  210. (defalias 'lm-code-mark 'lm-code-start)
  211. (defsubst lm-commentary-start ()
  212. "Return the buffer location of the `Commentary' start marker."
  213. (lm-section-start lm-commentary-header))
  214. (defalias 'lm-commentary-mark 'lm-commentary-start)
  215. (defsubst lm-commentary-end ()
  216. "Return the buffer location of the `Commentary' section end."
  217. (lm-section-end lm-commentary-header))
  218. (defsubst lm-history-start ()
  219. "Return the buffer location of the `History' start marker."
  220. (lm-section-start lm-history-header))
  221. (defalias 'lm-history-mark 'lm-history-start)
  222. (defsubst lm-copyright-mark ()
  223. "Return the buffer location of the `Copyright' line."
  224. (save-excursion
  225. (let ((case-fold-search t))
  226. (goto-char (point-min))
  227. (if (re-search-forward lm-copyright-prefix nil t)
  228. (point)))))
  229. (defun lm-header (header)
  230. "Return the contents of the header named HEADER."
  231. (goto-char (point-min))
  232. (let ((case-fold-search t))
  233. (when (and (re-search-forward (lm-get-header-re header) (lm-code-mark) t)
  234. ;; RCS ident likes format "$identifier: data$"
  235. (looking-at
  236. (if (save-excursion
  237. (skip-chars-backward "^$" (match-beginning 0))
  238. (= (point) (match-beginning 0)))
  239. "[^\n]+" "[^$\n]+")))
  240. (match-string-no-properties 0))))
  241. (defun lm-header-multiline (header)
  242. "Return the contents of the header named HEADER, with continuation lines.
  243. The returned value is a list of strings, one per line."
  244. (save-excursion
  245. (goto-char (point-min))
  246. (let ((res (lm-header header)))
  247. (when res
  248. (setq res (list res))
  249. (forward-line 1)
  250. (while (looking-at "^;+\\(\t\\|[\t\s]\\{2,\\}\\)\\(.+\\)")
  251. (push (match-string-no-properties 2) res)
  252. (forward-line 1)))
  253. (nreverse res))))
  254. ;; These give us smart access to the header fields and commentary
  255. (defmacro lm-with-file (file &rest body)
  256. "Execute BODY in a buffer containing the contents of FILE.
  257. If FILE is nil, execute BODY in the current buffer."
  258. (declare (indent 1) (debug t))
  259. (let ((filesym (make-symbol "file")))
  260. `(let ((,filesym ,file))
  261. (if ,filesym
  262. (with-temp-buffer
  263. (insert-file-contents ,filesym)
  264. (emacs-lisp-mode)
  265. ,@body)
  266. (save-excursion
  267. (save-restriction
  268. (widen)
  269. (goto-char (point-min))
  270. ;; Switching major modes is too drastic, so just switch
  271. ;; temporarily to the Emacs Lisp mode syntax table.
  272. (with-syntax-table emacs-lisp-mode-syntax-table
  273. ,@body)))))))
  274. ;; Fixme: Probably this should be amalgamated with copyright.el; also
  275. ;; we need a check for ranges in copyright years.
  276. (defun lm-crack-copyright (&optional file)
  277. "Return the copyright holder, and a list of copyright years.
  278. Use the current buffer if FILE is nil.
  279. Return argument is of the form (\"HOLDER\" \"YEAR1\" ... \"YEARN\")"
  280. (lm-with-file file
  281. (goto-char (lm-copyright-mark))
  282. (let ((holder nil)
  283. (years nil)
  284. (start (point))
  285. (end (line-end-position)))
  286. ;; Cope with multi-line copyright `lines'. Assume the second
  287. ;; line is indented at least as much as the original, with the
  288. ;; same commenting style.
  289. (save-excursion
  290. (beginning-of-line 2)
  291. (let ((str (match-string-no-properties 1)))
  292. (beginning-of-line)
  293. (while (and (looking-at str) (not (looking-at lm-copyright-prefix)))
  294. (setq end (line-end-position))
  295. (beginning-of-line 2))))
  296. ;; Make a single line and parse that.
  297. (let ((buff (current-buffer)))
  298. (with-temp-buffer
  299. (insert-buffer-substring buff start end)
  300. (goto-char (point-min))
  301. (while (re-search-forward "^;+[ \t]+" nil t)
  302. (replace-match ""))
  303. (goto-char (point-min))
  304. (while (re-search-forward " *\n" nil t)
  305. (replace-match " "))
  306. (goto-char (point-min))
  307. (while (re-search-forward "\\([0-9]+\\),? +" nil t)
  308. (setq years (cons (match-string-no-properties 1) years)))
  309. (if (looking-at ".*$")
  310. (setq holder (match-string-no-properties 0)))))
  311. (cons holder (nreverse years)))))
  312. (defun lm-summary (&optional file)
  313. "Return the one-line summary of file FILE, or current buffer if FILE is nil."
  314. (lm-with-file file
  315. (goto-char (point-min))
  316. (if (and (looking-at lm-header-prefix)
  317. (progn (goto-char (match-end 0))
  318. (looking-at "[^ ]+[ \t]+--+[ \t]+\\(.*\\)")))
  319. (let ((summary (match-string-no-properties 1)))
  320. ;; Strip off -*- specifications.
  321. (if (string-match "[ \t]*-\\*-.*-\\*-" summary)
  322. (substring summary 0 (match-beginning 0))
  323. summary)))))
  324. (defun lm-crack-address (x)
  325. "Split up an email address X into full name and real email address.
  326. The value is a cons of the form (FULLNAME . ADDRESS)."
  327. (cond ((string-match "\\(.+\\) [(<]\\(\\S-+@\\S-+\\)[>)]" x)
  328. (cons (match-string 1 x)
  329. (match-string 2 x)))
  330. ((string-match "\\(\\S-+@\\S-+\\) [(<]\\(.*\\)[>)]" x)
  331. (cons (match-string 2 x)
  332. (match-string 1 x)))
  333. ((string-match "\\S-+@\\S-+" x)
  334. (cons nil x))
  335. (t
  336. (cons x nil))))
  337. (defun lm-authors (&optional file)
  338. "Return the author list of file FILE, or current buffer if FILE is nil.
  339. Each element of the list is a cons; the car is the full name,
  340. the cdr is an email address."
  341. (lm-with-file file
  342. (let ((authorlist (lm-header-multiline "author")))
  343. (mapcar 'lm-crack-address authorlist))))
  344. (defun lm-maintainer (&optional file)
  345. "Return the maintainer of file FILE, or current buffer if FILE is nil.
  346. The return value has the form (NAME . ADDRESS)."
  347. (lm-with-file file
  348. (let ((maint (lm-header "maintainer")))
  349. (if maint
  350. (lm-crack-address maint)
  351. (car (lm-authors))))))
  352. (defun lm-creation-date (&optional file)
  353. "Return the created date given in file FILE, or current buffer if FILE is nil."
  354. (lm-with-file file
  355. (lm-header "created")))
  356. (defun lm-last-modified-date (&optional file iso-date)
  357. "Return the modify-date given in file FILE, or current buffer if FILE is nil.
  358. ISO-DATE non-nil means return the date in ISO 8601 format."
  359. (lm-with-file file
  360. (when (progn (goto-char (point-min))
  361. (re-search-forward
  362. "\\$[I]d: [^ ]+ [^ ]+ \\([^/]+\\)/\\([^/]+\\)/\\([^ ]+\\) "
  363. (lm-code-mark) t))
  364. (let ((dd (match-string 3))
  365. (mm (match-string 2))
  366. (yyyy (match-string 1)))
  367. (if iso-date
  368. (format "%s-%s-%s" yyyy mm dd)
  369. (format "%s %s %s"
  370. dd
  371. (nth (string-to-number mm)
  372. '("" "Jan" "Feb" "Mar" "Apr" "May" "Jun"
  373. "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"))
  374. yyyy))))))
  375. (defun lm-version (&optional file)
  376. "Return the version listed in file FILE, or current buffer if FILE is nil.
  377. This can be found in an RCS or SCCS header."
  378. (lm-with-file file
  379. (or (lm-header "version")
  380. (let ((header-max (lm-code-mark)))
  381. (goto-char (point-min))
  382. (cond
  383. ;; Look for an RCS header
  384. ((re-search-forward "\\$[I]d: [^ ]+ \\([^ ]+\\) " header-max t)
  385. (match-string-no-properties 1))
  386. ((re-search-forward "\\$Revision: +\\([^ ]+\\) " header-max t)
  387. (match-string-no-properties 1))
  388. ;; Look for an SCCS header
  389. ((re-search-forward
  390. (concat
  391. "@(#)"
  392. (if buffer-file-name
  393. (regexp-quote (file-name-nondirectory buffer-file-name))
  394. "[^\t\n]+")
  395. "\t\\([012345679.]*\\)")
  396. header-max t)
  397. (match-string-no-properties 1)))))))
  398. (defun lm-keywords (&optional file)
  399. "Return the keywords given in file FILE, or current buffer if FILE is nil.
  400. The return is a `downcase'-ed string, or nil if no keywords
  401. header. Multi-line keywords are joined up with a space between
  402. each line."
  403. (lm-with-file file
  404. (let ((keywords (lm-header-multiline "keywords")))
  405. (and keywords
  406. (mapconcat 'downcase keywords " ")))))
  407. (defun lm-keywords-list (&optional file)
  408. "Return list of keywords given in file FILE."
  409. (let ((keywords (lm-keywords file)))
  410. (if keywords
  411. (if (string-match-p "," keywords)
  412. (split-string keywords ",[ \t\n]*" t "[ ]+")
  413. (split-string keywords "[ \t\n]+" t "[ ]+")))))
  414. (defvar finder-known-keywords)
  415. (defun lm-keywords-finder-p (&optional file)
  416. "Return non-nil if any keywords in FILE are known to finder."
  417. (require 'finder)
  418. (let ((keys (lm-keywords-list file)))
  419. (catch 'keyword-found
  420. (while keys
  421. (if (assoc (intern (car keys)) finder-known-keywords)
  422. (throw 'keyword-found t))
  423. (setq keys (cdr keys)))
  424. nil)))
  425. (defun lm-adapted-by (&optional file)
  426. "Return the adapted-by names in file FILE, or current buffer if FILE is nil.
  427. This is the name of the person who cleaned up this package for
  428. distribution."
  429. (lm-with-file file
  430. (lm-header "adapted-by")))
  431. (defun lm-commentary (&optional file)
  432. "Return the commentary in file FILE, or current buffer if FILE is nil.
  433. Return the value as a string. In the file, the commentary
  434. section starts with the tag `Commentary' or `Documentation' and
  435. ends just before the next section. If the commentary section is
  436. absent, return nil."
  437. (lm-with-file file
  438. (let ((start (lm-commentary-start)))
  439. (when start
  440. (buffer-substring-no-properties start (lm-commentary-end))))))
  441. (defun lm-homepage (&optional file)
  442. "Return the homepage in file FILE, or current buffer if FILE is nil."
  443. (let ((page (lm-with-file file
  444. (lm-header "\\(?:x-\\)?\\(?:homepage\\|url\\)"))))
  445. (if (and page (string-match "^<.+>$" page))
  446. (substring page 1 -1)
  447. page)))
  448. ;;; Verification and synopses
  449. (defun lm-insert-at-column (col &rest strings)
  450. "Insert, at column COL, list of STRINGS."
  451. (if (> (current-column) col) (insert "\n"))
  452. (move-to-column col t)
  453. (apply 'insert strings))
  454. (defun lm-verify (&optional file showok verbose non-fsf-ok)
  455. "Check that the current buffer (or FILE if given) is in proper format.
  456. If FILE is a directory, recurse on its files and generate a report in a
  457. temporary buffer. In that case, the optional argument SHOWOK
  458. says display \"OK\" in temp buffer for files that have no problems.
  459. Optional argument VERBOSE specifies verbosity level.
  460. Optional argument NON-FSF-OK if non-nil means a non-FSF
  461. copyright notice is allowed."
  462. (interactive (list nil nil t))
  463. (let* ((ret (and verbose "Ok"))
  464. name)
  465. (if (and file (file-directory-p file))
  466. (setq ret
  467. (with-temp-buffer
  468. (dolist (f (directory-files file nil "\\.el\\'")
  469. (buffer-string))
  470. (when (file-regular-p f)
  471. (let ((status (lm-verify f)))
  472. (insert f ":")
  473. (if status
  474. (lm-insert-at-column lm-comment-column status
  475. "\n")
  476. (if showok
  477. (lm-insert-at-column lm-comment-column
  478. "OK\n"))))))))
  479. (lm-with-file file
  480. (setq name (lm-get-package-name))
  481. (setq ret
  482. (cond
  483. ((null name)
  484. "Can't find package name")
  485. ((not (lm-authors))
  486. "`Author:' tag missing")
  487. ((not (lm-maintainer))
  488. "`Maintainer:' tag missing")
  489. ((not (lm-summary))
  490. "Can't find the one-line summary description")
  491. ((not (lm-keywords))
  492. "`Keywords:' tag missing")
  493. ((not (lm-keywords-finder-p))
  494. "`Keywords:' has no valid finder keywords (see `finder-known-keywords')")
  495. ((not (lm-commentary-mark))
  496. "Can't find a `Commentary' section marker")
  497. ((not (lm-history-mark))
  498. "Can't find a `History' section marker")
  499. ((not (lm-code-mark))
  500. "Can't find a `Code' section marker")
  501. ((progn
  502. (goto-char (point-max))
  503. (not
  504. (re-search-backward
  505. (concat "^;;;[ \t]+" name "[ \t]+ends here[ \t]*$"
  506. "\\|^;;;[ \t]+ End of file[ \t]+" name)
  507. nil t)))
  508. "Can't find the footer line")
  509. ((not (and (lm-copyright-mark) (lm-crack-copyright)))
  510. "Can't find a valid copyright notice")
  511. ((not (or non-fsf-ok
  512. (string-match "Free Software Foundation"
  513. (car (lm-crack-copyright)))))
  514. "Copyright holder is not the Free Software Foundation")
  515. (t
  516. ret)))))
  517. (if verbose
  518. (message "%s" ret))
  519. ret))
  520. (defun lm-synopsis (&optional file showall)
  521. "Generate a synopsis listing for the buffer or the given FILE if given.
  522. If FILE is a directory, recurse on its files and generate a report in
  523. a temporary buffer. If SHOWALL is non-nil, also generate a line for files
  524. which do not include a recognizable synopsis."
  525. (interactive
  526. (list
  527. (read-file-name "Synopsis for (file or dir): ")))
  528. (if (and file (file-directory-p file))
  529. (with-output-to-temp-buffer "*Synopsis*"
  530. (set-buffer standard-output)
  531. (dolist (f (directory-files file nil ".*\\.el\\'"))
  532. (let ((syn (lm-synopsis (expand-file-name f file))))
  533. (when (or syn showall)
  534. (insert f ":")
  535. (lm-insert-at-column lm-comment-column (or syn "NA") "\n")))))
  536. (save-excursion
  537. (let ((must-kill (and file (not (get-file-buffer file)))))
  538. (when file (find-file file))
  539. (prog1
  540. (if (called-interactively-p 'interactive)
  541. (message "%s" (lm-summary))
  542. (lm-summary))
  543. (when must-kill (kill-buffer (current-buffer))))))))
  544. (defvar report-emacs-bug-address)
  545. (defun lm-report-bug (topic)
  546. "Report a bug in the package currently being visited to its maintainer.
  547. Prompts for bug subject TOPIC. Leaves you in a mail buffer."
  548. (interactive "sBug Subject: ")
  549. (require 'emacsbug)
  550. (let ((package (lm-get-package-name))
  551. (addr (lm-maintainer))
  552. (version (lm-version)))
  553. (compose-mail (if addr
  554. (concat (car addr) " <" (cdr addr) ">")
  555. report-emacs-bug-address)
  556. topic)
  557. (goto-char (point-max))
  558. (insert "\nIn " package)
  559. (if version
  560. (insert " version " version))
  561. (newline 2)
  562. (message "%s"
  563. (substitute-command-keys "Type \\[mail-send] to send bug report."))))
  564. (provide 'lisp-mnt)
  565. ;;; lisp-mnt.el ends here