(rmail-make-basic-summary-line): Limit line count
[bpt/emacs.git] / lisp / man.el
index 55df16c..ccc03a9 100644 (file)
@@ -1,10 +1,8 @@
 ;;; man.el --- browse UNIX manual pages
 
-;; Copyright (C) 1993, 1994 Free Software Foundation, Inc.
+;; Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
 
 ;; Author:             Barry A. Warsaw <bwarsaw@cen.com>
-;; Last-Modified:      $Date: 1995/05/29 13:20:51 $
-;; Version:            $Revision: 1.62 $
 ;; Keywords:           help
 ;; Adapted-By:         ESR, pot
 
@@ -21,8 +19,9 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to
-;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+;; along with GNU Emacs; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
 
 ;;; Commentary:
 
@@ -37,7 +36,7 @@
 ;; ========== Credits and History ========== 
 ;; In mid 1991, several people posted some interesting improvements to
 ;; man.el from the standard emacs 18.57 distribution.  I liked many of
-;; these, but wanted everthing in one single package, so I decided
+;; these, but wanted everything in one single package, so I decided
 ;; to incorporate them into a single manual browsing mode.  While
 ;; much of the code here has been rewritten, and some features added,
 ;; these folks deserve lots of credit for providing the initial
@@ -58,7 +57,7 @@
 
 ;; Francesco Potorti` <pot@cnuce.cnr.it> cleaned it up thoroughly,
 ;; making it faster, more robust and more tolerant of different
-;; systems' man idiosynchrasies.
+;; systems' man idiosyncrasies.
 
 ;; ========== Features ==========
 ;; + Runs "man" in the background and pipes the results through a
 (defvar Man-notify)
 (defvar Man-current-page)
 (defvar Man-page-list)
-(defvar Man-filter-list)
+(defvar Man-filter-list nil
+  "*Manpage cleaning filter command phrases.
+This variable contains a list of the following form:
+
+'((command-string phrase-string*)*)
+
+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.")
+
 (defvar Man-original-frame)
 (defvar Man-arguments)
 (defvar Man-sections-alist)
 (defvar Man-refpages-alist)
-(defvar Man-uses-untabify-flag)
+(defvar Man-uses-untabify-flag t
+  "When non-nil use `untabify' instead of Man-untabify-command.")
 (defvar Man-page-mode-string)
