]> code.delx.au - gnu-emacs/blobdiff - lisp/man.el
(diary-display-hook): Change default and fix doc string.
[gnu-emacs] / lisp / man.el
index 38f158beff03b41fd275b6e13936a432062e7c9d..1e60e660b49962844a5d5f955dce432c2436cdfe 100644 (file)
@@ -125,6 +125,8 @@ in all sections.")
 
 (defvar Man-section-translations-alist
   '(("3C++" . "3")
+    ("3X" . "3")                        ; Xlib man pages
+    ("3X11" . "3")
     ("1-UCB" . ""))
   "*Association list of bogus sections to real section numbers.
 Some manpages (e.g. the Sun C++ 2.1 manpages) have section numbers in
@@ -147,12 +149,12 @@ the associated section number.")
       "-e '/^Sun Release [0-9].*[0-9]$/d'"
       "-e '/^\\n$/D'"
       ))
-    ("awk '"
-     ("BEGIN { blankline=0; anonblank=0; }"
-      "/^$/ { if (anonblank==0) next; }"
-      "{ anonblank=1; }"
-      "/^$/ { blankline++; next; }"
-      "{ if (blankline>0) { print \"\"; blankline=0; } print $0; }"
+    ("awk '\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"
       "'"
       ))
      )
@@ -171,7 +173,7 @@ the manpage buffer.")
   '("" mode-line-modified
        mode-line-buffer-identification "   "
        global-mode-string
-       Man-page-mode-string
+       " " Man-page-mode-string
        "    %[(" mode-name minor-mode-alist mode-line-process ")%]----"
        (-3 . "%p") "-%-")
   "*Mode line format for manual mode buffer.")
@@ -185,18 +187,19 @@ the manpage buffer.")
 (defvar Man-section-regexp "[0-9][a-zA-Z+]*"
   "*Regular expression describing a manpage section within parentheses.")
 
