diff options
| author | Artur Malabarba | 2015-08-06 11:24:16 +0100 |
|---|---|---|
| committer | Artur Malabarba | 2015-08-06 11:27:37 +0100 |
| commit | 0aec2aaccd8b745fa7214f3edd453c04a04bfba4 (patch) | |
| tree | 29e3ac183ef209cb36a44dad8cb1d77b438def15 | |
| parent | 1be349c628b9fedd6db96dcd5e3d9d1abb60e4d0 (diff) | |
| download | emacs-0aec2aaccd8b745fa7214f3edd453c04a04bfba4.tar.gz emacs-0aec2aaccd8b745fa7214f3edd453c04a04bfba4.zip | |
* lisp/emacs-lisp/package.el: Simplify describe-package-1
(package-help-section-name-face): New face.
(package--print-help-section): New function.
(describe-package-1): Refactor section printing.
(package-make-button): Use face instead of font-lock-face, which
doesn't work on buttons.
| -rw-r--r-- | lisp/emacs-lisp/package.el | 83 |
1 files changed, 49 insertions, 34 deletions
diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el index 492f8cc3e1a..967720881f6 100644 --- a/lisp/emacs-lisp/package.el +++ b/lisp/emacs-lisp/package.el | |||
| @@ -2143,6 +2143,22 @@ will be deleted." | |||
| 2143 | (with-current-buffer standard-output | 2143 | (with-current-buffer standard-output |
| 2144 | (describe-package-1 package))))) | 2144 | (describe-package-1 package))))) |
| 2145 | 2145 | ||
| 2146 | (defface package-help-section-name-face | ||
| 2147 | '((t :inherit (bold font-lock-function-name-face))) | ||
| 2148 | "Face used on section names in package description buffers." | ||
| 2149 | :version "25.1") | ||
| 2150 | |||
| 2151 | (defun package--print-help-section (name &rest strings) | ||
| 2152 | "Print \"NAME: \", right aligned to the 13th column. | ||
| 2153 | If more STRINGS are provided, insert them followed by a newline. | ||
| 2154 | Otherwise no newline is inserted." | ||
| 2155 | (declare (indent 1)) | ||
| 2156 | (insert (make-string (max 0 (- 11 (string-width name))) ?\s) | ||
| 2157 | (propertize (concat name ": ") 'font-lock-face 'package-help-section-name-face)) | ||
| 2158 | (when strings | ||
| 2159 | (apply #'insert strings) | ||
| 2160 | (insert "\n"))) | ||
| 2161 | |||
| 2146 | (declare-function lm-commentary "lisp-mnt" (&optional file)) | 2162 | (declare-function lm-commentary "lisp-mnt" (&optional file)) |
| 2147 | 2163 | ||
| 2148 | (defun describe-package-1 (pkg) | 2164 | (defun describe-package-1 (pkg) |
| @@ -2178,16 +2194,16 @@ will be deleted." | |||
| 2178 | (princ status) | 2194 | (princ status) |
| 2179 | (princ " package.\n\n") | 2195 | (princ " package.\n\n") |
| 2180 | 2196 | ||
| 2181 | (insert " " (propertize "Status" 'font-lock-face 'bold) ": ") | 2197 | (package--print-help-section "Status") |
| 2182 | (cond (built-in | 2198 | (cond (built-in |
| 2183 | (insert (propertize (capitalize status) | 2199 | (insert (propertize (capitalize status) |
| 2184 | 'font-lock-face 'font-lock-builtin-face) | 2200 | 'font-lock-face 'package-status-builtin-face) |
| 2185 | ".")) | 2201 | ".")) |
| 2186 | (pkg-dir | 2202 | (pkg-dir |
| 2187 | (insert (propertize (if (member status '("unsigned" "dependency")) | 2203 | (insert (propertize (if (member status '("unsigned" "dependency")) |
| 2188 | "Installed" | 2204 | "Installed" |
| 2189 | (capitalize status)) | 2205 | (capitalize status)) |
| 2190 | 'font-lock-face 'font-lock-builtin-face)) | 2206 | 'font-lock-face 'package-status-builtin-face)) |
| 2191 | (insert (substitute-command-keys " in ‘")) | 2207 | (insert (substitute-command-keys " in ‘")) |
| 2192 | (let ((dir (abbreviate-file-name | 2208 | (let ((dir (abbreviate-file-name |
| 2193 | (file-name-as-directory | 2209 | (file-name-as-directory |
| @@ -2200,7 +2216,7 @@ will be deleted." | |||
| 2200 | (insert (substitute-command-keys | 2216 | (insert (substitute-command-keys |
| 2201 | "’,\n shadowing a ") | 2217 | "’,\n shadowing a ") |
| 2202 | (propertize "built-in package" | 2218 | (propertize "built-in package" |
| 2203 | 'font-lock-face 'font-lock-builtin-face)) | 2219 | 'font-lock-face 'package-status-builtin-face)) |
| 2204 | (insert (substitute-command-keys "’"))) | 2220 | (insert (substitute-command-keys "’"))) |
| 2205 | (if signed | 2221 | (if signed |
| 2206 | (insert ".") | 2222 | (insert ".") |
| @@ -2229,18 +2245,18 @@ will be deleted." | |||
| 2229 | (t (insert (capitalize status) "."))) | 2245 | (t (insert (capitalize status) "."))) |
| 2230 | (insert "\n") | 2246 | (insert "\n") |
| 2231 | (unless (and pkg-dir (not archive)) ; Installed pkgs don't have archive. | 2247 | (unless (and pkg-dir (not archive)) ; Installed pkgs don't have archive. |
| 2232 | (insert " " (propertize "Archive" 'font-lock-face 'bold) | 2248 | (package--print-help-section "Archive" |
| 2233 | ": " (or archive "n/a") "\n")) | 2249 | (or archive "n/a") "\n")) |
| 2234 | (and version | 2250 | (and version |
| 2235 | (insert " " | 2251 | (package--print-help-section "Version" |
| 2236 | (propertize "Version" 'font-lock-face 'bold) ": " | 2252 | (package-version-join version))) |
| 2237 | (package-version-join version) "\n")) | 2253 | (when desc |
| 2238 | (insert " " (propertize "Summary" 'font-lock-face 'bold) | 2254 | (package--print-help-section "Summary" |
| 2239 | ": " (if desc (package-desc-summary desc)) "\n") | 2255 | (package-desc-summary desc))) |
| 2240 | 2256 | ||
| 2241 | (setq reqs (if desc (package-desc-reqs desc))) | 2257 | (setq reqs (if desc (package-desc-reqs desc))) |
| 2242 | (when reqs | 2258 | (when reqs |
| 2243 | (insert " " (propertize "Requires" 'font-lock-face 'bold) ": ") | 2259 | (package--print-help-section "Requires") |
| 2244 | (let ((first t)) | 2260 | (let ((first t)) |
| 2245 | (dolist (req reqs) | 2261 | (dolist (req reqs) |
| 2246 | (let* ((name (car req)) | 2262 | (let* ((name (car req)) |
| @@ -2259,7 +2275,7 @@ will be deleted." | |||
| 2259 | (insert reason))) | 2275 | (insert reason))) |
| 2260 | (insert "\n"))) | 2276 | (insert "\n"))) |
| 2261 | (when required-by | 2277 | (when required-by |
| 2262 | (insert (propertize "Required by" 'font-lock-face 'bold) ": ") | 2278 | (package--print-help-section "Required by") |
| 2263 | (let ((first t)) | 2279 | (let ((first t)) |
| 2264 | (dolist (pkg required-by) | 2280 | (dolist (pkg required-by) |
| 2265 | (let ((text (package-desc-full-name pkg))) | 2281 | (let ((text (package-desc-full-name pkg))) |
| @@ -2272,11 +2288,11 @@ will be deleted." | |||
| 2272 | (package-desc-name pkg)))) | 2288 | (package-desc-name pkg)))) |
| 2273 | (insert "\n"))) | 2289 | (insert "\n"))) |
| 2274 | (when homepage | 2290 | (when homepage |
| 2275 | (insert " " (propertize "Homepage" 'font-lock-face 'bold) ": ") | 2291 | (package--print-help-section "Homepage") |
| 2276 | (help-insert-xref-button homepage 'help-url homepage) | 2292 | (help-insert-xref-button homepage 'help-url homepage) |
| 2277 | (insert "\n")) | 2293 | (insert "\n")) |
| 2278 | (when keywords | 2294 | (when keywords |
| 2279 | (insert " " (propertize "Keywords" 'font-lock-face 'bold) ": ") | 2295 | (package--print-help-section "Keywords") |
| 2280 | (dolist (k keywords) | 2296 | (dolist (k keywords) |
| 2281 | (package-make-button | 2297 | (package-make-button |
| 2282 | k | 2298 | k |
| @@ -2290,24 +2306,23 @@ will be deleted." | |||
| 2290 | (if bi (list (package--from-builtin bi)))))) | 2306 | (if bi (list (package--from-builtin bi)))))) |
| 2291 | (other-pkgs (delete desc all-pkgs))) | 2307 | (other-pkgs (delete desc all-pkgs))) |
| 2292 | (when other-pkgs | 2308 | (when other-pkgs |
| 2293 | (insert " " (propertize "Other versions" 'font-lock-face 'bold) ": " | 2309 | (package--print-help-section "Other versions" |
| 2294 | (mapconcat | 2310 | (mapconcat (lambda (opkg) |
| 2295 | (lambda (opkg) | 2311 | (let* ((ov (package-desc-version opkg)) |
| 2296 | (let* ((ov (package-desc-version opkg)) | 2312 | (dir (package-desc-dir opkg)) |
| 2297 | (dir (package-desc-dir opkg)) | 2313 | (from (or (package-desc-archive opkg) |
| 2298 | (from (or (package-desc-archive opkg) | 2314 | (if (stringp dir) "installed" dir)))) |
| 2299 | (if (stringp dir) "installed" dir)))) | 2315 | (if (not ov) (format "%s" from) |
| 2300 | (if (not ov) (format "%s" from) | 2316 | (format "%s (%s)" |
| 2301 | (format "%s (%s)" | 2317 | (make-text-button (package-version-join ov) nil |
| 2302 | (make-text-button (package-version-join ov) nil | 2318 | 'font-lock-face 'link |
| 2303 | 'font-lock-face 'link | 2319 | 'follow-link t |
| 2304 | 'follow-link t | 2320 | 'action |
| 2305 | 'action | 2321 | (lambda (_button) |
| 2306 | (lambda (_button) | 2322 | (describe-package opkg))) |
| 2307 | (describe-package opkg))) | 2323 | from)))) |
| 2308 | from)))) | 2324 | other-pkgs ", ") |
| 2309 | other-pkgs ", ") | 2325 | "."))) |
| 2310 | ".\n"))) | ||
| 2311 | 2326 | ||
| 2312 | (insert "\n") | 2327 | (insert "\n") |
| 2313 | 2328 | ||
| @@ -2375,7 +2390,7 @@ will be deleted." | |||
| 2375 | :background "light grey" | 2390 | :background "light grey" |
| 2376 | :foreground "black") | 2391 | :foreground "black") |
| 2377 | 'link))) | 2392 | 'link))) |
| 2378 | (apply 'insert-text-button button-text 'font-lock-face button-face 'follow-link t | 2393 | (apply 'insert-text-button button-text 'face button-face 'follow-link t |
| 2379 | props))) | 2394 | props))) |
| 2380 | 2395 | ||
| 2381 | 2396 | ||