1 ;;; man.el --- browse UNIX manual pages
3 ;; Copyright (C) 1993 Free Software Foundation, Inc.
5 ;; Author: Barry A. Warsaw <bwarsaw@cen.com>
6 ;; Last-Modified: 31-Jul-1991
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to
25 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
29 ;; This code provides a function, manual-entry, with which you can
30 ;; browse UNIX manual pages. Formatting is done in background so that
31 ;; you can continue to use your Emacs while processing is going on.
33 ;; The mode also supports hypertext-like following of manual page SEE
34 ;; ALSO references, and other features. See below or do `?' in a
35 ;; manual page buffer for details.
37 ;; ========== Credits and History ==========
38 ;; In mid 1991, several people posted some interesting improvements to
39 ;; man.el from the standard emacs 18.57 distribution. I liked many of
40 ;; these, but wanted everthing in one single package, so I decided
41 ;; to encorporate them into a single manual browsing mode. While
42 ;; much of the code here has been rewritten, and some features added,
43 ;; these folks deserve lots of credit for providing the initial
44 ;; excellent packages on which this one is based.
46 ;; Nick Duffek <duffek@chaos.cs.brandeis.edu>, posted a very nice
47 ;; improvement which retrieved and cleaned the manpages in a
48 ;; background process, and which correctly deciphered such options as
51 ;; Eric Rose <erose@jessica.stanford.edu>, submitted manual.el which
52 ;; provided a very nice manual browsing mode.
54 ;; This package was available as `superman.el' from the LCD package
55 ;; for some time before it was accepted into Emacs 19. The entry
56 ;; point and some other names have been changed to make it a drop-in
57 ;; replacement for the old man.el package.
59 ;; ========== Features ==========
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
62 ;; is done in the background. The cleaning commands are configurable.
63 ;; + Syntax is the same as Un*x man
64 ;; + Functionality is the same as Un*x man, including "man -k" and
65 ;; "man <section>, etc.
66 ;; + Provides a manual browsing mode with keybindings for traversing
67 ;; the sections of a manpage, following references in the SEE ALSO
69 ;; + Multiple manpages created with the same man command are put into
70 ;; a narrowed buffer circular list.
77 ;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
80 (defvar Man-notify 'friendly
81 "*Selects the behavior when manpage is ready.
82 This variable may have one of the following values:
84 bully -- make the manpage the current buffer and only window
85 aggressive -- make the manpage the current buffer in the other window
86 friendly -- display manpage in other window but don't make current
87 polite -- don't display manpage, but prints message when ready (beeps)
88 quiet -- like `polite', but don't beep
89 meek -- make no indication that manpage is ready
91 Any other value of `Man-notify' is equivalent to `meek'.")
93 (defvar Man-reuse-okay-p t
94 "*Reuse a manpage buffer if possible.
95 When t, and a manpage buffer already exists with the same invocation,
96 man just indicates the manpage is ready according to the value of
97 Man-notify. When nil, it always fires off a background process, putting
98 the results in a uniquely named buffer.")
100 (defvar Man-downcase-section-letters-p t
101 "*Letters in sections are converted to lower case.
102 Some Un*x man commands can't handle uppercase letters in sections, for
103 example \"man 2V chmod\", but they are often displayed in the manpage
104 with the upper case letter. When this variable is t, the section
105 letter (e.g., \"2V\") is converted to lowercase (e.g., \"2v\") before
106 being sent to the man background process.")
108 (defvar Man-circular-pages-p t
109 "*If t, the manpage list is treated as circular for traversal.")
111 (defvar Man-auto-section-alist
112 '((c-mode . ("2" "3"))
113 (c++-mode . ("2" "3"))
114 (shell-mode . ("1" "8"))
115 (cmushell-mode . ("1" "8"))
118 "*Association list of major modes and their default section numbers.
119 List is of the form: (MAJOR-MODE . [SECTION | (SECTION*)]). If current
120 major mode is not in list, then the default is to check for manpages
123 (defvar Man-section-translations-alist
126 "*Association list of bogus sections to real section numbers.
127 Some manpages (e.g. the Sun C++ 2.1 manpages) have section numbers in
128 their references which Un*x man(1) does not recognize. This
129 association list is used to translate those sections, when found, to
130 the associated section number.")
132 (defvar Man-filter-list
135 "-e '/[Nn]o such file or directory/d'"
136 "-e '/Reformatting page. Wait... done/d'"
137 "-e '/^\\([A-Z][A-Z.]*([0-9A-Za-z][-0-9A-Za-z+]*)\\).*\\1$/d'"
138 "-e '/^[ \\t]*Hewlett-Packard Company[ \\t]*- [0-9]* -.*$/d'"
139 "-e '/^[ \\t]*Hewlett-Packard[ \\t]*- [0-9]* -.*$/d'"
140 "-e '/^ *Page [0-9]*.*(printed [0-9\\/]*)$/d'"
141 "-e '/^Printed [0-9].*[0-9]$/d'"
142 "-e '/^[ \\t]*X Version 1[01].*Release [0-9]/d'"
143 "-e '/^Sun Microsystems.*Last change:/d'"
144 "-e '/^Sun Release [0-9].*[0-9]$/d'"
148 ("BEGIN { blankline=0; anonblank=0; }"
149 "/^$/ { if (anonblank==0) next; }"
151 "/^$/ { blankline++; next; }"
152 "{ if (blankline>0) { print \"\"; blankline=0; } print $0; }"
156 "*Manpage cleaning filter command phrases.
157 This variable contains an association list of the following form:
159 '((command-string (phrase-string*))*)
161 Each phrase-string is concatenated onto the command-string to form a
162 command filter. The (standard) output (and standard error) of the Un*x
163 man command is piped through each command filter in the order the
164 commands appear in the association list. The final output is placed in
165 the manpage buffer.")
167 (defvar Man-mode-line-format
168 '("" mode-line-modified
169 mode-line-buffer-identification " "
172 " %[(" mode-name minor-mode-alist mode-line-process ")%]----"
174 "*Mode line format for manual mode buffer.")
176 (defvar Man-mode-map nil
177 "*Keymap for Man-mode.")
179 (defvar Man-mode-hooks nil
180 "*Hooks for Man-mode.")
182 (defvar Man-section-regexp "[0-9][a-zA-Z+]*"
183 "*Regular expression describing a manpage section within parentheses.")
185 (defvar Man-heading-regexp "^[A-Z]"
186 "*Regular expression describing a manpage heading entry.")
188 (defvar Man-see-also-regexp "SEE ALSO"
189 "*Regular expression for SEE ALSO heading (or your equivalent).
190 This regexp should not start with a `^' character.")
192 (defvar Man-first-heading-regexp "^NAME$\\|^No manual entry for .*$"
193 "*Regular expression describing first heading on a manpage.
194 This regular expression should start with a `^' character.")
196 (defvar Man-reference-regexp "[-a-zA-Z0-9_.]+\\(([0-9][a-zA-Z+]*)\\)?"
197 "*Regular expression describing a reference in the SEE ALSO section.")
200 ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
201 ;; end user variables
203 (defconst Man-version-number "1.1"
204 "man's version number.")
207 ;; other variables and keymap initializations
208 (make-variable-buffer-local 'Man-sections-alist)
209 (make-variable-buffer-local 'Man-refpages-alist)
210 (make-variable-buffer-local 'Man-page-list)
211 (make-variable-buffer-local 'Man-current-page)
212 (make-variable-buffer-local 'Man-page-mode-string)
214 (setq-default Man-sections-alist nil)
215 (setq-default Man-refpages-alist nil)
216 (setq-default Man-page-list nil)
217 (setq-default Man-current-page 0)
218 (setq-default Man-page-mode-string "1 (of 1)")
222 (setq Man-mode-map (make-keymap))
223 (suppress-keymap Man-mode-map)
224 (define-key Man-mode-map " " 'scroll-up)
225 (define-key Man-mode-map "\177" 'scroll-down)
226 (define-key Man-mode-map "n" 'Man-next-section)
227 (define-key Man-mode-map "p" 'Man-previous-section)
228 (define-key Man-mode-map "\en" 'Man-next-manpage)
229 (define-key Man-mode-map "\ep" 'Man-previous-manpage)
230 (define-key Man-mode-map "," 'beginning-of-buffer)
231 (define-key Man-mode-map "." 'end-of-buffer)
232 (define-key Man-mode-map "r" 'Man-follow-manual-reference)
233 (define-key Man-mode-map "t" 'toggle-truncate-lines)
234 (define-key Man-mode-map "g" 'Man-goto-section)
235 (define-key Man-mode-map "s" 'Man-goto-see-also-section)
236 (define-key Man-mode-map "q" 'Man-quit)
237 (define-key Man-mode-map "m" 'manual-entry)
238 (define-key Man-mode-map "v" 'Man-version)
239 (define-key Man-mode-map "?" 'describe-mode)
243 ;; ======================================================================
246 (defun Man-page-mode-string ()
247 "Formats part of the mode line for manual mode."
248 (format "%d (of %d)" Man-current-page (length Man-page-list)))
250 (defun Man-delete-trailing-newline (str)
251 (if (string= (substring str (1- (length str))) "\n")
252 (substring str 0 (1- (length str)))
255 (defun Man-build-man-command ()
256 "Builds the entire background manpage and cleaning command."
257 (let ((command "man %s 2>&1 | ")
258 (flist Man-filter-list))
260 (let ((pcom (car (car flist)))
261 (pargs (car (cdr (car flist)))))
262 (setq flist (cdr flist))
263 (if (or (not (stringp pcom))
265 (error "malformed Man-filter-list."))
266 (setq command (concat command pcom
267 (mapconcat '(lambda (phrase) phrase)
270 (setq command (concat command " | " ))))
273 (defun Man-downcase (man-args)
274 "Downcases section letters in MAN-ARGS."
278 (len (length man-args)))
279 (while (and (< s len)
280 (setq mstart (string-match Man-section-regexp man-args s)))
281 (setq mend (match-end 0)
282 newargs (concat newargs (substring man-args s mstart)))
283 (setq newargs (concat newargs (downcase
284 (substring man-args mstart mend)))
286 (concat newargs (substring man-args s len))))
288 (defun Man-translate-references (ref)
289 "Translates REF from \"chmod(2V)\" to \"2v chmod\" style."
290 (if (string-match (concat "(" Man-section-regexp ")$") ref)
291 (let* ((word (progn (string-match "(" ref)
292 (substring ref 0 (1- (match-end 0)))))
293 (section-re (concat "(\\(" Man-section-regexp "\\))"))
294 (section (if (string-match section-re ref)
295 (substring ref (match-beginning 1) (match-end 1))
297 (slist Man-section-translations-alist)
299 (if Man-downcase-section-letters-p
300 (setq section (Man-downcase section)))
302 (let ((s1 (car (car slist)))
303 (s2 (cdr (car slist))))
304 (setq slist (cdr slist))
305 (if Man-downcase-section-letters-p
306 (setq s1 (Man-downcase s1)))
307 (if (not (string= s1 section)) nil
308 (setq section (if Man-downcase-section-letters-p
312 (concat section " " word))
315 (defun Man-linepos (&optional position col-p)
316 "Return the character position at various line/buffer positions.
317 Preserves the state of point, mark, etc. Optional POSITION can be one
318 of the following symbols:
319 bol == beginning of line
320 boi == beginning of indentation
321 eol == end of line [default]
322 bob == beginning of buffer
325 Optional COL-P non-nil returns current-column instead of character position."
329 ((eq position 'bol) (beginning-of-line))
330 ((eq position 'boi) (back-to-indentation))
331 ((eq position 'bob) (goto-char (point-min)))
332 ((eq position 'eob) (goto-char (point-max)))
334 (setq rval (if col-p (current-column) (point)))
339 ;; ======================================================================
340 ;; default man entry and get word under point
342 (defun Man-default-man-args (manword)
343 "Build the default man args from MANWORD and major-mode."
344 (let ((mode major-mode)
345 (slist Man-auto-section-alist))
347 (not (eq (car (car slist)) mode)))
348 (setq slist (cdr slist)))
351 (let ((sections (cdr (car slist))))
352 (if (not (listp sections))
353 (concat sections " " manword)
356 (setq manarg (concat manarg " " (car sections) " " manword))
357 (setq sections (cdr sections)))
361 (defun Man-default-man-entry ()
362 "Make a guess at a default manual entry.
363 This guess is based on the text surrounding the cursor, and the
364 default section number is selected from Man-auto-section-alist."
365 (let ((default-section nil)
369 ;; Default man entry title is any word the cursor is on,
370 ;; or if cursor not on a word, then nearest preceding
372 (and (not (looking-at "[a-zA-Z_]"))
373 (skip-chars-backward "^a-zA-Z_"))
374 (skip-chars-backward "(a-zA-Z_0-9")
375 (and (looking-at "(") (forward-char 1))
379 (progn (skip-chars-forward "a-zA-Z0-9_") (point))))
381 ;; If looking at something like ioctl(2) or brc(1M), include
382 ;; section number in default-entry
383 (if (looking-at "[ \t]*([ \t]*[0-9][a-zA-Z]?[ \t]*)")
384 (progn (skip-chars-forward "^0-9")
385 (setq default-section
389 (skip-chars-forward "0-9a-zA-Z")
392 ;; Otherwise, assume section number to be 2 if we're
394 (and (eq major-mode 'c-mode)
395 (setq default-section "2")))
397 (format "%s %s" default-section default-title)
401 ;; ======================================================================
402 ;; top level command and background process sentinel
405 (defun manual-entry (arg)
406 "Get a Un*x manual page and put it in a buffer.
407 This command is the top-level command in the man package. It runs a Un*x
408 command to retrieve and clean a manpage in the background and places the
409 results in a Man-mode (manpage browsing) buffer. See variable
410 Man-notify for what happens when the buffer is ready.
411 Universal argument ARG, is passed to Man-getpage-in-background."
413 (let* ((default-entry (Man-default-man-entry))
415 (read-string (format "Manual-entry: %s"
416 (if (string= default-entry "") ""
417 (format "(default: %s) "
419 (and (string= man-args "")
420 (if (string= default-entry "")
421 (error "No man args given.")
422 (setq man-args default-entry)))
423 ;; Recognize the subject(section) syntax.
424 (if (string-match "^[ \t]*\\([^( \t]+\\)[ \t]*(\\([^)]+\\))[ \t]*$"
427 (concat (substring man-args (match-beginning 2) (match-end 2))
429 (substring man-args (match-beginning 1) (match-end 1)))))
430 (if Man-downcase-section-letters-p
431 (setq man-args (Man-downcase man-args)))
432 (Man-getpage-in-background man-args (consp arg))
435 (defun Man-getpage-in-background (man-args &optional override-reuse-p)
436 "Uses MAN-ARGS to build and fire off the manpage and cleaning command.
437 Optional OVERRIDE-REUSE-P, when supplied non-nil forces man to
438 start a background process even if a buffer already exists and
439 Man-reuse-okay-p is non-nil."
440 (let* ((bufname (concat "*man " man-args "*"))
441 (buffer (get-buffer bufname)))
442 (if (and Man-reuse-okay-p
443 (not override-reuse-p)
445 (Man-notify-when-ready buffer)
446 (message "Invoking man %s in background..." man-args)
447 (setq buffer (generate-new-buffer bufname))
448 (set-process-sentinel
449 (start-process "man" buffer "sh" "-c"
450 (format (Man-build-man-command) man-args))
451 'Man-bgproc-sentinel))
454 (defun Man-notify-when-ready (man-buffer)
455 "Notify the user when MAN-BUFFER is ready.
456 See the variable `Man-notify' for the different notification behaviors."
458 ((eq Man-notify 'bully)
459 (pop-to-buffer man-buffer)
460 (delete-other-windows))
461 ((eq Man-notify 'aggressive)
462 (pop-to-buffer man-buffer))
463 ((eq Man-notify 'friendly)
464 (display-buffer man-buffer 'not-this-window))
465 ((eq Man-notify 'polite)
467 (message "Manual buffer %s is ready." (buffer-name man-buffer)))
468 ((eq Man-notify 'quiet)
469 (message "Manual buffer %s is ready." (buffer-name man-buffer)))
470 ((or (eq Man-notify 'meek)
475 (defun Man-bgproc-sentinel (process msg)
476 "Manpage background process sentinel."
477 (let ((Man-buffer (process-buffer process))
480 (if (null (buffer-name Man-buffer)) ;; deleted buffer
481 (set-process-buffer process nil)
483 (set-buffer Man-buffer)
484 (goto-char (point-min))
485 (cond ((or (looking-at "No \\(manual \\)*entry for")
486 (looking-at "[^\n]*: nothing appropriate$"))
487 (setq err-mess (buffer-substring (point) (Man-linepos 'eol))
490 ((not (and (eq (process-status process) 'exit)
491 (= (process-exit-status process) 0)))
493 (concat (buffer-name Man-buffer)
495 (let ((eos (1- (length msg))))
496 (if (= (aref msg eos) ?\n)
497 (substring msg 0 eos) msg))))
498 (goto-char (point-max))
499 (insert (format "\nprocess %s" msg))
502 (kill-buffer Man-buffer)
503 (save-window-excursion
505 (set-buffer Man-buffer)
507 (set-buffer-modified-p nil)))
508 (Man-notify-when-ready Man-buffer))
515 ;; ======================================================================
516 ;; set up manual mode in buffer and build alists
519 "SUPERMAN 1.1: A mode for browsing Un*x manual pages.
521 The following man commands are available in the buffer. Try
522 \"\\[describe-key] <key> RET\" for more information:
524 \\[manual-entry] Prompt to retrieve a new manpage.
525 \\[Man-follow-manual-reference] Retrieve reference in SEE ALSO section.
526 \\[Man-next-manpage] Jump to next manpage in circular list.
527 \\[Man-previous-manpage] Jump to previous manpage in circular list.
528 \\[Man-next-section] Jump to next manpage section.
529 \\[Man-previous-section] Jump to previous manpage section.
530 \\[Man-goto-section] Go to a manpage section.
531 \\[Man-goto-see-also-section] Jumps to the SEE ALSO manpage section.
532 \\[Man-quit] Deletes the manpage, its buffer, and window.
533 \\[Man-version] Prints man's version number.
534 \\[describe-mode] Prints this help text.
536 The following variables may be of some use. Try
537 \"\\[describe-variable] <variable-name> RET\" for more information:
539 Man-notify What happens when manpage formatting is done.
540 Man-reuse-okay-p Okay to reuse already formatted buffer?
541 Man-downcase-section-letters-p Force section letters to lower case?
542 Man-circular-pages-p Multiple manpage list treated as circular?
543 Man-auto-section-alist List of major modes and their section numbers.
544 Man-section-translations-alist List of section numbers and their Un*x equiv.
545 Man-filter-list Background manpage filter command.
546 Man-mode-line-format Mode line format for Man-mode buffers.
547 Man-mode-map Keymap bindings for Man-mode buffers.
548 Man-mode-hooks Hooks for Man-mode.
549 Man-section-regexp Regexp describing manpage section letters.
550 Man-heading-regexp Regexp describing section headers.
551 Man-see-also-regexp Regexp for SEE ALSO section (or your equiv).
552 Man-first-heading-regexp Regexp for first heading on a manpage.
553 Man-reference-regexp Regexp matching a references in SEE ALSO.
554 Man-version-number Superman version number.
556 The following key bindings are currently in effect in the buffer:
559 (setq major-mode 'Man-mode
561 buffer-auto-save-file-name nil
562 mode-line-format Man-mode-line-format
565 (buffer-disable-undo (current-buffer))
567 (use-local-map Man-mode-map)
568 (goto-char (point-min))
569 (Man-build-page-list)
571 (run-hooks 'Man-mode-hook))
573 (defun Man-build-section-alist ()
574 "Build the association list of manpage sections."
575 (setq Man-sections-alist nil)
576 (goto-char (point-min))
577 (while (re-search-forward Man-heading-regexp (point-max) t)
578 (aput 'Man-sections-alist
579 (buffer-substring (Man-linepos 'bol) (Man-linepos)))
583 (defun Man-build-references-alist ()
584 "Build the association list of references (in the SEE ALSO section)."
585 (setq Man-refpages-alist nil)
587 (if (Man-find-section Man-see-also-regexp)
588 (let ((start (progn (forward-line 1) (point)))
594 (narrow-to-region start end)
595 (goto-char (point-min))
596 (back-to-indentation)
597 (while (and (not (eobp)) (/= (point) runningpoint))
598 (setq runningpoint (point))
600 (eow (re-search-forward Man-reference-regexp end t))
601 (word (buffer-substring bow (match-end 0)))
602 (len (1- (length word))))
605 (setq word (concat hyphenated word)
607 (if (= (aref word len) ?-)
608 (setq hyphenated (substring word 0 len))
609 (aput 'Man-refpages-alist word))))
610 (skip-chars-forward " \t\n,"))
613 (defun Man-build-page-list ()
614 "Build the list of separate manpages in the buffer."
615 (setq Man-page-list nil)
617 (let ((page-start (Man-linepos 'bob))
618 (page-end (Man-linepos 'eob))
619 (regexp Man-first-heading-regexp))
620 (goto-char (point-min))
621 (re-search-forward regexp (point-max) t)
623 (if (re-search-forward regexp (point-max) t)
625 (setq page-end (Man-linepos 'bol))
627 (goto-char (point-max))
628 (setq page-end (point)))
629 (setq Man-page-list (append Man-page-list
630 (list (cons page-start page-end)))
635 ;; ======================================================================
638 (defun Man-next-section (n)
639 "Move point to Nth next section (default 1)."
641 (if (looking-at Man-heading-regexp)
643 (if (re-search-forward Man-heading-regexp (point-max) t n)
645 (goto-char (point-max))))
647 (defun Man-previous-section (n)
648 "Move point to Nth previous section (default 1)."
650 (if (looking-at Man-heading-regexp)
652 (if (re-search-backward Man-heading-regexp (point-min) t n)
654 (goto-char (point-min))))
656 (defun Man-find-section (section)
657 "Move point to SECTION if it exists, otherwise don't move point.
658 Returns t if section is found, nil otherwise."
659 (let ((curpos (point)))
660 (goto-char (point-min))
661 (if (re-search-forward (concat "^" section) (point-max) t)
662 (progn (beginning-of-line) t)
667 (defun Man-goto-section ()
668 "Query for section to move point to."
670 (aput 'Man-sections-alist
671 (let* ((default (aheadsym Man-sections-alist))
672 (completion-ignore-case t)
674 (prompt (concat "Go to section: (default " default ") ")))
675 (setq chosen (completing-read prompt Man-sections-alist))
680 (Man-find-section (aheadsym Man-sections-alist)))
682 (defun Man-goto-see-also-section ()
683 "Move point the the \"SEE ALSO\" section.
684 Actually the section moved to is described by Man-see-also-regexp."
686 (if (not (Man-find-section Man-see-also-regexp))
687 (error (concat "No " Man-see-also-regexp
688 " section found in current manpage."))))
690 (defun Man-follow-manual-reference (arg)
691 "Get one of the manpages referred to in the \"SEE ALSO\" section.
692 Queries you for the page to retrieve. Of course it does this in the
693 background. Universal argument ARG is passed to Man-getpage-in-background."
695 (if (not Man-refpages-alist)
696 (error (concat "No references found in current manpage."))
697 (aput 'Man-refpages-alist
698 (let* ((default (aheadsym Man-refpages-alist))
700 (prompt (concat "Refer to: (default " default ") ")))
701 (setq chosen (completing-read prompt Man-refpages-alist nil t))
706 (Man-getpage-in-background
707 (Man-translate-references (aheadsym Man-refpages-alist))
711 "Kill the buffer containing the manpage."
713 (let ((buff (current-buffer)))
714 (delete-windows-on buff)
717 (defun Man-goto-page (page)
718 "Go to the manual page on page PAGE."
720 (if (not Man-page-list)
721 (error "You're looking at the only manpage in the buffer.")
722 (format "nGo to manpage [1-%d]: " (length Man-page-list))))
724 (> page (length Man-page-list)))
725 (error "No manpage %d found" page))
726 (let* ((page-range (nth (1- page) Man-page-list))
727 (page-start (car page-range))
728 (page-end (cdr page-range)))
729 (setq Man-current-page page
730 Man-page-mode-string (Man-page-mode-string))
732 (goto-char page-start)
733 (narrow-to-region page-start page-end)
734 (Man-build-section-alist)
735 ;; Don't let bugs in Man-build-references-alist
736 ;; interfere with ordinary use of this package.
738 (Man-build-references-alist)
741 (narrow-to-region page-start page-end)
742 (goto-char (point-min))))
745 (defun Man-next-manpage ()
746 "Find the next manpage entry in the buffer."
748 (if (= (length Man-page-list) 1)
749 (error "This is the only manpage in the buffer."))
750 (if (< Man-current-page (length Man-page-list))
751 (Man-goto-page (1+ Man-current-page))
752 (if Man-circular-pages-p
754 (error "You're looking at the last manpage in the buffer."))))
756 (defun Man-previous-manpage ()
757 "Find the previous manpage entry in the buffer."
759 (if (= (length Man-page-list) 1)
760 (error "This is the only manpage in the buffer."))
761 (if (> Man-current-page 1)
762 (Man-goto-page (1- Man-current-page))
763 (if Man-circular-pages-p
764 (Man-goto-page (length Man-page-list))
765 (error "You're looking at the first manpage in the buffer."))))
767 (defun Man-version (arg)
769 Universal argument (\\[universal-argument]) ARG inserts version
770 information in the current buffer instead of printing the message in
774 (insert "Using Superman version " Man-version-number ".")
775 (message "Using Superman version %s." Man-version-number)))