(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
"-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"
"'"
))
)
'("" 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.")
(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 ""
(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)))
(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)
(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,
;; 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.
(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))
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
(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
(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."
(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
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)