Mercurial > emacs
annotate lisp/man.el @ 5020:94de08fd8a7c
(Fnext_single_property_change): Fix missing \n\.
| author | Richard M. Stallman <rms@gnu.org> |
|---|---|
| date | Mon, 15 Nov 1993 06:41:45 +0000 |
| parents | 50708e8b133b |
| children | 8c482171bb10 |
| rev | line source |
|---|---|
| 3235 | 1 ;;; man.el --- browse UNIX manual pages |
| 2 | |
| 3 ;; Copyright (C) 1993 Free Software Foundation, Inc. | |
| 4 | |
| 5 ;; Author: Barry A. Warsaw <bwarsaw@cen.com> | |
| 6 ;; Last-Modified: 31-Jul-1991 | |
| 7 ;; Version: 1.1 | |
| 8 ;; Keywords: help | |
| 9 ;; Adapted-By: ESR | |
| 10 | |
| 11 ;; This file is part of GNU Emacs. | |
| 12 | |
| 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) | |
| 16 ;; any later version. | |
| 17 | |
| 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. | |
| 22 | |
| 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. | |
| 26 | |
| 27 ;;; Commentary: | |
| 28 | |
| 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. | |
| 32 ;; | |
| 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. | |
| 36 | |
| 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. | |
| 45 | |
| 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 | |
| 49 ;; man -k. | |
| 50 | |
| 51 ;; Eric Rose <erose@jessica.stanford.edu>, submitted manual.el which | |
| 52 ;; provided a very nice manual browsing mode. | |
| 53 | |
|
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3307
diff
changeset
|
54 ;; This package was available as `superman.el' from the LCD package |
| 3235 | 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. | |
| 58 | |
| 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 | |
|
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
65 ;; "man <section>", etc. |
| 3235 | 66 ;; + Provides a manual browsing mode with keybindings for traversing |
| 67 ;; the sections of a manpage, following references in the SEE ALSO | |
| 68 ;; section, and more. | |
| 69 ;; + Multiple manpages created with the same man command are put into | |
| 70 ;; a narrowed buffer circular list. | |
| 71 | |
| 72 ;;; Code: | |
| 73 | |
| 74 (require 'assoc) | |
| 75 | |
| 76 ;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv | |
| 77 ;; user variables | |
| 78 | |
| 79 (defvar Man-notify 'friendly | |
| 80 "*Selects the behavior when manpage is ready. | |
| 81 This variable may have one of the following values: | |
| 82 | |
|
4915
c0523a78e6a5
(Man-frame-parameters): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4444
diff
changeset
|
83 newframe -- put the manpage in its own frame (see `Man-frame-parameters') |
| 3235 | 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 | |
| 90 | |
| 91 Any other value of `Man-notify' is equivalent to `meek'.") | |
| 92 | |
|
4915
c0523a78e6a5
(Man-frame-parameters): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4444
diff
changeset
|
93 (defvar Man-frame-parameters nil |
|
c0523a78e6a5
(Man-frame-parameters): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4444
diff
changeset
|
94 "*Frame parameter list for creating a new frame for a manual page.") |
|
c0523a78e6a5
(Man-frame-parameters): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4444
diff
changeset
|
95 |
| 3235 | 96 (defvar Man-reuse-okay-p t |
| 97 "*Reuse a manpage buffer if possible. | |
| 98 When t, and a manpage buffer already exists with the same invocation, | |
| 99 man just indicates the manpage is ready according to the value of | |
|
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
100 `Man-notify'. When nil, it always fires off a background process, putting |
| 3235 | 101 the results in a uniquely named buffer.") |
| 102 | |
| 103 (defvar Man-downcase-section-letters-p t | |
| 104 "*Letters in sections are converted to lower case. | |
| 105 Some Un*x man commands can't handle uppercase letters in sections, for | |
| 106 example \"man 2V chmod\", but they are often displayed in the manpage | |
|
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
107 with the upper case letter. When this variable is t, the section |
| 3235 | 108 letter (e.g., \"2V\") is converted to lowercase (e.g., \"2v\") before |
| 109 being sent to the man background process.") | |
| 110 | |
| 111 (defvar Man-circular-pages-p t | |
| 112 "*If t, the manpage list is treated as circular for traversal.") | |
| 113 | |
|
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
114 ;; I changed this to nil because it is a bad idea |
|
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
115 ;; to fail to recognize things in other sections. |
| 3235 | 116 (defvar Man-auto-section-alist |
|
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
117 nil |
|
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
118 ;; '((c-mode . ("2" "3")) |
|
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
119 ;; (c++-mode . ("2" "3")) |
|
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
120 ;; (c++-c-mode . ("2" "3")) |
|
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
121 ;; (shell-mode . ("1" "8")) |
|
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
122 ;; (cmushell-mode . ("1" "8")) |
|
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
123 ;; (text-mode . "1") |
|
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
124 ;; ) |
| 3235 | 125 "*Association list of major modes and their default section numbers. |
| 126 List is of the form: (MAJOR-MODE . [SECTION | (SECTION*)]). If current | |
| 127 major mode is not in list, then the default is to check for manpages | |
| 128 in all sections.") | |
| 129 | |
| 130 (defvar Man-section-translations-alist | |
| 131 '(("3C++" . "3") | |
|
4378
088883bdcd70
(Man-section-translations-alist): Add entries for xlib.
Richard M. Stallman <rms@gnu.org>
parents:
4377
diff
changeset
|
132 ("3X" . "3") ; Xlib man pages |
|
088883bdcd70
(Man-section-translations-alist): Add entries for xlib.
Richard M. Stallman <rms@gnu.org>
parents:
4377
diff
changeset
|
133 ("3X11" . "3") |
| 3235 | 134 ("1-UCB" . "")) |
| 135 "*Association list of bogus sections to real section numbers. | |
| 136 Some manpages (e.g. the Sun C++ 2.1 manpages) have section numbers in | |
|
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
137 their references which Un*x `man' does not recognize. This |
|
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3307
diff
changeset
|
138 association list is used to translate those sections, when found, to |
| 3235 | 139 the associated section number.") |
| 140 | |
| 141 (defvar Man-filter-list | |
| 142 '(("sed " | |
|
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
143 (;;"-e 's/.\010//g'" |
| 3235 | 144 "-e '/[Nn]o such file or directory/d'" |
| 145 "-e '/Reformatting page. Wait... done/d'" | |
| 146 "-e '/^\\([A-Z][A-Z.]*([0-9A-Za-z][-0-9A-Za-z+]*)\\).*\\1$/d'" | |
| 147 "-e '/^[ \\t]*Hewlett-Packard Company[ \\t]*- [0-9]* -.*$/d'" | |
| 148 "-e '/^[ \\t]*Hewlett-Packard[ \\t]*- [0-9]* -.*$/d'" | |
| 149 "-e '/^ *Page [0-9]*.*(printed [0-9\\/]*)$/d'" | |
| 150 "-e '/^Printed [0-9].*[0-9]$/d'" | |
|
3659
296caa999ccf
(Man-filter-list): Add an element for X man pages.
Richard M. Stallman <rms@gnu.org>
parents:
3644
diff
changeset
|
151 "-e '/^[ \\t]*X Version 1[01].*Release [0-9]/d'" |
|
4968
1607732e7712
(Man-filter-list): Include anything starting with
Richard M. Stallman <rms@gnu.org>
parents:
4915
diff
changeset
|
152 "-e '/^[A-za-z].*Last change:/d'" |
| 3235 | 153 "-e '/^Sun Release [0-9].*[0-9]$/d'" |
| 154 "-e '/^\\n$/D'" | |
| 155 )) | |
|
4329
dfabe5b99500
(Man-filter-list): Insert \n newlines in awk script.
Richard M. Stallman <rms@gnu.org>
parents:
4203
diff
changeset
|
156 ("awk '\n" |
|
dfabe5b99500
(Man-filter-list): Insert \n newlines in awk script.
Richard M. Stallman <rms@gnu.org>
parents:
4203
diff
changeset
|
157 ("BEGIN { blankline=0; anonblank=0; }\n" |
|
dfabe5b99500
(Man-filter-list): Insert \n newlines in awk script.
Richard M. Stallman <rms@gnu.org>
parents:
4203
diff
changeset
|
158 "/^$/ { if (anonblank==0) next; }\n" |
|
dfabe5b99500
(Man-filter-list): Insert \n newlines in awk script.
Richard M. Stallman <rms@gnu.org>
parents:
4203
diff
changeset
|
159 "{ anonblank=1; }\n" |
|
dfabe5b99500
(Man-filter-list): Insert \n newlines in awk script.
Richard M. Stallman <rms@gnu.org>
parents:
4203
diff
changeset
|
160 "/^$/ { blankline++; next; }\n" |
|
dfabe5b99500
(Man-filter-list): Insert \n newlines in awk script.
Richard M. Stallman <rms@gnu.org>
parents:
4203
diff
changeset
|
161 "{ if (blankline>0) { print \"\"; blankline=0; } print $0; }\n" |
| 3235 | 162 "'" |
| 163 )) | |
| 164 ) | |
| 165 "*Manpage cleaning filter command phrases. | |
| 166 This variable contains an association list of the following form: | |
| 167 | |
| 168 '((command-string (phrase-string*))*) | |
| 169 | |
| 170 Each phrase-string is concatenated onto the command-string to form a | |
|
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
171 command filter. The (standard) output (and standard error) of the Un*x |
| 3235 | 172 man command is piped through each command filter in the order the |
|
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
173 commands appear in the association list. The final output is placed in |
| 3235 | 174 the manpage buffer.") |
| 175 | |
| 176 (defvar Man-mode-line-format | |
| 177 '("" mode-line-modified | |
| 178 mode-line-buffer-identification " " | |
| 179 global-mode-string | |
|
4009
4edc10a61fa7
(Man-mode-line-format): Add a space after global-mode-string.
Richard M. Stallman <rms@gnu.org>
parents:
4002
diff
changeset
|
180 " " Man-page-mode-string |
| 3235 | 181 " %[(" mode-name minor-mode-alist mode-line-process ")%]----" |
| 182 (-3 . "%p") "-%-") | |
| 183 "*Mode line format for manual mode buffer.") | |
| 184 | |
| 185 (defvar Man-mode-map nil | |
|
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
186 "*Keymap for Man mode.") |
| 3235 | 187 |
| 188 (defvar Man-mode-hooks nil | |
|
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
189 "*Hooks for Man mode.") |
| 3235 | 190 |
|
4980
50708e8b133b
(Man-section-regexp): Allow section names l, n, L, N.
Richard M. Stallman <rms@gnu.org>
parents:
4968
diff
changeset
|
191 (defvar Man-section-regexp "[0-9][a-zA-Z+]*\\|[LNln]" |
| 3235 | 192 "*Regular expression describing a manpage section within parentheses.") |
| 193 | |
|
4377
09cb5e07f8a3
(Man-build-references-alist): When setting word,
Richard M. Stallman <rms@gnu.org>
parents:
4334
diff
changeset
|
194 (defvar Man-heading-regexp "^ ?[A-Z]" |
| 3235 | 195 "*Regular expression describing a manpage heading entry.") |
| 196 | |
| 197 (defvar Man-see-also-regexp "SEE ALSO" | |
| 198 "*Regular expression for SEE ALSO heading (or your equivalent). | |
| 199 This regexp should not start with a `^' character.") | |
| 200 | |
|
4377
09cb5e07f8a3
(Man-build-references-alist): When setting word,
Richard M. Stallman <rms@gnu.org>
parents:
4334
diff
changeset
|
201 (defvar Man-first-heading-regexp "^ ?NAME$\\|^ ?No manual entry for .*$" |
| 3235 | 202 "*Regular expression describing first heading on a manpage. |
| 203 This regular expression should start with a `^' character.") | |
| 204 | |
|
4377
09cb5e07f8a3
(Man-build-references-alist): When setting word,
Richard M. Stallman <rms@gnu.org>
parents:
4334
diff
changeset
|
205 (defvar Man-reference-regexp |
|
09cb5e07f8a3
(Man-build-references-alist): When setting word,
Richard M. Stallman <rms@gnu.org>
parents:
4334
diff
changeset
|
206 "[-a-zA-Z0-9_][-a-zA-Z0-9_.]*\\(([0-9][a-zA-Z+]*)\\)?" |
| 3235 | 207 "*Regular expression describing a reference in the SEE ALSO section.") |
| 208 | |
|
3833
70551a213fae
* man.el (Man-switches): New variable.
Jim Blandy <jimb@redhat.com>
parents:
3714
diff
changeset
|
209 (defvar Man-switches "" |
|
70551a213fae
* man.el (Man-switches): New variable.
Jim Blandy <jimb@redhat.com>
parents:
3714
diff
changeset
|
210 "*Switches passed to the man command, as a single string.") |
| 3235 | 211 |
| 212 ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
| 213 ;; end user variables | |
| 214 | |
| 215 ;; other variables and keymap initializations | |
| 216 (make-variable-buffer-local 'Man-sections-alist) | |
| 217 (make-variable-buffer-local 'Man-refpages-alist) | |
| 218 (make-variable-buffer-local 'Man-page-list) | |
| 219 (make-variable-buffer-local 'Man-current-page) | |
| 220 (make-variable-buffer-local 'Man-page-mode-string) | |
| 221 | |
| 222 (setq-default Man-sections-alist nil) | |
| 223 (setq-default Man-refpages-alist nil) | |
| 224 (setq-default Man-page-list nil) | |
| 225 (setq-default Man-current-page 0) | |
| 226 (setq-default Man-page-mode-string "1 (of 1)") | |
| 227 | |
| 228 (if Man-mode-map | |
| 229 nil | |
| 230 (setq Man-mode-map (make-keymap)) | |
| 231 (suppress-keymap Man-mode-map) | |
| 232 (define-key Man-mode-map " " 'scroll-up) | |
| 233 (define-key Man-mode-map "\177" 'scroll-down) | |
| 234 (define-key Man-mode-map "n" 'Man-next-section) | |
| 235 (define-key Man-mode-map "p" 'Man-previous-section) | |
| 236 (define-key Man-mode-map "\en" 'Man-next-manpage) | |
| 237 (define-key Man-mode-map "\ep" 'Man-previous-manpage) | |
| 238 (define-key Man-mode-map "," 'beginning-of-buffer) | |
| 239 (define-key Man-mode-map "." 'end-of-buffer) | |
| 240 (define-key Man-mode-map "r" 'Man-follow-manual-reference) | |
| 241 (define-key Man-mode-map "t" 'toggle-truncate-lines) | |
| 242 (define-key Man-mode-map "g" 'Man-goto-section) | |
| 243 (define-key Man-mode-map "s" 'Man-goto-see-also-section) | |
| 244 (define-key Man-mode-map "q" 'Man-quit) | |
| 245 (define-key Man-mode-map "m" 'manual-entry) | |
| 246 (define-key Man-mode-map "?" 'describe-mode) | |
| 247 ) | |
| 248 | |
| 249 | |
| 250 ;; ====================================================================== | |
| 251 ;; utilities | |
| 252 | |
| 253 (defun Man-page-mode-string () | |
| 254 "Formats part of the mode line for manual mode." | |
| 255 (format "%d (of %d)" Man-current-page (length Man-page-list))) | |
| 256 | |
| 257 (defun Man-delete-trailing-newline (str) | |
| 258 (if (string= (substring str (1- (length str))) "\n") | |
| 259 (substring str 0 (1- (length str))) | |
| 260 str)) | |
| 261 | |
| 262 (defun Man-build-man-command () | |
| 263 "Builds the entire background manpage and cleaning command." | |
|
4002
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
264 (let ((command (concat "man " Man-switches " %s 2>&1")) |
| 3235 | 265 (flist Man-filter-list)) |
| 266 (while flist | |
| 267 (let ((pcom (car (car flist))) | |
| 268 (pargs (car (cdr (car flist))))) | |
| 269 (setq flist (cdr flist)) | |
| 270 (if (or (not (stringp pcom)) | |
| 271 (not (listp pargs))) | |
| 272 (error "malformed Man-filter-list.")) | |
|
4002
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
273 (setq command (concat command " | " pcom |
| 3235 | 274 (mapconcat '(lambda (phrase) phrase) |
|
4002
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
275 pargs " "))))) |
| 3235 | 276 command)) |
| 277 | |
| 278 (defun Man-downcase (man-args) | |
| 279 "Downcases section letters in MAN-ARGS." | |
| 280 (let ((newargs "") | |
| 281 (s 0) | |
| 282 mstart mend | |
| 283 (len (length man-args))) | |
| 284 (while (and (< s len) | |
| 285 (setq mstart (string-match Man-section-regexp man-args s))) | |
| 286 (setq mend (match-end 0) | |
| 287 newargs (concat newargs (substring man-args s mstart))) | |
| 288 (setq newargs (concat newargs (downcase | |
| 289 (substring man-args mstart mend))) | |
| 290 s mend)) | |
| 291 (concat newargs (substring man-args s len)))) | |
| 292 | |
| 293 (defun Man-translate-references (ref) | |
| 294 "Translates REF from \"chmod(2V)\" to \"2v chmod\" style." | |
| 295 (if (string-match (concat "(" Man-section-regexp ")$") ref) | |
| 296 (let* ((word (progn (string-match "(" ref) | |
| 297 (substring ref 0 (1- (match-end 0))))) | |
| 298 (section-re (concat "(\\(" Man-section-regexp "\\))")) | |
| 299 (section (if (string-match section-re ref) | |
| 300 (substring ref (match-beginning 1) (match-end 1)) | |
| 301 "")) | |
| 302 (slist Man-section-translations-alist) | |
| 303 ) | |
| 304 (if Man-downcase-section-letters-p | |
| 305 (setq section (Man-downcase section))) | |
| 306 (while slist | |
| 307 (let ((s1 (car (car slist))) | |
| 308 (s2 (cdr (car slist)))) | |
| 309 (setq slist (cdr slist)) | |
| 310 (if Man-downcase-section-letters-p | |
| 311 (setq s1 (Man-downcase s1))) | |
| 312 (if (not (string= s1 section)) nil | |
| 313 (setq section (if Man-downcase-section-letters-p | |
| 314 (Man-downcase s2) | |
| 315 s2) | |
| 316 slist nil)))) | |
| 317 (concat section " " word)) | |
| 318 ref)) | |
| 319 | |
| 320 (defun Man-linepos (&optional position col-p) | |
| 321 "Return the character position at various line/buffer positions. | |
|
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
322 Preserves the state of point, mark, etc. Optional arg POSITION can be one |
| 3235 | 323 of the following symbols: |
| 324 bol == beginning of line | |
| 325 boi == beginning of indentation | |
| 326 eol == end of line [default] | |
| 327 bob == beginning of buffer | |
| 328 eob == end of buffer | |
| 329 | |
|
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
330 Optional arg COL-P, if non-nil, means to return |
|
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
331 the current column instead of character position." |
| 3235 | 332 (let ((tpnt (point)) |
| 333 rval) | |
| 334 (cond | |
| 335 ((eq position 'bol) (beginning-of-line)) | |
| 336 ((eq position 'boi) (back-to-indentation)) | |
| 337 ((eq position 'bob) (goto-char (point-min))) | |
| 338 ((eq position 'eob) (goto-char (point-max))) | |
| 339 (t (end-of-line))) | |
| 340 (setq rval (if col-p (current-column) (point))) | |
| 341 (goto-char tpnt) | |
| 342 rval)) | |
| 343 | |
| 344 | |
| 345 ;; ====================================================================== | |
| 346 ;; default man entry and get word under point | |
| 347 | |
| 348 (defun Man-default-man-args (manword) | |
|
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
349 "Build the default man args from MANWORD and buffer's major mode." |
|
4002
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
350 (let ((sections (cdr (assq major-mode Man-auto-section-alist)))) |
|
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
351 (cond |
|
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
352 ((null sections) manword) |
|
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
353 ((consp sections) |
|
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
354 (mapconcat (lambda (n) (concat n " " manword)) sections " ")) |
|
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
355 (t |
|
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
356 (concat sections " " manword))))) |
| 3235 | 357 |
| 358 (defun Man-default-man-entry () | |
| 359 "Make a guess at a default manual entry. | |
| 360 This guess is based on the text surrounding the cursor, and the | |
|
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
361 default section number is selected from `Man-auto-section-alist'." |
|
4002
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
362 (let (default-title) |
| 3235 | 363 (save-excursion |
| 364 | |
| 365 ;; Default man entry title is any word the cursor is on, | |
| 366 ;; or if cursor not on a word, then nearest preceding | |
| 367 ;; word. | |
| 368 (and (not (looking-at "[a-zA-Z_]")) | |
| 369 (skip-chars-backward "^a-zA-Z_")) | |
| 370 (skip-chars-backward "(a-zA-Z_0-9") | |
| 371 (and (looking-at "(") (forward-char 1)) | |
| 372 (setq default-title | |
| 373 (buffer-substring | |
| 374 (point) | |
| 375 (progn (skip-chars-forward "a-zA-Z0-9_") (point)))) | |
| 376 | |
| 377 ;; If looking at something like ioctl(2) or brc(1M), include | |
| 378 ;; section number in default-entry | |
| 379 (if (looking-at "[ \t]*([ \t]*[0-9][a-zA-Z]?[ \t]*)") | |
| 380 (progn (skip-chars-forward "^0-9") | |
|
4002
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
381 (setq default-title |
|
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
382 (concat (buffer-substring |
|
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
383 (point) |
|
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
384 (progn |
|
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
385 (skip-chars-forward "0-9a-zA-Z") |
|
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
386 (point))) |
|
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
387 " " |
|
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
388 default-title))) |
|
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
389 (setq default-title (Man-default-man-args default-title))) |
|
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
390 default-title))) |
| 3235 | 391 |
| 392 | |
| 393 ;; ====================================================================== | |
| 394 ;; top level command and background process sentinel | |
| 395 | |
| 4444 | 396 ;;; This alias makes completion more predictable if ignoring case. |
| 397 ;;;###autoload | |
| 398 (defalias 'man 'manual-entry) | |
| 399 | |
| 3235 | 400 ;;;###autoload |
| 401 (defun manual-entry (arg) | |
| 402 "Get a Un*x manual page and put it in a buffer. | |
|
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
403 This command is the top-level command in the man package. It runs a Un*x |
| 3235 | 404 command to retrieve and clean a manpage in the background and places the |
|
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
405 results in a Man mode (manpage browsing) buffer. See variable |
|
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
406 `Man-notify' for what happens when the buffer is ready. |
|
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
407 Universal argument ARG, is passed to `Man-getpage-in-background'." |
| 3235 | 408 (interactive "P") |
| 409 (let* ((default-entry (Man-default-man-entry)) | |
| 410 (man-args | |
| 411 (read-string (format "Manual-entry: %s" | |
| 412 (if (string= default-entry "") "" | |
| 413 (format "(default: %s) " | |
| 414 default-entry)))))) | |
| 415 (and (string= man-args "") | |
| 416 (if (string= default-entry "") | |
| 417 (error "No man args given.") | |
| 418 (setq man-args default-entry))) | |
|
4002
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
419 |
|
3644
9e251319cdc8
* man.el (manual-entry): Recognize the subject(section) syntax.
Jim Blandy <jimb@redhat.com>
parents:
3619
diff
changeset
|
420 ;; Recognize the subject(section) syntax. |
|
4002
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
421 (setq man-args (Man-translate-references man-args)) |
|
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
422 |
|
4968
1607732e7712
(Man-filter-list): Include anything starting with
Richard M. Stallman <rms@gnu.org>
parents:
4915
diff
changeset
|
423 ;; This is apparently already done correctly via Man-translate-references. |
|
1607732e7712
(Man-filter-list): Include anything starting with
Richard M. Stallman <rms@gnu.org>
parents:
4915
diff
changeset
|
424 ;; (if Man-downcase-section-letters-p |
|
1607732e7712
(Man-filter-list): Include anything starting with
Richard M. Stallman <rms@gnu.org>
parents:
4915
diff
changeset
|
425 ;; (setq man-args (Man-downcase man-args))) |
| 3235 | 426 (Man-getpage-in-background man-args (consp arg)) |
| 427 )) | |
| 428 | |
|
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
429 (defun Man-getpage-in-background (TOPIC &optional override-reuse-p) |
|
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
430 "Uses TOPIC to build and fire off the manpage and cleaning command. |
|
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
431 Optional OVERRIDE-REUSE-P, when non-nil, means to |
| 3235 | 432 start a background process even if a buffer already exists and |
|
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
433 `Man-reuse-okay-p' is non-nil." |
|
4002
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
434 (let* ((man-args TOPIC) |
|
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
435 (bufname (concat "*man " man-args "*")) |
| 3235 | 436 (buffer (get-buffer bufname))) |
| 437 (if (and Man-reuse-okay-p | |
| 438 (not override-reuse-p) | |
| 439 buffer) | |
| 440 (Man-notify-when-ready buffer) | |
| 441 (message "Invoking man %s in background..." man-args) | |
| 442 (setq buffer (generate-new-buffer bufname)) | |
|
4175
3e4fa4423f5a
(Man-getpage-in-background): Copy process-environment
Richard M. Stallman <rms@gnu.org>
parents:
4009
diff
changeset
|
443 (let ((process-environment (copy-sequence process-environment))) |
|
3713
c77a3da2d08d
(Man-getpage-in-background): Use TERM=dumb to prevent
Richard M. Stallman <rms@gnu.org>
parents:
3659
diff
changeset
|
444 ;; Prevent any attempt to use display terminal fanciness. |
|
c77a3da2d08d
(Man-getpage-in-background): Use TERM=dumb to prevent
Richard M. Stallman <rms@gnu.org>
parents:
3659
diff
changeset
|
445 (setenv "TERM" "dumb") |
|
c77a3da2d08d
(Man-getpage-in-background): Use TERM=dumb to prevent
Richard M. Stallman <rms@gnu.org>
parents:
3659
diff
changeset
|
446 (set-process-sentinel |
|
c77a3da2d08d
(Man-getpage-in-background): Use TERM=dumb to prevent
Richard M. Stallman <rms@gnu.org>
parents:
3659
diff
changeset
|
447 (start-process "man" buffer "sh" "-c" |
|
3714
a1edd269b2f4
(Man-getpage-in-background): Move close paren.
Richard M. Stallman <rms@gnu.org>
parents:
3713
diff
changeset
|
448 (format (Man-build-man-command) man-args)) |
|
a1edd269b2f4
(Man-getpage-in-background): Move close paren.
Richard M. Stallman <rms@gnu.org>
parents:
3713
diff
changeset
|
449 'Man-bgproc-sentinel)) |
|
a1edd269b2f4
(Man-getpage-in-background): Move close paren.
Richard M. Stallman <rms@gnu.org>
parents:
3713
diff
changeset
|
450 ))) |
| 3235 | 451 |
| 452 (defun Man-notify-when-ready (man-buffer) | |
| 453 "Notify the user when MAN-BUFFER is ready. | |
|
3307
1fc2bc44def7
(Man-notify-when-ready): Correct previous change.
Richard M. Stallman <rms@gnu.org>
parents:
3235
diff
changeset
|
454 See the variable `Man-notify' for the different notification behaviors." |
| 3235 | 455 (cond |
|
4915
c0523a78e6a5
(Man-frame-parameters): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4444
diff
changeset
|
456 ((eq Man-notify 'newframe) |
|
c0523a78e6a5
(Man-frame-parameters): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4444
diff
changeset
|
457 (set-buffer man-buffer) |
|
c0523a78e6a5
(Man-frame-parameters): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4444
diff
changeset
|
458 (new-frame Man-frame-parameters)) |
|
3307
1fc2bc44def7
(Man-notify-when-ready): Correct previous change.
Richard M. Stallman <rms@gnu.org>
parents:
3235
diff
changeset
|
459 ((eq Man-notify 'bully) |
| 3235 | 460 (pop-to-buffer man-buffer) |
| 461 (delete-other-windows)) | |
|
3307
1fc2bc44def7
(Man-notify-when-ready): Correct previous change.
Richard M. Stallman <rms@gnu.org>
parents:
3235
diff
changeset
|
462 ((eq Man-notify 'aggressive) |
| 3235 | 463 (pop-to-buffer man-buffer)) |
|
3307
1fc2bc44def7
(Man-notify-when-ready): Correct previous change.
Richard M. Stallman <rms@gnu.org>
parents:
3235
diff
changeset
|
464 ((eq Man-notify 'friendly) |
| 3235 | 465 (display-buffer man-buffer 'not-this-window)) |
|
3307
1fc2bc44def7
(Man-notify-when-ready): Correct previous change.
Richard M. Stallman <rms@gnu.org>
parents:
3235
diff
changeset
|
466 ((eq Man-notify 'polite) |
| 3235 | 467 (beep) |
| 468 (message "Manual buffer %s is ready." (buffer-name man-buffer))) | |
|
3307
1fc2bc44def7
(Man-notify-when-ready): Correct previous change.
Richard M. Stallman <rms@gnu.org>
parents:
3235
diff
changeset
|
469 ((eq Man-notify 'quiet) |
| 3235 | 470 (message "Manual buffer %s is ready." (buffer-name man-buffer))) |
|
3307
1fc2bc44def7
(Man-notify-when-ready): Correct previous change.
Richard M. Stallman <rms@gnu.org>
parents:
3235
diff
changeset
|
471 ((or (eq Man-notify 'meek) |
| 3235 | 472 t) |
| 473 (message "")) | |
| 474 )) | |
| 475 | |
|
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
476 (defun Man-set-fonts () |
|
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
477 (goto-char (point-min)) |
|
4203
b42338a458a5
(Man-set-fonts): Don't look for another char after
Richard M. Stallman <rms@gnu.org>
parents:
4175
diff
changeset
|
478 (while (re-search-forward "\\(.\b\\)+" nil t) |
|
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
479 (let ((st (match-beginning 0)) (en (match-end 0))) |
|
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
480 (goto-char st) |
|
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
481 (if window-system |
|
4203
b42338a458a5
(Man-set-fonts): Don't look for another char after
Richard M. Stallman <rms@gnu.org>
parents:
4175
diff
changeset
|
482 (put-text-property st (if (= en (point-max)) en (1+ en)) 'face |
|
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
483 (if (looking-at "_") 'underline 'bold))) |
|
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
484 (while (and (< (point) en) (looking-at ".\b")) |
|
4203
b42338a458a5
(Man-set-fonts): Don't look for another char after
Richard M. Stallman <rms@gnu.org>
parents:
4175
diff
changeset
|
485 (replace-match ""))))) |
|
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
486 |
| 3235 | 487 (defun Man-bgproc-sentinel (process msg) |
| 488 "Manpage background process sentinel." | |
| 489 (let ((Man-buffer (process-buffer process)) | |
| 490 (delete-buff nil) | |
| 491 (err-mess nil)) | |
| 492 (if (null (buffer-name Man-buffer)) ;; deleted buffer | |
| 493 (set-process-buffer process nil) | |
| 494 (save-excursion | |
| 495 (set-buffer Man-buffer) | |
| 496 (goto-char (point-min)) | |
| 497 (cond ((or (looking-at "No \\(manual \\)*entry for") | |
| 498 (looking-at "[^\n]*: nothing appropriate$")) | |
| 499 (setq err-mess (buffer-substring (point) (Man-linepos 'eol)) | |
| 500 delete-buff t) | |
| 501 ) | |
| 502 ((not (and (eq (process-status process) 'exit) | |
| 503 (= (process-exit-status process) 0))) | |
| 504 (setq err-mess | |
| 505 (concat (buffer-name Man-buffer) | |
| 506 ": process " | |
| 507 (let ((eos (1- (length msg)))) | |
| 508 (if (= (aref msg eos) ?\n) | |
| 509 (substring msg 0 eos) msg)))) | |
| 510 (goto-char (point-max)) | |
| 511 (insert (format "\nprocess %s" msg)) | |
| 512 ))) | |
| 513 (if delete-buff | |
| 514 (kill-buffer Man-buffer) | |
| 515 (save-window-excursion | |
| 516 (save-excursion | |
| 517 (set-buffer Man-buffer) | |
|
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
518 (Man-set-fonts) |
| 3235 | 519 (Man-mode) |
| 520 (set-buffer-modified-p nil))) | |
| 521 (Man-notify-when-ready Man-buffer)) | |
| 522 | |
| 523 (if err-mess | |
| 524 (error err-mess)) | |
| 525 ))) | |
| 526 | |
| 527 | |
| 528 ;; ====================================================================== | |
| 529 ;; set up manual mode in buffer and build alists | |
| 530 | |
| 531 (defun Man-mode () | |
|
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
532 "A mode for browsing Un*x manual pages. |
| 3235 | 533 |
| 534 The following man commands are available in the buffer. Try | |
| 535 \"\\[describe-key] <key> RET\" for more information: | |
| 536 | |
| 537 \\[manual-entry] Prompt to retrieve a new manpage. | |
| 538 \\[Man-follow-manual-reference] Retrieve reference in SEE ALSO section. | |
| 539 \\[Man-next-manpage] Jump to next manpage in circular list. | |
| 540 \\[Man-previous-manpage] Jump to previous manpage in circular list. | |
| 541 \\[Man-next-section] Jump to next manpage section. | |
| 542 \\[Man-previous-section] Jump to previous manpage section. | |
| 543 \\[Man-goto-section] Go to a manpage section. | |
| 544 \\[Man-goto-see-also-section] Jumps to the SEE ALSO manpage section. | |
| 545 \\[Man-quit] Deletes the manpage, its buffer, and window. | |
| 546 \\[describe-mode] Prints this help text. | |
| 547 | |
| 548 The following variables may be of some use. Try | |
| 549 \"\\[describe-variable] <variable-name> RET\" for more information: | |
| 550 | |
| 551 Man-notify What happens when manpage formatting is done. | |
| 552 Man-reuse-okay-p Okay to reuse already formatted buffer? | |
| 553 Man-downcase-section-letters-p Force section letters to lower case? | |
| 554 Man-circular-pages-p Multiple manpage list treated as circular? | |
| 555 Man-auto-section-alist List of major modes and their section numbers. | |
| 556 Man-section-translations-alist List of section numbers and their Un*x equiv. | |
| 557 Man-filter-list Background manpage filter command. | |
| 558 Man-mode-line-format Mode line format for Man-mode buffers. | |
| 559 Man-mode-map Keymap bindings for Man-mode buffers. | |
| 560 Man-mode-hooks Hooks for Man-mode. | |
| 561 Man-section-regexp Regexp describing manpage section letters. | |
| 562 Man-heading-regexp Regexp describing section headers. | |
| 563 Man-see-also-regexp Regexp for SEE ALSO section (or your equiv). | |
| 564 Man-first-heading-regexp Regexp for first heading on a manpage. | |
| 565 Man-reference-regexp Regexp matching a references in SEE ALSO. | |
|
3833
70551a213fae
* man.el (Man-switches): New variable.
Jim Blandy <jimb@redhat.com>
parents:
3714
diff
changeset
|
566 Man-switches Background `man' command switches. |
| 3235 | 567 |
| 568 The following key bindings are currently in effect in the buffer: | |
| 569 \\{Man-mode-map}" | |
| 570 (interactive) | |
| 571 (setq major-mode 'Man-mode | |
|
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
572 mode-name "Man" |
| 3235 | 573 buffer-auto-save-file-name nil |
| 574 mode-line-format Man-mode-line-format | |
| 575 truncate-lines t | |
| 576 buffer-read-only t) | |
| 577 (buffer-disable-undo (current-buffer)) | |
| 578 (auto-fill-mode -1) | |
| 579 (use-local-map Man-mode-map) | |
| 580 (goto-char (point-min)) | |
| 581 (Man-build-page-list) | |
|
3619
062dbb10173d
(Man-mode): Run Man-mode-hook.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
582 (Man-goto-page 1) |
|
062dbb10173d
(Man-mode): Run Man-mode-hook.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
583 (run-hooks 'Man-mode-hook)) |
| 3235 | 584 |
| 585 (defun Man-build-section-alist () | |
| 586 "Build the association list of manpage sections." | |
| 587 (setq Man-sections-alist nil) | |
| 588 (goto-char (point-min)) | |
| 589 (while (re-search-forward Man-heading-regexp (point-max) t) | |
| 590 (aput 'Man-sections-alist | |
| 591 (buffer-substring (Man-linepos 'bol) (Man-linepos))) | |
| 592 (forward-line 1) | |
| 593 )) | |
| 594 | |
| 595 (defun Man-build-references-alist () | |
| 596 "Build the association list of references (in the SEE ALSO section)." | |
| 597 (setq Man-refpages-alist nil) | |
| 598 (save-excursion | |
| 599 (if (Man-find-section Man-see-also-regexp) | |
| 600 (let ((start (progn (forward-line 1) (point))) | |
| 601 (end (progn | |
| 602 (Man-next-section 1) | |
| 603 (point))) | |
| 604 hyphenated | |
| 605 (runningpoint -1)) | |
| 606 (narrow-to-region start end) | |
| 607 (goto-char (point-min)) | |
| 608 (back-to-indentation) | |
| 609 (while (and (not (eobp)) (/= (point) runningpoint)) | |
| 610 (setq runningpoint (point)) | |
|
4377
09cb5e07f8a3
(Man-build-references-alist): When setting word,
Richard M. Stallman <rms@gnu.org>
parents:
4334
diff
changeset
|
611 (let* ((eow (re-search-forward Man-reference-regexp end t)) |
|
09cb5e07f8a3
(Man-build-references-alist): When setting word,
Richard M. Stallman <rms@gnu.org>
parents:
4334
diff
changeset
|
612 (word (buffer-substring (match-beginning 0) (match-end 0))) |
| 3235 | 613 (len (1- (length word)))) |
| 614 (if (not eow) nil | |
| 615 (if hyphenated | |
| 616 (setq word (concat hyphenated word) | |
| 617 hyphenated nil)) | |
| 618 (if (= (aref word len) ?-) | |
| 619 (setq hyphenated (substring word 0 len)) | |
| 620 (aput 'Man-refpages-alist word)))) | |
| 621 (skip-chars-forward " \t\n,")) | |
| 622 )))) | |
| 623 | |
| 624 (defun Man-build-page-list () | |
| 625 "Build the list of separate manpages in the buffer." | |
| 626 (setq Man-page-list nil) | |
| 627 (save-excursion | |
| 628 (let ((page-start (Man-linepos 'bob)) | |
| 629 (page-end (Man-linepos 'eob)) | |
| 630 (regexp Man-first-heading-regexp)) | |
| 631 (goto-char (point-min)) | |
| 632 (re-search-forward regexp (point-max) t) | |
| 633 (while (not (eobp)) | |
| 634 (if (re-search-forward regexp (point-max) t) | |
| 635 (progn | |
| 636 (setq page-end (Man-linepos 'bol)) | |
| 637 (end-of-line)) | |
| 638 (goto-char (point-max)) | |
| 639 (setq page-end (point))) | |
| 640 (setq Man-page-list (append Man-page-list | |
| 641 (list (cons page-start page-end))) | |
| 642 page-start page-end) | |
| 643 )))) | |
| 644 | |
| 645 | |
| 646 ;; ====================================================================== | |
| 647 ;; Man-mode commands | |
| 648 | |
| 649 (defun Man-next-section (n) | |
| 650 "Move point to Nth next section (default 1)." | |
| 651 (interactive "p") | |
| 652 (if (looking-at Man-heading-regexp) | |
| 653 (forward-line 1)) | |
| 654 (if (re-search-forward Man-heading-regexp (point-max) t n) | |
| 655 (beginning-of-line) | |
| 656 (goto-char (point-max)))) | |
| 657 | |
| 658 (defun Man-previous-section (n) | |
| 659 "Move point to Nth previous section (default 1)." | |
| 660 (interactive "p") | |
| 661 (if (looking-at Man-heading-regexp) | |
| 662 (forward-line -1)) | |
| 663 (if (re-search-backward Man-heading-regexp (point-min) t n) | |
| 664 (beginning-of-line) | |
| 665 (goto-char (point-min)))) | |
| 666 | |
| 667 (defun Man-find-section (section) | |
| 668 "Move point to SECTION if it exists, otherwise don't move point. | |
| 669 Returns t if section is found, nil otherwise." | |
| 670 (let ((curpos (point))) | |
| 671 (goto-char (point-min)) | |
|
4334
b39cd3621215
* man.el (Man-find-section): HP/UX man pages have section names
Jim Blandy <jimb@redhat.com>
parents:
4329
diff
changeset
|
672 (if (re-search-forward (concat "^\\s-?" section) (point-max) t) |
| 3235 | 673 (progn (beginning-of-line) t) |
| 674 (goto-char curpos) | |
| 675 nil) | |
| 676 )) | |
| 677 | |
| 678 (defun Man-goto-section () | |
| 679 "Query for section to move point to." | |
| 680 (interactive) | |
| 681 (aput 'Man-sections-alist | |
| 682 (let* ((default (aheadsym Man-sections-alist)) | |
| 683 (completion-ignore-case t) | |
| 684 chosen | |
| 685 (prompt (concat "Go to section: (default " default ") "))) | |
| 686 (setq chosen (completing-read prompt Man-sections-alist)) | |
| 687 (if (or (not chosen) | |
| 688 (string= chosen "")) | |
| 689 default | |
| 690 chosen))) | |
| 691 (Man-find-section (aheadsym Man-sections-alist))) | |
| 692 | |
| 693 (defun Man-goto-see-also-section () | |
| 694 "Move point the the \"SEE ALSO\" section. | |
|
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
695 Actually the section moved to is described by `Man-see-also-regexp'." |
| 3235 | 696 (interactive) |
| 697 (if (not (Man-find-section Man-see-also-regexp)) | |
| 698 (error (concat "No " Man-see-also-regexp | |
| 699 " section found in current manpage.")))) | |
| 700 | |
| 701 (defun Man-follow-manual-reference (arg) | |
| 702 "Get one of the manpages referred to in the \"SEE ALSO\" section. | |
|
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
703 Queries you for the page to retrieve. Of course it does this in the |
|
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
704 background. Universal argument ARG is passed to `Man-getpage-in-background'." |
| 3235 | 705 (interactive "P") |
| 706 (if (not Man-refpages-alist) | |
| 707 (error (concat "No references found in current manpage.")) | |
| 708 (aput 'Man-refpages-alist | |
| 709 (let* ((default (aheadsym Man-refpages-alist)) | |
| 710 chosen | |
| 711 (prompt (concat "Refer to: (default " default ") "))) | |
| 712 (setq chosen (completing-read prompt Man-refpages-alist nil t)) | |
| 713 (if (or (not chosen) | |
| 714 (string= chosen "")) | |
| 715 default | |
| 716 chosen))) | |
| 717 (Man-getpage-in-background | |
| 718 (Man-translate-references (aheadsym Man-refpages-alist)) | |
| 719 (consp arg)))) | |
| 720 | |
| 721 (defun Man-quit () | |
| 722 "Kill the buffer containing the manpage." | |
| 723 (interactive) | |
| 724 (let ((buff (current-buffer))) | |
| 725 (delete-windows-on buff) | |
| 726 (kill-buffer buff))) | |
| 727 | |
| 728 (defun Man-goto-page (page) | |
| 729 "Go to the manual page on page PAGE." | |
| 730 (interactive | |
| 731 (if (not Man-page-list) | |
| 732 (error "You're looking at the only manpage in the buffer.") | |
| 733 (format "nGo to manpage [1-%d]: " (length Man-page-list)))) | |
| 734 (if (or (< page 1) | |
| 735 (> page (length Man-page-list))) | |
| 736 (error "No manpage %d found" page)) | |
| 737 (let* ((page-range (nth (1- page) Man-page-list)) | |
| 738 (page-start (car page-range)) | |
| 739 (page-end (cdr page-range))) | |
| 740 (setq Man-current-page page | |
| 741 Man-page-mode-string (Man-page-mode-string)) | |
| 742 (widen) | |
| 743 (goto-char page-start) | |
| 744 (narrow-to-region page-start page-end) | |
| 745 (Man-build-section-alist) | |
|
3659
296caa999ccf
(Man-filter-list): Add an element for X man pages.
Richard M. Stallman <rms@gnu.org>
parents:
3644
diff
changeset
|
746 ;; Don't let bugs in Man-build-references-alist |
|
296caa999ccf
(Man-filter-list): Add an element for X man pages.
Richard M. Stallman <rms@gnu.org>
parents:
3644
diff
changeset
|
747 ;; interfere with ordinary use of this package. |
|
296caa999ccf
(Man-filter-list): Add an element for X man pages.
Richard M. Stallman <rms@gnu.org>
parents:
3644
diff
changeset
|
748 (condition-case nil |
|
296caa999ccf
(Man-filter-list): Add an element for X man pages.
Richard M. Stallman <rms@gnu.org>
parents:
3644
diff
changeset
|
749 (Man-build-references-alist) |
|
296caa999ccf
(Man-filter-list): Add an element for X man pages.
Richard M. Stallman <rms@gnu.org>
parents:
3644
diff
changeset
|
750 (error)) |
| 3235 | 751 (widen) |
| 752 (narrow-to-region page-start page-end) | |
| 753 (goto-char (point-min)))) | |
| 754 | |
| 755 | |
| 756 (defun Man-next-manpage () | |
| 757 "Find the next manpage entry in the buffer." | |
| 758 (interactive) | |
| 759 (if (= (length Man-page-list) 1) | |
| 760 (error "This is the only manpage in the buffer.")) | |
| 761 (if (< Man-current-page (length Man-page-list)) | |
| 762 (Man-goto-page (1+ Man-current-page)) | |
| 763 (if Man-circular-pages-p | |
| 764 (Man-goto-page 1) | |
| 765 (error "You're looking at the last manpage in the buffer.")))) | |
| 766 | |
| 767 (defun Man-previous-manpage () | |
| 768 "Find the previous manpage entry in the buffer." | |
| 769 (interactive) | |
| 770 (if (= (length Man-page-list) 1) | |
| 771 (error "This is the only manpage in the buffer.")) | |
| 772 (if (> Man-current-page 1) | |
| 773 (Man-goto-page (1- Man-current-page)) | |
| 774 (if Man-circular-pages-p | |
| 775 (Man-goto-page (length Man-page-list)) | |
| 776 (error "You're looking at the first manpage in the buffer.")))) | |
|
3833
70551a213fae
* man.el (Man-switches): New variable.
Jim Blandy <jimb@redhat.com>
parents:
3714
diff
changeset
|
777 |
|
70551a213fae
* man.el (Man-switches): New variable.
Jim Blandy <jimb@redhat.com>
parents:
3714
diff
changeset
|
778 (provide 'man) |
|
70551a213fae
* man.el (Man-switches): New variable.
Jim Blandy <jimb@redhat.com>
parents:
3714
diff
changeset
|
779 |
| 3235 | 780 ;;; man.el ends here |