-(defvar Man-heading-regexp "^[A-Z]"
+(defvar Man-heading-regexp "^ ?[A-Z]"
   "*Regular expression describing a manpage heading entry.")
 
 (defvar Man-see-also-regexp "SEE ALSO"
   "*Regular expression for SEE ALSO heading (or your equivalent).
 This regexp should not start with a `^' character.")
 
-(defvar Man-first-heading-regexp "^NAME$\\|^No manual entry for .*$"
+(defvar Man-first-heading-regexp "^ ?NAME$\\|^ ?No manual entry for .*$"
   "*Regular expression describing first heading on a manpage.
 This regular expression should start with a `^' character.")
 
-(defvar Man-reference-regexp "[-a-zA-Z0-9_.]+\\(([0-9][a-zA-Z+]*)\\)?"
+(defvar Man-reference-regexp
+  "[-a-zA-Z0-9_][-a-zA-Z0-9_.]*\\(([0-9][a-zA-Z+]*)\\)?"
   "*Regular expression describing a reference in the SEE ALSO section.")
 
 (defvar Man-switches ""
@@ -254,7 +257,7 @@ This regular expression should start with a `^' character.")
 
 (defun Man-build-man-command ()
   "Builds the entire background manpage and cleaning command."
-  (let ((command (concat "man " Man-switches " %s 2>&1 | "))
+  (let ((command (concat "man " Man-switches " %s 2>&1"))
        (flist Man-filter-list))
     (while flist
       (let ((pcom (car (car flist)))
@@ -263,11 +266,9 @@ This regular expression should start with a `^' character.")
        (if (or (not (stringp pcom))
                (not (listp pargs)))
            (error "malformed Man-filter-list."))
-       (setq command (concat command pcom
+       (setq command (concat command " | " pcom
                              (mapconcat '(lambda (phrase) phrase)
-                                        pargs " "))))
-      (if flist
-         (setq command (concat command " | " ))))
+                                        pargs " ")))))
     command))
 
 (defun Man-downcase (man-args)
@@ -342,29 +343,19 @@ the current column instead of character position."
 
 (defun Man-default-man-args (manword)
   "Build the default man args from MANWORD and buffer's major mode."
-  (let ((mode major-mode)
-       (slist Man-auto-section-alist))
-    (while (and slist
-               (not (eq (car (car slist)) mode)))
-      (setq slist (cdr slist)))
-    (if (not slist)
-       manword
-      (let ((sections (cdr (car slist))))
-       (if (not (listp sections))
-           (concat sections " " manword)
-         (let ((manarg ""))
-           (while sections
-             (setq manarg (concat manarg " " (car sections) " " manword))
-             (setq sections (cdr sections)))
-           manarg)
-         )))))
+  (let ((sections (cdr (assq major-mode Man-auto-section-alist))))
+    (cond
+     ((null sections) manword)
+     ((consp sections) 
+      (mapconcat (lambda (n) (concat n " " manword)) sections " "))
+     (t
+      (concat sections " " manword)))))
 
 (defun Man-default-man-entry ()
   "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-section nil)
-       default-title)
+  (let (default-title)
     (save-excursion
       
       ;; Default man entry title is any word the cursor is on,
@@ -383,25 +374,25 @@ default section number is selected from `Man-auto-section-alist'."
       ;; section number in default-entry
       (if (looking-at "[ \t]*([ \t]*[0-9][a-zA-Z]?[ \t]*)")
          (progn (skip-chars-forward "^0-9")
-                (setq default-section
-                      (buffer-substring
-                       (point)
-                       (progn
-                         (skip-chars-forward "0-9a-zA-Z")
-                         (point)))))
-       
-       ;; Otherwise, assume section number to be 2 if we're
-       ;; in C code
-       (and (eq major-mode 'c-mode)
-            (setq default-section "2")))
-      (if default-section
-         (format "%s %s" default-section default-title)
-       default-title))))
+                (setq default-title
+                      (concat (buffer-substring
+                               (point)
+                               (progn
+                                 (skip-chars-forward "0-9a-zA-Z")
+                                 (point)))
+                              " "
+                              default-title)))
+       (setq default-title (Man-default-man-args default-title)))
+      default-title)))
         
 \f
 ;; ======================================================================
 ;; top level command and background process sentinel
 
+;;; This alias makes completion more predictable if ignoring case.
+;;;###autoload
+(defalias 'man 'manual-entry)
+
 ;;;###autoload
 (defun manual-entry (arg)
   "Get a Un*x manual page and put it in a buffer.
@@ -421,13 +412,10 @@ Universal argument ARG, is passed to `Man-getpage-in-background'."
         (if (string= default-entry "")
             (error "No man args given.")
           (setq man-args default-entry)))
+
     ;; Recognize the subject(section) syntax.
-    (if (string-match "^[ \t]*\\([^( \t]+\\)[ \t]*(\\([^)]+\\))[ \t]*$"
-                     man-args)
-       (setq man-args
-             (concat (substring man-args (match-beginning 2) (match-end 2))
-                     " "
-                     (substring man-args (match-beginning 1) (match-end 1)))))
+    (setq man-args (Man-translate-references man-args))
+
     (if Man-downcase-section-letters-p
        (setq man-args (Man-downcase man-args)))
     (Man-getpage-in-background man-args (consp arg))
@@ -438,7 +426,7 @@ Universal argument ARG, is passed to `Man-getpage-in-background'."
 Optional OVERRIDE-REUSE-P, when non-nil, means to
 start a background process even if a buffer already exists and
 `Man-reuse-okay-p' is non-nil."
-  (let* ((man-args (Man-default-man-args TOPIC))
+  (let* ((man-args TOPIC)
         (bufname (concat "*man " man-args "*"))
         (buffer  (get-buffer bufname)))
     (if (and Man-reuse-okay-p
@@ -447,7 +435,7 @@ start a background process even if a buffer already exists and
        (Man-notify-when-ready buffer)
       (message "Invoking man %s in background..." man-args)
       (setq buffer (generate-new-buffer bufname))
-      (let ((process-environment process-environment))
+      (let ((process-environment (copy-sequence process-environment)))
        ;; Prevent any attempt to use display terminal fanciness.
        (setenv "TERM" "dumb")
        (set-process-sentinel
@@ -479,14 +467,14 @@ See the variable `Man-notify' for the different notification behaviors."
 
 (defun Man-set-fonts ()
   (goto-char (point-min))
-  (while (re-search-forward "\\(.\b.\\)+" nil t)
+  (while (re-search-forward "\\(.\b\\)+" nil t)
     (let ((st (match-beginning 0)) (en (match-end 0)))
       (goto-char st)
       (if window-system
-         (put-text-property st en 'face 
+         (put-text-property st (if (= en (point-max)) en (1+ en)) 'face 
                             (if (looking-at "_") 'underline 'bold)))
       (while (and (< (point) en) (looking-at ".\b"))
-       (replace-match "") (forward-char 1)))))
+       (replace-match "")))))
 
 (defun Man-bgproc-sentinel (process msg)
   "Manpage background process sentinel."
@@ -612,9 +600,8 @@ The following key bindings are currently in effect in the buffer:
          (back-to-indentation)
          (while (and (not (eobp)) (/= (point) runningpoint))
            (setq runningpoint (point))
-           (let* ((bow (point))
-                  (eow (re-search-forward Man-reference-regexp end t))
-                  (word (buffer-substring bow (match-end 0)))
+           (let* ((eow (re-search-forward Man-reference-regexp end t))
+                  (word (buffer-substring (match-beginning 0) (match-end 0)))
                   (len (1- (length word))))
              (if (not eow) nil
                (if hyphenated
@@ -674,7 +661,7 @@ The following key bindings are currently in effect in the buffer:
 Returns t if section is found, nil otherwise."
   (let ((curpos (point)))
     (goto-char (point-min))
-    (if (re-search-forward (concat "^" section) (point-max) t)
+    (if (re-search-forward (concat "^\\s-?" section) (point-max) t)
        (progn (beginning-of-line) t)
       (goto-char curpos)
       nil)