diff options
| -rw-r--r-- | lisp/man.el | 102 |
1 files changed, 51 insertions, 51 deletions
diff --git a/lisp/man.el b/lisp/man.el index ae3b0624d3c..38f158beff0 100644 --- a/lisp/man.el +++ b/lisp/man.el | |||
| @@ -62,7 +62,7 @@ | |||
| 62 | ;; is done in the background. The cleaning commands are configurable. | 62 | ;; is done in the background. The cleaning commands are configurable. |
| 63 | ;; + Syntax is the same as Un*x man | 63 | ;; + Syntax is the same as Un*x man |
| 64 | ;; + Functionality is the same as Un*x man, including "man -k" and | 64 | ;; + Functionality is the same as Un*x man, including "man -k" and |
| 65 | ;; "man <section>, etc. | 65 | ;; "man <section>", etc. |
| 66 | ;; + Provides a manual browsing mode with keybindings for traversing | 66 | ;; + Provides a manual browsing mode with keybindings for traversing |
| 67 | ;; the sections of a manpage, following references in the SEE ALSO | 67 | ;; the sections of a manpage, following references in the SEE ALSO |
| 68 | ;; section, and more. | 68 | ;; section, and more. |
| @@ -93,27 +93,31 @@ Any other value of `Man-notify' is equivalent to `meek'.") | |||
| 93 | "*Reuse a manpage buffer if possible. | 93 | "*Reuse a manpage buffer if possible. |
| 94 | When t, and a manpage buffer already exists with the same invocation, | 94 | When t, and a manpage buffer already exists with the same invocation, |
| 95 | man just indicates the manpage is ready according to the value of | 95 | man just indicates the manpage is ready according to the value of |
| 96 | Man-notify. When nil, it always fires off a background process, putting | 96 | `Man-notify'. When nil, it always fires off a background process, putting |
| 97 | the results in a uniquely named buffer.") | 97 | the results in a uniquely named buffer.") |
| 98 | 98 | ||
| 99 | (defvar Man-downcase-section-letters-p t | 99 | (defvar Man-downcase-section-letters-p t |
| 100 | "*Letters in sections are converted to lower case. | 100 | "*Letters in sections are converted to lower case. |
| 101 | Some Un*x man commands can't handle uppercase letters in sections, for | 101 | Some Un*x man commands can't handle uppercase letters in sections, for |
| 102 | example \"man 2V chmod\", but they are often displayed in the manpage | 102 | example \"man 2V chmod\", but they are often displayed in the manpage |
| 103 | with the upper case letter. When this variable is t, the section | 103 | with the upper case letter. When this variable is t, the section |
| 104 | letter (e.g., \"2V\") is converted to lowercase (e.g., \"2v\") before | 104 | letter (e.g., \"2V\") is converted to lowercase (e.g., \"2v\") before |
| 105 | being sent to the man background process.") | 105 | being sent to the man background process.") |
| 106 | 106 | ||
| 107 | (defvar Man-circular-pages-p t | 107 | (defvar Man-circular-pages-p t |
| 108 | "*If t, the manpage list is treated as circular for traversal.") | 108 | "*If t, the manpage list is treated as circular for traversal.") |
| 109 | 109 | ||
| 110 | ;; I changed this to nil because it is a bad idea | ||
| 111 | ;; to fail to recognize things in other sections. | ||
| 110 | (defvar Man-auto-section-alist | 112 | (defvar Man-auto-section-alist |
| 111 | '((c-mode . ("2" "3")) | 113 | nil |
| 112 | (c++-mode . ("2" "3")) | 114 | ;; '((c-mode . ("2" "3")) |
| 113 | (shell-mode . ("1" "8")) | 115 | ;; (c++-mode . ("2" "3")) |
| 114 | (cmushell-mode . ("1" "8")) | 116 | ;; (c++-c-mode . ("2" "3")) |
| 115 | (text-mode . "1") | 117 | ;; (shell-mode . ("1" "8")) |
| 116 | ) | 118 | ;; (cmushell-mode . ("1" "8")) |
| 119 | ;; (text-mode . "1") | ||
| 120 | ;; ) | ||
| 117 | "*Association list of major modes and their default section numbers. | 121 | "*Association list of major modes and their default section numbers. |
| 118 | List is of the form: (MAJOR-MODE . [SECTION | (SECTION*)]). If current | 122 | List is of the form: (MAJOR-MODE . [SECTION | (SECTION*)]). If current |
| 119 | major mode is not in list, then the default is to check for manpages | 123 | major mode is not in list, then the default is to check for manpages |
| @@ -124,13 +128,13 @@ in all sections.") | |||
| 124 | ("1-UCB" . "")) | 128 | ("1-UCB" . "")) |
| 125 | "*Association list of bogus sections to real section numbers. | 129 | "*Association list of bogus sections to real section numbers. |
| 126 | Some manpages (e.g. the Sun C++ 2.1 manpages) have section numbers in | 130 | Some manpages (e.g. the Sun C++ 2.1 manpages) have section numbers in |
| 127 | their references which Un*x man(1) does not recognize. This | 131 | their references which Un*x `man' does not recognize. This |
| 128 | association list is used to translate those sections, when found, to | 132 | association list is used to translate those sections, when found, to |
| 129 | the associated section number.") | 133 | the associated section number.") |
| 130 | 134 | ||
| 131 | (defvar Man-filter-list | 135 | (defvar Man-filter-list |
| 132 | '(("sed " | 136 | '(("sed " |
| 133 | ("-e 's/.\010//g'" | 137 | (;;"-e 's/.\010//g'" |
| 134 | "-e '/[Nn]o such file or directory/d'" | 138 | "-e '/[Nn]o such file or directory/d'" |
| 135 | "-e '/Reformatting page. Wait... done/d'" | 139 | "-e '/Reformatting page. Wait... done/d'" |
| 136 | "-e '/^\\([A-Z][A-Z.]*([0-9A-Za-z][-0-9A-Za-z+]*)\\).*\\1$/d'" | 140 | "-e '/^\\([A-Z][A-Z.]*([0-9A-Za-z][-0-9A-Za-z+]*)\\).*\\1$/d'" |
| @@ -158,9 +162,9 @@ This variable contains an association list of the following form: | |||
| 158 | '((command-string (phrase-string*))*) | 162 | '((command-string (phrase-string*))*) |
| 159 | 163 | ||
| 160 | Each phrase-string is concatenated onto the command-string to form a | 164 | Each phrase-string is concatenated onto the command-string to form a |
| 161 | command filter. The (standard) output (and standard error) of the Un*x | 165 | command filter. The (standard) output (and standard error) of the Un*x |
| 162 | man command is piped through each command filter in the order the | 166 | man command is piped through each command filter in the order the |
| 163 | commands appear in the association list. The final output is placed in | 167 | commands appear in the association list. The final output is placed in |
| 164 | the manpage buffer.") | 168 | the manpage buffer.") |
| 165 | 169 | ||
| 166 | (defvar Man-mode-line-format | 170 | (defvar Man-mode-line-format |
| @@ -173,10 +177,10 @@ the manpage buffer.") | |||
| 173 | "*Mode line format for manual mode buffer.") | 177 | "*Mode line format for manual mode buffer.") |
| 174 | 178 | ||
| 175 | (defvar Man-mode-map nil | 179 | (defvar Man-mode-map nil |
| 176 | "*Keymap for Man-mode.") | 180 | "*Keymap for Man mode.") |
| 177 | 181 | ||
| 178 | (defvar Man-mode-hooks nil | 182 | (defvar Man-mode-hooks nil |
| 179 | "*Hooks for Man-mode.") | 183 | "*Hooks for Man mode.") |
| 180 | 184 | ||
| 181 | (defvar Man-section-regexp "[0-9][a-zA-Z+]*" | 185 | (defvar Man-section-regexp "[0-9][a-zA-Z+]*" |
| 182 | "*Regular expression describing a manpage section within parentheses.") | 186 | "*Regular expression describing a manpage section within parentheses.") |
| @@ -200,10 +204,6 @@ This regular expression should start with a `^' character.") | |||
| 200 | 204 | ||
| 201 | ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | 205 | ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 202 | ;; end user variables | 206 | ;; end user variables |
| 203 | |||
| 204 | (defconst Man-version-number "1.1" | ||
| 205 | "man's version number.") | ||
| 206 | |||
| 207 | 207 | ||
| 208 | ;; other variables and keymap initializations | 208 | ;; other variables and keymap initializations |
| 209 | (make-variable-buffer-local 'Man-sections-alist) | 209 | (make-variable-buffer-local 'Man-sections-alist) |
| @@ -236,7 +236,6 @@ This regular expression should start with a `^' character.") | |||
| 236 | (define-key Man-mode-map "s" 'Man-goto-see-also-section) | 236 | (define-key Man-mode-map "s" 'Man-goto-see-also-section) |
| 237 | (define-key Man-mode-map "q" 'Man-quit) | 237 | (define-key Man-mode-map "q" 'Man-quit) |
| 238 | (define-key Man-mode-map "m" 'manual-entry) | 238 | (define-key Man-mode-map "m" 'manual-entry) |
| 239 | (define-key Man-mode-map "v" 'Man-version) | ||
| 240 | (define-key Man-mode-map "?" 'describe-mode) | 239 | (define-key Man-mode-map "?" 'describe-mode) |
| 241 | ) | 240 | ) |
| 242 | 241 | ||
| @@ -315,7 +314,7 @@ This regular expression should start with a `^' character.") | |||
| 315 | 314 | ||
| 316 | (defun Man-linepos (&optional position col-p) | 315 | (defun Man-linepos (&optional position col-p) |
| 317 | "Return the character position at various line/buffer positions. | 316 | "Return the character position at various line/buffer positions. |
| 318 | Preserves the state of point, mark, etc. Optional POSITION can be one | 317 | Preserves the state of point, mark, etc. Optional arg POSITION can be one |
| 319 | of the following symbols: | 318 | of the following symbols: |
| 320 | bol == beginning of line | 319 | bol == beginning of line |
| 321 | boi == beginning of indentation | 320 | boi == beginning of indentation |
| @@ -323,7 +322,8 @@ of the following symbols: | |||
| 323 | bob == beginning of buffer | 322 | bob == beginning of buffer |
| 324 | eob == end of buffer | 323 | eob == end of buffer |
| 325 | 324 | ||
| 326 | Optional COL-P non-nil returns current-column instead of character position." | 325 | Optional arg COL-P, if non-nil, means to return |
| 326 | the current column instead of character position." | ||
| 327 | (let ((tpnt (point)) | 327 | (let ((tpnt (point)) |
| 328 | rval) | 328 | rval) |
| 329 | (cond | 329 | (cond |
| @@ -341,7 +341,7 @@ Optional COL-P non-nil returns current-column instead of character position." | |||
| 341 | ;; default man entry and get word under point | 341 | ;; default man entry and get word under point |
| 342 | 342 | ||
| 343 | (defun Man-default-man-args (manword) | 343 | (defun Man-default-man-args (manword) |
| 344 | "Build the default man args from MANWORD and major-mode." | 344 | "Build the default man args from MANWORD and buffer's major mode." |
| 345 | (let ((mode major-mode) | 345 | (let ((mode major-mode) |
| 346 | (slist Man-auto-section-alist)) | 346 | (slist Man-auto-section-alist)) |
| 347 | (while (and slist | 347 | (while (and slist |
| @@ -362,7 +362,7 @@ Optional COL-P non-nil returns current-column instead of character position." | |||
| 362 | (defun Man-default-man-entry () | 362 | (defun Man-default-man-entry () |
| 363 | "Make a guess at a default manual entry. | 363 | "Make a guess at a default manual entry. |
| 364 | This guess is based on the text surrounding the cursor, and the | 364 | This guess is based on the text surrounding the cursor, and the |
| 365 | default section number is selected from Man-auto-section-alist." | 365 | default section number is selected from `Man-auto-section-alist'." |
| 366 | (let ((default-section nil) | 366 | (let ((default-section nil) |
| 367 | default-title) | 367 | default-title) |
| 368 | (save-excursion | 368 | (save-excursion |
| @@ -405,11 +405,11 @@ default section number is selected from Man-auto-section-alist." | |||
| 405 | ;;;###autoload | 405 | ;;;###autoload |
| 406 | (defun manual-entry (arg) | 406 | (defun manual-entry (arg) |
| 407 | "Get a Un*x manual page and put it in a buffer. | 407 | "Get a Un*x manual page and put it in a buffer. |
| 408 | This command is the top-level command in the man package. It runs a Un*x | 408 | This command is the top-level command in the man package. It runs a Un*x |
| 409 | command to retrieve and clean a manpage in the background and places the | 409 | command to retrieve and clean a manpage in the background and places the |
| 410 | results in a Man-mode (manpage browsing) buffer. See variable | 410 | results in a Man mode (manpage browsing) buffer. See variable |
| 411 | Man-notify for what happens when the buffer is ready. | 411 | `Man-notify' for what happens when the buffer is ready. |
| 412 | Universal argument ARG, is passed to Man-getpage-in-background." | 412 | Universal argument ARG, is passed to `Man-getpage-in-background'." |
| 413 | (interactive "P") | 413 | (interactive "P") |
| 414 | (let* ((default-entry (Man-default-man-entry)) | 414 | (let* ((default-entry (Man-default-man-entry)) |
| 415 | (man-args | 415 | (man-args |
| @@ -433,12 +433,13 @@ Universal argument ARG, is passed to Man-getpage-in-background." | |||
| 433 | (Man-getpage-in-background man-args (consp arg)) | 433 | (Man-getpage-in-background man-args (consp arg)) |
| 434 | )) | 434 | )) |
| 435 | 435 | ||
| 436 | (defun Man-getpage-in-background (man-args &optional override-reuse-p) | 436 | (defun Man-getpage-in-background (TOPIC &optional override-reuse-p) |
| 437 | "Uses MAN-ARGS to build and fire off the manpage and cleaning command. | 437 | "Uses TOPIC to build and fire off the manpage and cleaning command. |
| 438 | Optional OVERRIDE-REUSE-P, when supplied non-nil forces man to | 438 | Optional OVERRIDE-REUSE-P, when non-nil, means to |
| 439 | start a background process even if a buffer already exists and | 439 | start a background process even if a buffer already exists and |
| 440 | Man-reuse-okay-p is non-nil." | 440 | `Man-reuse-okay-p' is non-nil." |
| 441 | (let* ((bufname (concat "*man " man-args "*")) | 441 | (let* ((man-args (Man-default-man-args TOPIC)) |
| 442 | (bufname (concat "*man " man-args "*")) | ||
| 442 | (buffer (get-buffer bufname))) | 443 | (buffer (get-buffer bufname))) |
| 443 | (if (and Man-reuse-okay-p | 444 | (if (and Man-reuse-okay-p |
| 444 | (not override-reuse-p) | 445 | (not override-reuse-p) |
| @@ -476,6 +477,17 @@ See the variable `Man-notify' for the different notification behaviors." | |||
| 476 | (message "")) | 477 | (message "")) |
| 477 | )) | 478 | )) |
| 478 | 479 | ||
| 480 | (defun Man-set-fonts () | ||
| 481 | (goto-char (point-min)) | ||
| 482 | (while (re-search-forward "\\(.\b.\\)+" nil t) | ||
| 483 | (let ((st (match-beginning 0)) (en (match-end 0))) | ||
| 484 | (goto-char st) | ||
| 485 | (if window-system | ||
| 486 | (put-text-property st en 'face | ||
| 487 | (if (looking-at "_") 'underline 'bold))) | ||
| 488 | (while (and (< (point) en) (looking-at ".\b")) | ||
| 489 | (replace-match "") (forward-char 1))))) | ||
| 490 | |||
| 479 | (defun Man-bgproc-sentinel (process msg) | 491 | (defun Man-bgproc-sentinel (process msg) |
| 480 | "Manpage background process sentinel." | 492 | "Manpage background process sentinel." |
| 481 | (let ((Man-buffer (process-buffer process)) | 493 | (let ((Man-buffer (process-buffer process)) |
| @@ -507,6 +519,7 @@ See the variable `Man-notify' for the different notification behaviors." | |||
| 507 | (save-window-excursion | 519 | (save-window-excursion |
| 508 | (save-excursion | 520 | (save-excursion |
| 509 | (set-buffer Man-buffer) | 521 | (set-buffer Man-buffer) |
| 522 | (Man-set-fonts) | ||
| 510 | (Man-mode) | 523 | (Man-mode) |
| 511 | (set-buffer-modified-p nil))) | 524 | (set-buffer-modified-p nil))) |
| 512 | (Man-notify-when-ready Man-buffer)) | 525 | (Man-notify-when-ready Man-buffer)) |
| @@ -520,7 +533,7 @@ See the variable `Man-notify' for the different notification behaviors." | |||
| 520 | ;; set up manual mode in buffer and build alists | 533 | ;; set up manual mode in buffer and build alists |
| 521 | 534 | ||
| 522 | (defun Man-mode () | 535 | (defun Man-mode () |
| 523 | "SUPERMAN 1.1: A mode for browsing Un*x manual pages. | 536 | "A mode for browsing Un*x manual pages. |
| 524 | 537 | ||
| 525 | The following man commands are available in the buffer. Try | 538 | The following man commands are available in the buffer. Try |
| 526 | \"\\[describe-key] <key> RET\" for more information: | 539 | \"\\[describe-key] <key> RET\" for more information: |
| @@ -534,7 +547,6 @@ The following man commands are available in the buffer. Try | |||
| 534 | \\[Man-goto-section] Go to a manpage section. | 547 | \\[Man-goto-section] Go to a manpage section. |
| 535 | \\[Man-goto-see-also-section] Jumps to the SEE ALSO manpage section. | 548 | \\[Man-goto-see-also-section] Jumps to the SEE ALSO manpage section. |
| 536 | \\[Man-quit] Deletes the manpage, its buffer, and window. | 549 | \\[Man-quit] Deletes the manpage, its buffer, and window. |
| 537 | \\[Man-version] Prints man's version number. | ||
| 538 | \\[describe-mode] Prints this help text. | 550 | \\[describe-mode] Prints this help text. |
| 539 | 551 | ||
| 540 | The following variables may be of some use. Try | 552 | The following variables may be of some use. Try |
| @@ -555,14 +567,13 @@ Man-heading-regexp Regexp describing section headers. | |||
| 555 | Man-see-also-regexp Regexp for SEE ALSO section (or your equiv). | 567 | Man-see-also-regexp Regexp for SEE ALSO section (or your equiv). |
| 556 | Man-first-heading-regexp Regexp for first heading on a manpage. | 568 | Man-first-heading-regexp Regexp for first heading on a manpage. |
| 557 | Man-reference-regexp Regexp matching a references in SEE ALSO. | 569 | Man-reference-regexp Regexp matching a references in SEE ALSO. |
| 558 | Man-version-number Superman version number. | ||
| 559 | Man-switches Background `man' command switches. | 570 | Man-switches Background `man' command switches. |
| 560 | 571 | ||
| 561 | The following key bindings are currently in effect in the buffer: | 572 | The following key bindings are currently in effect in the buffer: |
| 562 | \\{Man-mode-map}" | 573 | \\{Man-mode-map}" |
| 563 | (interactive) | 574 | (interactive) |
| 564 | (setq major-mode 'Man-mode | 575 | (setq major-mode 'Man-mode |
| 565 | mode-name "Manual" | 576 | mode-name "Man" |
| 566 | buffer-auto-save-file-name nil | 577 | buffer-auto-save-file-name nil |
| 567 | mode-line-format Man-mode-line-format | 578 | mode-line-format Man-mode-line-format |
| 568 | truncate-lines t | 579 | truncate-lines t |
| @@ -686,7 +697,7 @@ Returns t if section is found, nil otherwise." | |||
| 686 | 697 | ||
| 687 | (defun Man-goto-see-also-section () | 698 | (defun Man-goto-see-also-section () |
| 688 | "Move point the the \"SEE ALSO\" section. | 699 | "Move point the the \"SEE ALSO\" section. |
| 689 | Actually the section moved to is described by Man-see-also-regexp." | 700 | Actually the section moved to is described by `Man-see-also-regexp'." |
| 690 | (interactive) | 701 | (interactive) |
| 691 | (if (not (Man-find-section Man-see-also-regexp)) | 702 | (if (not (Man-find-section Man-see-also-regexp)) |
| 692 | (error (concat "No " Man-see-also-regexp | 703 | (error (concat "No " Man-see-also-regexp |
| @@ -694,8 +705,8 @@ Actually the section moved to is described by Man-see-also-regexp." | |||
| 694 | 705 | ||
| 695 | (defun Man-follow-manual-reference (arg) | 706 | (defun Man-follow-manual-reference (arg) |
| 696 | "Get one of the manpages referred to in the \"SEE ALSO\" section. | 707 | "Get one of the manpages referred to in the \"SEE ALSO\" section. |
| 697 | Queries you for the page to retrieve. Of course it does this in the | 708 | Queries you for the page to retrieve. Of course it does this in the |
| 698 | background. Universal argument ARG is passed to Man-getpage-in-background." | 709 | background. Universal argument ARG is passed to `Man-getpage-in-background'." |
| 699 | (interactive "P") | 710 | (interactive "P") |
| 700 | (if (not Man-refpages-alist) | 711 | (if (not Man-refpages-alist) |
| 701 | (error (concat "No references found in current manpage.")) | 712 | (error (concat "No references found in current manpage.")) |
| @@ -768,17 +779,6 @@ background. Universal argument ARG is passed to Man-getpage-in-background." | |||
| 768 | (if Man-circular-pages-p | 779 | (if Man-circular-pages-p |
| 769 | (Man-goto-page (length Man-page-list)) | 780 | (Man-goto-page (length Man-page-list)) |
| 770 | (error "You're looking at the first manpage in the buffer.")))) | 781 | (error "You're looking at the first manpage in the buffer.")))) |
| 771 | |||
| 772 | (defun Man-version (arg) | ||
| 773 | "Show man's version. | ||
| 774 | Universal argument (\\[universal-argument]) ARG inserts version | ||
| 775 | information in the current buffer instead of printing the message in | ||
| 776 | the echo area." | ||
| 777 | (interactive "P") | ||
| 778 | (if (consp arg) | ||
| 779 | (insert "Using Superman version " Man-version-number ".") | ||
| 780 | (message "Using Superman version %s." Man-version-number))) | ||
| 781 | |||
| 782 | 782 | ||
| 783 | (provide 'man) | 783 | (provide 'man) |
| 784 | 784 | ||