-(defvar Man-sed-script)
+(defvar Man-sed-script nil
+  "Script for sed to nuke backspaces and ANSI codes from manpages.")
 
 ;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
 ;; user variables
   "*Face to use when fontifying overstrike.")
 
 (defvar Man-underline-face 'underline
-  "*Face to use when fontifying underlinining.")
+  "*Face to use when fontifying underlining.")
 
 ;; Use the value of the obsolete user option Man-notify, if set.
 (defvar Man-notify-method (if (boundp 'Man-notify) Man-notify 'friendly)
@@ -292,7 +304,6 @@ This regular expression should start with a `^' character.")
   (define-key Man-mode-map "<"    'beginning-of-buffer)
   (define-key Man-mode-map "."    'beginning-of-buffer)
   (define-key Man-mode-map "r"    'Man-follow-manual-reference)
-  (define-key Man-mode-map "t"    'toggle-truncate-lines)
   (define-key Man-mode-map "g"    'Man-goto-section)
   (define-key Man-mode-map "s"    'Man-goto-see-also-section)
   (define-key Man-mode-map "k"    'Man-kill)
@@ -305,7 +316,7 @@ This regular expression should start with a `^' character.")
 ;; ======================================================================
 ;; utilities
 
-(defsubst Man-init-defvars ()
+(defun Man-init-defvars ()
   "Used for initialising variables based on the value of window-system.
 This is necessary if one wants to dump man.el with emacs."
 
@@ -314,75 +325,56 @@ This is necessary if one wants to dump man.el with emacs."
   (setq Man-fontify-manpage-flag (and Man-fontify-manpage-flag
                                      window-system))
 
-  (defconst Man-uses-untabify-flag t
-    ;; don't use pr: it is buggy
-    ;; (or (not (file-readable-p "/etc/passwd"))
-    ;;   (/= 0 (apply 'call-process
-    ;;                Man-untabify-command nil nil nil
-    ;;                (append Man-untabify-command-args
-    ;;                        (list "/etc/passwd")))))
-    "When non-nil use `untabify' instead of Man-untabify-command.")
-
-  (defconst 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))
-    "Script for sed to nuke backspaces and ANSI codes from manpages.")
-
-  (defvar Man-filter-list
-    (list
-     (cons
-      Man-sed-command
-      (list
-       (if Man-sed-script
-          (concat "-e '" Man-sed-script "'")
-        "")
-       "-e '/^[\001-\032][\001-\032]*$/d'"
-       "-e '/\e[789]/s///g'"
-       "-e '/Reformatting page.  Wait/d'"
-       "-e '/Reformatting entry.  Wait/d'"
-       "-e '/^[ \t]*Hewlett-Packard[ \t]Company[ \t]*-[ \t][0-9]*[ \t]-/d'"
-       "-e '/^[ \t]*Hewlett-Packard[ \t]*-[ \t][0-9]*[ \t]-.*$/d'"
-       "-e '/^[ \t][ \t]*-[ \t][0-9]*[ \t]-[ \t]*Formatted:.*[0-9]$/d'"
-       "-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 '/^Sun[ \t]Release[ \t][0-9].*[0-9]$/d'"
-       "-e '/[ \t]*Copyright [0-9]* UNIX System Laboratories, Inc.$/d'"
-       ))
-     (cons
-      Man-awk-command
-      (list
-       "'\n"
-       "BEGIN { blankline=0; anonblank=0; }\n"
-       "/^$/ { if (anonblank==0) next; }\n"
-       "{ anonblank=1; }\n"
-       "/^$/ { blankline++; next; }\n"
-       "{ if (blankline>0) { print \"\"; blankline=0; } print $0; }\n"
-       "'"
-       ))
-     (if (not Man-uses-untabify-flag)
+  (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
         (cons
-         Man-untabify-command
-         Man-untabify-command-args)
-       ))
-    "*Manpage cleaning filter command phrases.
-This variable contains a list of the following form:
-
-'((command-string phrase-string*)*)
-
-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.")
+         Man-sed-command
+         (list
+          (if Man-sed-script
+              (concat "-e '" Man-sed-script "'")
+            "")
+          "-e '/^[\001-\032][\001-\032]*$/d'"
+          "-e '/\e[789]/s///g'"
+          "-e '/Reformatting page.  Wait/d'"
+          "-e '/Reformatting entry.  Wait/d'"
+          "-e '/^[ \t]*Hewlett-Packard[ \t]Company[ \t]*-[ \t][0-9]*[ \t]-/d'"
+          "-e '/^[ \t]*Hewlett-Packard[ \t]*-[ \t][0-9]*[ \t]-.*$/d'"
+          "-e '/^[ \t][ \t]*-[ \t][0-9]*[ \t]-[ \t]*Formatted:.*[0-9]$/d'"
+          "-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 '/^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'"
+          ))
+        (cons
+         Man-awk-command
+         (list
+          "'\n"
+          "BEGIN { blankline=0; anonblank=0; }\n"
+          "/^$/ { if (anonblank==0) next; }\n"
+          "{ anonblank=1; }\n"
+          "/^$/ { blankline++; next; }\n"
+          "{ if (blankline>0) { print \"\"; blankline=0; } print $0; }\n"
+          "'"
+          ))
+        (if (not Man-uses-untabify-flag)
+            (cons
+             Man-untabify-command
+             Man-untabify-command-args)
+          )))
 )
 
 (defsubst Man-match-substring (&optional n string)
@@ -424,17 +416,17 @@ that string instead of from the current buffer."
   "Translates REF from \"chmod(2V)\" to \"2v chmod\" style.
 Leave it as is if already in that style.  Possibly downcase and
 translate the section (see the Man-downcase-section-letters-flag
-and the Man-section-translations-alist variables)." 
+and the Man-section-translations-alist variables)."
   (let ((name "")
        (section "")
        (slist Man-section-translations-alist))
     (cond
      ;; "chmod(2V)" case ?
-     ((string-match (concat Man-reference-regexp "$") ref)
+     ((string-match (concat "^" Man-reference-regexp "$") ref)
       (setq name (Man-match-substring 1 ref)
            section (Man-match-substring 2 ref)))
      ;; "2v chmod" case ?
-     ((string-match (concat "\\(" Man-section-regexp
+     ((string-match (concat "^\\(" Man-section-regexp
                            "\\) +\\(" Man-name-regexp "\\)$") ref)
       (setq name (Man-match-substring 2 ref)
            section (Man-match-substring 1 ref))))
@@ -518,9 +510,6 @@ If a buffer already exists for this man page, it will display immediately."
                 default-entry)
             input))))
 
-  ;; Init the man package variables, if not already done.
-  (Man-init-defvars)
-
   ;; Possibly translate the "subject(section)" syntax into the
   ;; "section subject" syntax and possibly downcase the section.
   (setq man-args (Man-translate-references man-args))
@@ -626,6 +615,9 @@ 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 "-"))
   (message "%s man page made up" Man-arguments))
 
 (defun Man-cleanup-manpage ()
@@ -649,6 +641,9 @@ 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 "-"))
   (message "%s man page cleaned up" Man-arguments))
 
 (defun Man-bgproc-sentinel (process msg)
@@ -1059,6 +1054,9 @@ Specify which reference to use; default is based on word at point."
        (Man-goto-page (length Man-page-list))
       (error "You're looking at the first manpage in the buffer"))))
 \f
+;; Init the man package variables, if not already done.
+(Man-init-defvars)
+
 (provide 'man)
 
 ;;; man.el ends here