Skip to content

Commit 963a9ff

Browse files
oitofelixskangas
authored andcommitted
Globally sanitize single-file package long descriptions (Bug#37548)
Consistent with multi-file package descriptions which don’t have commentary sections nor double semicolon prefixes. * lisp/emacs-lisp/lisp-mnt.el (lm-commentary): Remove commentary header, double semicolon prefixes of each line, trailing new-lines and trailing white-space from commentary. * lisp/emacs-lisp/package.el (package--get-description) (describe-package-1): * lisp/finder.el (finder-commentary): * lisp/info.el (Info-finder-find-node): Remove ad-hoc sanitation.
1 parent cd2d812 commit 963a9ff

File tree

4 files changed

+21
-44
lines changed

4 files changed

+21
-44
lines changed

lisp/emacs-lisp/lisp-mnt.el

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,18 @@ absent, return nil."
485485
(lm-with-file file
486486
(let ((start (lm-commentary-start)))
487487
(when start
488-
(buffer-substring-no-properties start (lm-commentary-end))))))
488+
(replace-regexp-in-string ; Get rid of...
489+
"[[:blank:]]*$" "" ; trailing white-space
490+
(replace-regexp-in-string
491+
(format "%s\\|%s\\|%s"
492+
;; commentary header
493+
(concat "^;;;[[:blank:]]*\\("
494+
lm-commentary-header
495+
"\\):[[:blank:]\n]*")
496+
"^;;[[:blank:]]*" ; double semicolon prefix
497+
"[[:blank:]\n]*\\'") ; trailing new-lines
498+
"" (buffer-substring-no-properties
499+
start (lm-commentary-end))))))))
489500

490501
(defun lm-homepage (&optional file)
491502
"Return the homepage in file FILE, or current buffer if FILE is nil."

lisp/emacs-lisp/package.el

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2376,18 +2376,9 @@ The description is read from the installed package files."
23762376
result
23772377

23782378
;; Look for Commentary header.
2379-
(let ((mainsrcfile (expand-file-name (format "%s.el" (package-desc-name desc))
2380-
srcdir)))
2381-
(when (file-readable-p mainsrcfile)
2382-
(with-temp-buffer
2383-
(insert (or (lm-commentary mainsrcfile) ""))
2384-
(goto-char (point-min))
2385-
(when (re-search-forward "^;;; Commentary:\n" nil t)
2386-
(replace-match ""))
2387-
(while (re-search-forward "^\\(;+ ?\\)" nil t)
2388-
(replace-match ""))
2389-
(buffer-string))))
2390-
)))
2379+
(lm-commentary (expand-file-name
2380+
(format "%s.el" (package-desc-name desc)) srcdir))
2381+
"")))
23912382

23922383
(defun describe-package-1 (pkg)
23932384
"Insert the package description for PKG.
@@ -2582,16 +2573,10 @@ Helper function for `describe-package'."
25822573
(if built-in
25832574
;; For built-in packages, get the description from the
25842575
;; Commentary header.
2585-
(let ((fn (locate-file (format "%s.el" name) load-path
2586-
load-file-rep-suffixes))
2587-
(opoint (point)))
2588-
(insert (or (lm-commentary fn) ""))
2589-
(save-excursion
2590-
(goto-char opoint)
2591-
(when (re-search-forward "^;;; Commentary:\n" nil t)
2592-
(replace-match ""))
2593-
(while (re-search-forward "^\\(;+ ?\\)" nil t)
2594-
(replace-match ""))))
2576+
(insert (or (lm-commentary (locate-file (format "%s.el" name)
2577+
load-path
2578+
load-file-rep-suffixes))
2579+
""))
25952580

25962581
(if (package-installed-p desc)
25972582
;; For installed packages, get the description from the

lisp/finder.el

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -394,13 +394,6 @@ FILE should be in a form suitable for passing to `locate-library'."
394394
(erase-buffer)
395395
(insert str)
396396
(goto-char (point-min))
397-
(delete-blank-lines)
398-
(goto-char (point-max))
399-
(delete-blank-lines)
400-
(goto-char (point-min))
401-
(while (re-search-forward "^;+ ?" nil t)
402-
(replace-match "" nil nil))
403-
(goto-char (point-min))
404397
(while (re-search-forward "\\<\\([-[:alnum:]]+\\.el\\)\\>" nil t)
405398
(if (locate-library (match-string 1))
406399
(make-text-button (match-beginning 1) (match-end 1)

lisp/info.el

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3780,20 +3780,8 @@ Build a menu of the possible matches."
37803780
;; there is no "nxml.el" (it's nxml-mode.el).
37813781
;; But package.el makes the same assumption.
37823782
;; I think nxml is the only exception - maybe it should be just be renamed.
3783-
(let ((str (ignore-errors (lm-commentary (find-library-name nodename)))))
3784-
(if (null str)
3785-
(insert "Can’t find package description.\n\n")
3786-
(insert
3787-
(with-temp-buffer
3788-
(insert str)
3789-
(goto-char (point-min))
3790-
(delete-blank-lines)
3791-
(goto-char (point-max))
3792-
(delete-blank-lines)
3793-
(goto-char (point-min))
3794-
(while (re-search-forward "^;+ ?" nil t)
3795-
(replace-match "" nil nil))
3796-
(buffer-string))))))))
3783+
(insert (or (ignore-errors (lm-commentary (find-library-name nodename)))
3784+
(insert "Can’t find package description.\n\n"))))))
37973785

37983786
;;;###autoload
37993787
(defun info-finder (&optional keywords)

0 commit comments

Comments
 (0)