comparison lisp/man.el @ 3909:192e7aa8389a

(Man-auto-section-alist): Default value nil. (Man-getpage-in-background): Call Man-default-man-args. (Man-filter-list): Don't discard overstrike here. (Man-set-fonts): New function. (Man-bgproc-sentinel): Call Man-set-fonts. (Man-version-number): Var deleted. (Man-version): Command and binding deleted. (Man-mode): Use Manual, not Man, as official mode name.
author Richard M. Stallman <rms@gnu.org>
date Mon, 28 Jun 1993 19:53:30 +0000
parents 70551a213fae
children 511feb3c2874
comparison
equal deleted inserted replaced
3908:a148b4ff79c6 3909:192e7aa8389a
60 ;; + Runs "man" in the background and pipes the results through a 60 ;; + Runs "man" in the background and pipes the results through a
61 ;; series of sed and awk scripts so that all retrieving and cleaning 61 ;; series of sed and awk scripts so that all retrieving and cleaning
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.
69 ;; + Multiple manpages created with the same man command are put into 69 ;; + Multiple manpages created with the same man command are put into
70 ;; a narrowed buffer circular list. 70 ;; a narrowed buffer circular list.
91 91
92 (defvar Man-reuse-okay-p t 92 (defvar Man-reuse-okay-p t
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
120 in all sections.") 124 in all sections.")
121 125
122 (defvar Man-section-translations-alist 126 (defvar Man-section-translations-alist
123 '(("3C++" . "3") 127 '(("3C++" . "3")
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'"
137 "-e '/^[ \\t]*Hewlett-Packard Company[ \\t]*- [0-9]* -.*$/d'" 141 "-e '/^[ \\t]*Hewlett-Packard Company[ \\t]*- [0-9]* -.*$/d'"
138 "-e '/^[ \\t]*Hewlett-Packard[ \\t]*- [0-9]* -.*$/d'" 142 "-e '/^[ \\t]*Hewlett-Packard[ \\t]*- [0-9]* -.*$/d'"
156 This variable contains an association list of the following form: 160 This variable contains an association list of the following form:
157 161
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
167 '("" mode-line-modified 171 '("" mode-line-modified
168 mode-line-buffer-identification " " 172 mode-line-buffer-identification " "
171 " %[(" mode-name minor-mode-alist mode-line-process ")%]----" 175 " %[(" mode-name minor-mode-alist mode-line-process ")%]----"
172 (-3 . "%p") "-%-") 176 (-3 . "%p") "-%-")
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.")
183 187
184 (defvar Man-heading-regexp "^[A-Z]" 188 (defvar Man-heading-regexp "^[A-Z]"
198 (defvar Man-switches "" 202 (defvar Man-switches ""
199 "*Switches passed to the man command, as a single string.") 203 "*Switches passed to the man command, as a single string.")
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)
210 (make-variable-buffer-local 'Man-refpages-alist) 210 (make-variable-buffer-local 'Man-refpages-alist)
211 (make-variable-buffer-local 'Man-page-list) 211 (make-variable-buffer-local 'Man-page-list)
234 (define-key Man-mode-map "t" 'toggle-truncate-lines) 234 (define-key Man-mode-map "t" 'toggle-truncate-lines)
235 (define-key Man-mode-map "g" 'Man-goto-section) 235 (define-key Man-mode-map "g" 'Man-goto-section)
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
243 242
244 ;; ====================================================================== 243 ;; ======================================================================
313 (concat section " " word)) 312 (concat section " " word))
314 ref)) 313 ref))
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
322 eol == end of line [default] 321 eol == end of line [default]
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
330 ((eq position 'bol) (beginning-of-line)) 330 ((eq position 'bol) (beginning-of-line))
331 ((eq position 'boi) (back-to-indentation)) 331 ((eq position 'boi) (back-to-indentation))
339 339
340 ;; ====================================================================== 340 ;; ======================================================================
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
348 (not (eq (car (car slist)) mode))) 348 (not (eq (car (car slist)) mode)))
349 (setq slist (cdr slist))) 349 (setq slist (cdr slist)))
360 ))))) 360 )))))
361 361
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
369 369
370 ;; Default man entry title is any word the cursor is on, 370 ;; Default man entry title is any word the cursor is on,
403 ;; top level command and background process sentinel 403 ;; top level command and background process sentinel
404 404
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
416 (read-string (format "Manual-entry: %s" 416 (read-string (format "Manual-entry: %s"
417 (if (string= default-entry "") "" 417 (if (string= default-entry "") ""
431 (if Man-downcase-section-letters-p 431 (if Man-downcase-section-letters-p
432 (setq man-args (Man-downcase man-args))) 432 (setq man-args (Man-downcase man-args)))
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)
445 buffer) 446 buffer)
446 (Man-notify-when-ready buffer) 447 (Man-notify-when-ready buffer)
473 (message "Manual buffer %s is ready." (buffer-name man-buffer))) 474 (message "Manual buffer %s is ready." (buffer-name man-buffer)))
474 ((or (eq Man-notify 'meek) 475 ((or (eq Man-notify 'meek)
475 t) 476 t)
476 (message "")) 477 (message ""))
477 )) 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)))))
478 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))
482 (delete-buff nil) 494 (delete-buff nil)
505 (if delete-buff 517 (if delete-buff
506 (kill-buffer Man-buffer) 518 (kill-buffer Man-buffer)
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))
513 526
514 (if err-mess 527 (if err-mess
518 531
519 ;; ====================================================================== 532 ;; ======================================================================
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:
527 540
528 \\[manual-entry] Prompt to retrieve a new manpage. 541 \\[manual-entry] Prompt to retrieve a new manpage.
532 \\[Man-next-section] Jump to next manpage section. 545 \\[Man-next-section] Jump to next manpage section.
533 \\[Man-previous-section] Jump to previous manpage section. 546 \\[Man-previous-section] Jump to previous manpage section.
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
541 \"\\[describe-variable] <variable-name> RET\" for more information: 553 \"\\[describe-variable] <variable-name> RET\" for more information:
542 554
553 Man-section-regexp Regexp describing manpage section letters. 565 Man-section-regexp Regexp describing manpage section letters.
554 Man-heading-regexp Regexp describing section headers. 566 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
569 buffer-read-only t) 580 buffer-read-only t)
570 (buffer-disable-undo (current-buffer)) 581 (buffer-disable-undo (current-buffer))
684 chosen))) 695 chosen)))
685 (Man-find-section (aheadsym Man-sections-alist))) 696 (Man-find-section (aheadsym Man-sections-alist)))
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
693 " section found in current manpage.")))) 704 " section found in current manpage."))))
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."))
702 (aput 'Man-refpages-alist 713 (aput 'Man-refpages-alist
703 (let* ((default (aheadsym Man-refpages-alist)) 714 (let* ((default (aheadsym Man-refpages-alist))
766 (if (> Man-current-page 1) 777 (if (> Man-current-page 1)
767 (Man-goto-page (1- Man-current-page)) 778 (Man-goto-page (1- Man-current-page))
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
785 ;;; man.el ends here 785 ;;; man.el ends here