lisp-mnt.el 21 KB

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