]> code.delx.au - gnu-emacs/blobdiff - lisp/man.el
(comint-postoutput-scroll-to-bottom): Cope with unset
[gnu-emacs] / lisp / man.el
index 551aad8234638cc3a8505a90d93cf3ede869169c..47475d28b2d00d09b8e6b57f891d49274c3e3bf7 100644 (file)
@@ -1,6 +1,6 @@
 ;;; man.el --- browse UNIX manual pages
 
-;; Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
+;; Copyright (C) 1993, 1994, 1996, 1997 Free Software Foundation, Inc.
 
 ;; Author:             Barry A. Warsaw <bwarsaw@cen.com>
 ;; Keywords:           help
 ;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
 ;; empty defvars (keep the compiler quiet)
 
+(defgroup man nil
+  "Browse UNIX manual pages."
+  :prefix "Man-"
+  :group 'help)
+
+
 (defvar Man-notify)
 (defvar Man-current-page)
 (defvar Man-page-list)
-(defvar Man-filter-list nil
+(defcustom Man-filter-list nil
   "*Manpage cleaning filter command phrases.
 This variable contains a list of the following form:
 
@@ -111,7 +117,11 @@ Each phrase-string is concatenated onto the command-string to form a
 command filter.  The (standard) output (and standard error) of the Un*x
 man command is piped through each command filter in the order the
 commands appear in the association list.  The final output is placed in
-the manpage buffer.")
+the manpage buffer."
+  :type '(repeat (list (string :tag "Command String")
+                      (repeat :inline t
+                              (string :tag "Phrase String"))))
+  :group 'man)
 
 (defvar Man-original-frame)
 (defvar Man-arguments)
@@ -126,17 +136,23 @@ the manpage buffer.")
 ;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
 ;; user variables
 
-(defvar Man-fontify-manpage-flag t
-  "*Make up the manpage with fonts.")
+(defcustom Man-fontify-manpage-flag t
+  "*Make up the manpage with fonts."
+  :type 'boolean
+  :group 'man)
 
-(defvar Man-overstrike-face 'bold
-  "*Face to use when fontifying overstrike.")
+(defcustom Man-overstrike-face 'bold
+  "*Face to use when fontifying overstrike."
+  :type 'face
+  :group 'man)
 
-(defvar Man-underline-face 'underline
-  "*Face to use when fontifying underlining.")
+(defcustom Man-underline-face 'underline
+  "*Face to use when fontifying underlining."
+  :type 'face
+  :group 'man)
 
 ;; Use the value of the obsolete user option Man-notify, if set.
-(defvar Man-notify-method (if (boundp 'Man-notify) Man-notify 'friendly)
+(defcustom Man-notify-method (if (boundp 'Man-notify) Man-notify 'friendly)
   "*Selects the behavior when manpage is ready.
 This variable may have one of the following values, where (sf) means
 that the frames are switched, so the manpage is displayed in the frame
@@ -151,23 +167,33 @@ polite     -- don't display manpage, but prints message and beep when ready
 quiet      -- like `polite', but don't beep
 meek       -- make no indication that the manpage is ready
 
-Any other value of `Man-notify-method' is equivalent to `meek'.")
+Any other value of `Man-notify-method' is equivalent to `meek'."
+  :type '(radio (const newframe) (const pushy) (const bully)
+               (const aggressive) (const friendly)
+               (const polite) (const quiet) (const meek))
+  :group 'man)
 
-(defvar Man-frame-parameters nil
-  "*Frame parameter list for creating a new frame for a manual page.")
+(defcustom Man-frame-parameters nil
+  "*Frame parameter list for creating a new frame for a manual page."
+  :type 'sexp
+  :group 'man)
 
-(defvar Man-downcase-section-letters-flag t
+(defcustom Man-downcase-section-letters-flag t
   "*Letters in sections are converted to lower case.
 Some Un*x man commands can't handle uppercase letters in sections, for
 example \"man 2V chmod\", but they are often displayed in the manpage
 with the upper case letter.  When this variable is t, the section
 letter (e.g., \"2V\") is converted to lowercase (e.g., \"2v\") before
-being sent to the man background process.")
+being sent to the man background process."
+  :type 'boolean
+  :group 'man)
 
-(defvar Man-circular-pages-flag t
-  "*If t, the manpage list is treated as circular for traversal.")
+(defcustom Man-circular-pages-flag t
+  "*If t, the manpage list is treated as circular for traversal."
+  :type 'boolean
+  :group 'man)
 
-(defvar Man-section-translations-alist
+(defcustom Man-section-translations-alist
   (list
    '("3C++" . "3")
    ;; Some systems have a real 3x man section, so let's comment this.
@@ -178,7 +204,10 @@ being sent to the man background process.")
 Some manpages (e.g. the Sun C++ 2.1 manpages) have section numbers in
 their references which Un*x `man' does not recognize.  This
 association list is used to translate those sections, when found, to
-the associated section number.")
+the associated section number."
+  :type '(repeat (cons (string :tag "Bogus Section")
+                      (string :tag "Real Section")))
+  :group 'man)
 
 (defvar manual-program "man"
   "The name of the program that produces man pages.")
@@ -196,12 +225,17 @@ the associated section number.")
   "Command used for processing awk scripts.")
 
 (defvar Man-mode-line-format
-  '("" mode-line-modified
-       mode-line-buffer-identification "  "
-       global-mode-string
-       " " Man-page-mode-string
-       "  %[(" mode-name mode-line-process minor-mode-alist ")%]----"
-       (-3 . "%p") "-%-")
+  '("-"
+    mode-line-mule-info
+    mode-line-modified
+    mode-line-frame-identification
+    mode-line-buffer-identification "  "
+    global-mode-string
+    " " Man-page-mode-string
+    "  %[(" mode-name mode-line-process minor-mode-alist "%n)%]--"
+    (line-number-mode "L%l--")
+    (column-number-mode "C%c--")
+    (-3 . "%p") "-%-")
   "Mode line format for manual mode buffer.")
 
 (defvar Man-mode-map nil
@@ -290,6 +324,13 @@ This regular expression should start with a `^' character.")
 /\e\\[[0-9][0-9]*m/ s///g"
   "Script for berkeley-like sed to nuke backspaces and ANSI codes from manpages.")
 
+(defvar man-mode-syntax-table
+  (let ((table (copy-syntax-table (standard-syntax-table))))
+    (modify-syntax-entry ?. "w" table)
+    (modify-syntax-entry ?_ "w" table)
+    table)
+  "Syntax table used in Man mode buffers.")
+
 (if Man-mode-map
     nil
   (setq Man-mode-map (make-keymap))
@@ -309,6 +350,7 @@ This regular expression should start with a `^' character.")
   (define-key Man-mode-map "k"    'Man-kill)
   (define-key Man-mode-map "q"    'Man-quit)
   (define-key Man-mode-map "m"    'man)
+  (define-key Man-mode-map "\r"   'man-follow)
   (define-key Man-mode-map "?"    'describe-mode)
   )
 
@@ -325,16 +367,18 @@ This is necessary if one wants to dump man.el with emacs."
   (setq Man-fontify-manpage-flag (and Man-fontify-manpage-flag
                                      window-system))
 
-  (setq Man-sed-script
-       (cond
-        (Man-fontify-manpage-flag
-         nil)
-        ((= 0 (call-process Man-sed-command nil nil nil Man-sysv-sed-script))
-         Man-sysv-sed-script)
-        ((= 0 (call-process Man-sed-command nil nil nil Man-berkeley-sed-script))
-         Man-berkeley-sed-script)
-        (t
-         nil)))
+  ;; Avoid possible error in call-process by using a directory that must exist.
+  (let ((default-directory "/"))
+    (setq Man-sed-script
+         (cond
+          (Man-fontify-manpage-flag
+           nil)
+          ((= 0 (call-process Man-sed-command nil nil nil Man-sysv-sed-script))
+           Man-sysv-sed-script)
+          ((= 0 (call-process Man-sed-command nil nil nil Man-berkeley-sed-script))
+           Man-berkeley-sed-script)
+          (t
+           nil))))
 
   (setq Man-filter-list
        (list
@@ -354,7 +398,7 @@ This is necessary if one wants to dump man.el with emacs."
           "-e '/^[ \t]*Page[ \t][0-9]*.*(printed[ \t][0-9\\/]*)$/d'"
           "-e '/^Printed[ \t][0-9].*[0-9]$/d'"
           "-e '/^[ \t]*X[ \t]Version[ \t]1[01].*Release[ \t][0-9]/d'"
-          "-e '/^[A-za-z].*Last[ \t]change:/d'"
+          "-e '/^[A-Za-z].*Last[ \t]change:/d'"
           "-e '/^Sun[ \t]Release[ \t][0-9].*[0-9]$/d'"
           "-e '/[ \t]*Copyright [0-9]* UNIX System Laboratories, Inc.$/d'"
           "-e '/^[ \t]*Rev\\..*Page [0-9][0-9]*$/d'"
@@ -462,31 +506,23 @@ and the Man-section-translations-alist variables)."
   "Make a guess at a default manual entry.
 This guess is based on the text surrounding the cursor, and the
 default section number is selected from `Man-auto-section-alist'."
-  (let (default-title)
+  (let (word)
     (save-excursion
-      
       ;; Default man entry title is any word the cursor is on, or if
-      ;; cursor not on a word, then nearest preceding word.  Cannot
-      ;; use the current-word function because it skips the dots.
-      (if (not (looking-at "[-a-zA-Z_.]"))
-         (skip-chars-backward "^a-zA-Z"))
-      (skip-chars-backward "-(a-zA-Z_0-9_.")
-      (if (looking-at "(") (forward-char 1))
-      (setq default-title
-           (buffer-substring
-            (point)
-            (progn (skip-chars-forward "-a-zA-Z0-9_.") (point))))
-      
+      ;; cursor not on a word, then nearest preceding word.
+      (setq word (current-word))
+      (if (string-match "[._]+$" word)
+         (setq word (substring word 0 (match-beginning 0))))
       ;; If looking at something like ioctl(2) or brc(1M), include the
       ;; section number in the returned value.  Remove text properties.
-      (let ((result (concat
-                    default-title
-                    (if (looking-at
-                         (concat "[ \t]*([ \t]*\\("
-                                 Man-section-regexp "\\)[ \t]*)"))
-                        (format "(%s)" (Man-match-substring 1))))))
-       (set-text-properties 0 (length result) nil result)
-       result))))
+      (forward-word 1)
+      ;; Use `format' here to clear any text props from `word'.
+      (format "%s%s"
+             word
+             (if (looking-at
+                  (concat "[ \t]*([ \t]*\\(" Man-section-regexp "\\)[ \t]*)"))
+                 (format "(%s)" (Man-match-substring 1))
+               "")))))
 
 \f
 ;; ======================================================================
@@ -523,6 +559,14 @@ If a buffer already exists for this man page, it will display immediately."
 
   (Man-getpage-in-background man-args))
 
+;;;###autoload
+(defun man-follow (man-args)
+  "Get a Un*x manual page of the item under point and put it in a buffer."
+  (interactive (list (Man-default-man-entry)))
+  (if (or (not man-args)
+         (string= man-args ""))
+      (error "No item under point")
+    (man man-args)))
 
 (defun Man-getpage-in-background (topic)
   "Uses TOPIC to build and fire off the manpage and cleaning command."
@@ -538,7 +582,12 @@ If a buffer already exists for this man page, it will display immediately."
        (set-buffer buffer)
        (setq Man-original-frame (selected-frame))
        (setq Man-arguments man-args))
-      (let ((process-environment (copy-sequence process-environment)))
+      (let ((process-environment (copy-sequence process-environment))
+           ;; The following is so Awk script gets \n intact
+           ;; But don't prevent decoding of the outside.
+           (coding-system-for-write 'raw-text-unix)
+           ;; Avoid possible error by using a directory that always exists.
+           (default-directory "/"))
        ;; Prevent any attempt to use display terminal fanciness.
        (setenv "TERM" "dumb")
        (if (fboundp 'start-process)
@@ -573,8 +622,9 @@ See the variable `Man-notify-method' for the different notification behaviors."
       ;; can't rely on the editor command loop to reselect the
       ;; selected window's buffer.
       (save-excursion
-       (set-buffer man-buffer)
-       (make-frame Man-frame-parameters)))
+       (let ((frame (make-frame Man-frame-parameters)))
+         (set-window-buffer (frame-selected-window frame) man-buffer)
+          (set-window-dedicated-p (frame-selected-window frame) t))))
      ((eq Man-notify-method 'pushy)
       (switch-to-buffer man-buffer))
      ((eq Man-notify-method 'bully)
@@ -603,6 +653,15 @@ See the variable `Man-notify-method' for the different notification behaviors."
       (message ""))
      )))
 
+(defun Man-softhyphen-to-minus ()
+  ;; \255 is some kind of dash in Latin-1.
+  (goto-char (point-min))
+  (if enable-multibyte-characters
+      (while (search-forward "\255" nil t)
+       (if (= (preceding-char) ?\255)
+           (replace-match "-")))
+    (while (search-forward "\255" nil t) (replace-match "-"))))
+
 (defun Man-fontify-manpage ()
   "Convert overstriking and underlining to the correct fonts.
 Same for the ANSI bold and normal escape sequences."
@@ -636,9 +695,7 @@ Same for the ANSI bold and normal escape sequences."
   (while (re-search-forward "[-|]\\(\b[-|]\\)+" nil t)
     (replace-match "+")
     (put-text-property (1- (point)) (point) 'face 'bold))
-  ;; \255 is some kind of dash in Latin-1.
-  (goto-char (point-min))
-  (while (search-forward "\255" nil t) (replace-match "-"))
+  (Man-softhyphen-to-minus)
   (message "%s man page made up" Man-arguments))
 
 (defun Man-cleanup-manpage ()
@@ -662,9 +719,7 @@ Same for the ANSI bold and normal escape sequences."
        ))
   (goto-char (point-min))
   (while (re-search-forward "[-|]\\(\b[-|]\\)+" nil t) (replace-match "+"))
-  ;; \255 is some kind of dash in Latin-1.
-  (goto-char (point-min))
-  (while (search-forward "\255" nil t) (replace-match "-"))
+  (Man-softhyphen-to-minus)
   (message "%s man page cleaned up" Man-arguments))
 
 (defun Man-bgproc-sentinel (process msg)
@@ -779,6 +834,7 @@ The following key bindings are currently in effect in the buffer:
   (buffer-disable-undo (current-buffer))
   (auto-fill-mode -1)
   (use-local-map Man-mode-map)
+  (set-syntax-table man-mode-syntax-table)
   (Man-build-page-list)
   (Man-strip-page-headers)
   (Man-unindent)
@@ -1011,26 +1067,12 @@ Specify which reference to use; default is based on word at point."
 (defun Man-kill ()
   "Kill the buffer containing the manpage."
   (interactive)
-  (let ((buff (current-buffer)))
-    (delete-windows-on buff)
-    (kill-buffer buff))
-  (if (and window-system
-          (or (eq Man-notify-method 'newframe)
-              (and pop-up-frames
-                   (eq Man-notify-method 'bully))))
-      (delete-frame)))
+  (quit-window t))
 
 (defun Man-quit ()
   "Bury the buffer containing the manpage."
   (interactive)
-  (let ((buff (current-buffer)))
-    (delete-windows-on buff)
-    (bury-buffer buff))
-  (if (and window-system
-          (or (eq Man-notify-method 'newframe)
-              (and pop-up-frames
-                   (eq Man-notify-method 'bully))))
-      (delete-frame)))
+  (quit-window))
 
 (defun Man-goto-page (page)
   "Go to the manual page on page PAGE."