diff options
| -rw-r--r-- | lisp/man.el | 182 |
1 files changed, 94 insertions, 88 deletions
diff --git a/lisp/man.el b/lisp/man.el index bbbc7519ea2..ba9930fc945 100644 --- a/lisp/man.el +++ b/lisp/man.el | |||
| @@ -98,10 +98,10 @@ Any other value of `Man-notify' is equivalent to `meek'.") | |||
| 98 | 98 | ||
| 99 | (defvar Man-reuse-okay-p t | 99 | (defvar Man-reuse-okay-p t |
| 100 | "*Reuse a manpage buffer if possible. | 100 | "*Reuse a manpage buffer if possible. |
| 101 | When t, and a manpage buffer already exists with the same invocation, | 101 | If non-nil, and a manpage buffer already exists with the same |
| 102 | man just indicates the manpage is ready according to the value of | 102 | invocation, man just indicates the manpage is ready according to the |
| 103 | `Man-notify'. When nil, it always fires off a background process, putting | 103 | value of `Man-notify'. When nil, it always fires off a background |
| 104 | the results in a uniquely named buffer.") | 104 | process, putting the results in a uniquely named buffer.") |
| 105 | 105 | ||
| 106 | (defvar Man-downcase-section-letters-p t | 106 | (defvar Man-downcase-section-letters-p t |
| 107 | "*Letters in sections are converted to lower case. | 107 | "*Letters in sections are converted to lower case. |
| @@ -148,12 +148,12 @@ the associated section number.") | |||
| 148 | "-e '/Reformatting page. Wait/d'" | 148 | "-e '/Reformatting page. Wait/d'" |
| 149 | "-e '/Reformatting entry. Wait/d'" | 149 | "-e '/Reformatting entry. Wait/d'" |
| 150 | "-e '/^ *\\([A-Za-z][A-Za-z.]*([0-9A-Za-z][-0-9A-Za-z+]*)\\).*\\1$/d'" | 150 | "-e '/^ *\\([A-Za-z][A-Za-z.]*([0-9A-Za-z][-0-9A-Za-z+]*)\\).*\\1$/d'" |
| 151 | "-e '/^[ \\t]*Hewlett-Packard Company[ \\t]*- [0-9]* -.*$/d'" | 151 | "-e '/^[ \t]*Hewlett-Packard Company[ \t]*- [0-9]* -.*$/d'" |
| 152 | "-e '/^[ \\t]*Hewlett-Packard[ \\t]*- [0-9]* -.*$/d'" | 152 | "-e '/^[ \t]*Hewlett-Packard[ \t]*- [0-9]* -.*$/d'" |
| 153 | "-e '/^ *- [0-9]* - *Formatted:.*[0-9]$/d'" | 153 | "-e '/^ *- [0-9]* - *Formatted:.*[0-9]$/d'" |
| 154 | "-e '/^ *Page [0-9]*.*(printed [0-9\\/]*)$/d'" | 154 | "-e '/^[ \t]*Page [0-9]*.*(printed [0-9\\/]*)$/d'" |
| 155 | "-e '/^Printed [0-9].*[0-9]$/d'" | 155 | "-e '/^Printed [0-9].*[0-9]$/d'" |
| 156 | "-e '/^[ \\t]*X Version 1[01].*Release [0-9]/d'" | 156 | "-e '/^[ \t]*X Version 1[01].*Release [0-9]/d'" |
| 157 | "-e '/^[A-za-z].*Last change:/d'" | 157 | "-e '/^[A-za-z].*Last change:/d'" |
| 158 | "-e '/^Sun Release [0-9].*[0-9]$/d'" | 158 | "-e '/^Sun Release [0-9].*[0-9]$/d'" |
| 159 | "-e '/^\\n$/D'" | 159 | "-e '/^\\n$/D'" |
| @@ -199,14 +199,14 @@ the manpage buffer.") | |||
| 199 | (defvar Man-section-regexp "[0-9][a-zA-Z+]*\\|[LNln]" | 199 | (defvar Man-section-regexp "[0-9][a-zA-Z+]*\\|[LNln]" |
| 200 | "*Regular expression describing a manpage section within parentheses.") | 200 | "*Regular expression describing a manpage section within parentheses.") |
| 201 | 201 | ||
| 202 | (defvar Man-heading-regexp "^ ?[A-Z]" | 202 | (defvar Man-heading-regexp "^[ \t]*[A-Z]" |
| 203 | "*Regular expression describing a manpage heading entry.") | 203 | "*Regular expression describing a manpage heading entry.") |
| 204 | 204 | ||
| 205 | (defvar Man-see-also-regexp "SEE ALSO" | 205 | (defvar Man-see-also-regexp "SEE ALSO" |
| 206 | "*Regular expression for SEE ALSO heading (or your equivalent). | 206 | "*Regular expression for SEE ALSO heading (or your equivalent). |
| 207 | This regexp should not start with a `^' character.") | 207 | This regexp should not start with a `^' character.") |
| 208 | 208 | ||
| 209 | (defvar Man-first-heading-regexp "^ ?NAME$\\|^ ?No manual entry for .*$" | 209 | (defvar Man-first-heading-regexp "^[ \t]*NAME$\\|^[ \t]*No manual entry fo.*$" |
| 210 | "*Regular expression describing first heading on a manpage. | 210 | "*Regular expression describing first heading on a manpage. |
| 211 | This regular expression should start with a `^' character.") | 211 | This regular expression should start with a `^' character.") |
| 212 | 212 | ||
| @@ -432,9 +432,9 @@ overrides this and forces the man page to be regenerated." | |||
| 432 | (let* ((default-entry (Man-default-man-entry)) | 432 | (let* ((default-entry (Man-default-man-entry)) |
| 433 | (man-args | 433 | (man-args |
| 434 | (read-string (format "Manual-entry: %s" | 434 | (read-string (format "Manual-entry: %s" |
| 435 | (if (string= default-entry "") "" | 435 | (if (string= default-entry "") "" |
| 436 | (format "(default: %s) " | 436 | (format "(default: %s) " |
| 437 | default-entry)))))) | 437 | default-entry)))))) |
| 438 | (and (string= man-args "") | 438 | (and (string= man-args "") |
| 439 | (if (string= default-entry "") | 439 | (if (string= default-entry "") |
| 440 | (error "No man args given.") | 440 | (error "No man args given.") |
| @@ -462,7 +462,7 @@ start a background process even if a buffer already exists and | |||
| 462 | buffer) | 462 | buffer) |
| 463 | (Man-notify-when-ready buffer) | 463 | (Man-notify-when-ready buffer) |
| 464 | (require 'env) | 464 | (require 'env) |
| 465 | (message "Invoking man %s in background..." man-args) | 465 | (message "Invoking man %s in background." man-args) |
| 466 | (setq buffer (generate-new-buffer bufname)) | 466 | (setq buffer (generate-new-buffer bufname)) |
| 467 | (save-excursion | 467 | (save-excursion |
| 468 | (set-buffer buffer) | 468 | (set-buffer buffer) |
| @@ -474,7 +474,7 @@ start a background process even if a buffer already exists and | |||
| 474 | (start-process manual-program buffer "sh" "-c" | 474 | (start-process manual-program buffer "sh" "-c" |
| 475 | (format (Man-build-man-command) man-args)) | 475 | (format (Man-build-man-command) man-args)) |
| 476 | 'Man-bgproc-sentinel)) | 476 | 'Man-bgproc-sentinel)) |
| 477 | ))) | 477 | ))) |
| 478 | 478 | ||
| 479 | (defun Man-notify-when-ready (man-buffer) | 479 | (defun Man-notify-when-ready (man-buffer) |
| 480 | "Notify the user when MAN-BUFFER is ready. | 480 | "Notify the user when MAN-BUFFER is ready. |
| @@ -529,42 +529,42 @@ See the variable `Man-notify' for the different notification behaviors." | |||
| 529 | "Manpage background process sentinel." | 529 | "Manpage background process sentinel." |
| 530 | (let ((Man-buffer (process-buffer process)) | 530 | (let ((Man-buffer (process-buffer process)) |
| 531 | (delete-buff nil) | 531 | (delete-buff nil) |
| 532 | (err-mess nil)) | 532 | (err-mess nil) |
| 533 | (case-fold-search nil)) | ||
| 533 | (if (null (buffer-name Man-buffer)) ;; deleted buffer | 534 | (if (null (buffer-name Man-buffer)) ;; deleted buffer |
| 534 | (set-process-buffer process nil) | 535 | (set-process-buffer process nil) |
| 535 | (save-excursion | 536 | (save-match-data |
| 536 | (set-buffer Man-buffer) | 537 | (save-excursion |
| 537 | (goto-char (point-min)) | 538 | (set-buffer Man-buffer) |
| 538 | (cond ((or (looking-at "No \\(manual \\)*entry for") | 539 | (goto-char (point-min)) |
| 539 | (looking-at "[^\n]*: nothing appropriate$")) | 540 | (cond ((or (looking-at "No \\(manual \\)*entry for") |
| 540 | (setq err-mess (buffer-substring (point) (Man-linepos 'eol)) | 541 | (looking-at "[^\n]*: nothing appropriate$")) |
| 541 | delete-buff t) | 542 | (setq err-mess (buffer-substring (point) (Man-linepos 'eol)) |
| 542 | ) | 543 | delete-buff t)) |
| 543 | ((not (and (eq (process-status process) 'exit) | 544 | ((not (and (eq (process-status process) 'exit) |
| 544 | (= (process-exit-status process) 0))) | 545 | (= (process-exit-status process) 0))) |
| 545 | (setq err-mess | 546 | (setq err-mess |
| 546 | (concat (buffer-name Man-buffer) | 547 | (concat (buffer-name Man-buffer) |
| 547 | ": process " | 548 | ": process " |
| 548 | (let ((eos (1- (length msg)))) | 549 | (let ((eos (1- (length msg)))) |
| 549 | (if (= (aref msg eos) ?\n) | 550 | (if (= (aref msg eos) ?\n) |
| 550 | (substring msg 0 eos) msg)))) | 551 | (substring msg 0 eos) msg)))) |
| 551 | (goto-char (point-max)) | 552 | (goto-char (point-max)) |
| 552 | (insert (format "\nprocess %s" msg)) | 553 | (insert (format "\nprocess %s" msg)) |
| 553 | ))) | 554 | ))) |
| 554 | (if delete-buff | 555 | (if delete-buff |
| 555 | (kill-buffer Man-buffer) | 556 | (kill-buffer Man-buffer) |
| 556 | (save-window-excursion | 557 | (save-window-excursion |
| 557 | (save-excursion | 558 | (save-excursion |
| 558 | (set-buffer Man-buffer) | 559 | (set-buffer Man-buffer) |
| 559 | (Man-set-fonts) | 560 | (Man-set-fonts) |
| 560 | (run-hooks 'Man-cooked-hook) | 561 | (run-hooks 'Man-cooked-hook) |
| 561 | (Man-mode) | 562 | (Man-mode) |
| 562 | (set-buffer-modified-p nil))) | 563 | (set-buffer-modified-p nil))) |
| 563 | (Man-notify-when-ready Man-buffer)) | 564 | (Man-notify-when-ready Man-buffer)) |
| 564 | 565 | ||
| 565 | (if err-mess | 566 | (if err-mess |
| 566 | (error err-mess)) | 567 | (error err-mess)))))) |
| 567 | ))) | ||
| 568 | 568 | ||
| 569 | 569 | ||
| 570 | ;; ====================================================================== | 570 | ;; ====================================================================== |
| @@ -628,11 +628,11 @@ The following key bindings are currently in effect in the buffer: | |||
| 628 | "Build the association list of manpage sections." | 628 | "Build the association list of manpage sections." |
| 629 | (setq Man-sections-alist nil) | 629 | (setq Man-sections-alist nil) |
| 630 | (goto-char (point-min)) | 630 | (goto-char (point-min)) |
| 631 | (while (re-search-forward Man-heading-regexp (point-max) t) | 631 | (let ((case-fold-search nil)) |
| 632 | (aput 'Man-sections-alist | 632 | (while (re-search-forward Man-heading-regexp (point-max) t) |
| 633 | (buffer-substring (Man-linepos 'bol) (Man-linepos))) | 633 | (aput 'Man-sections-alist |
| 634 | (forward-line 1) | 634 | (buffer-substring (Man-linepos 'bol) (Man-linepos))) |
| 635 | )) | 635 | (forward-line 1)))) |
| 636 | 636 | ||
| 637 | (defun Man-build-references-alist () | 637 | (defun Man-build-references-alist () |
| 638 | "Build the association list of references (in the SEE ALSO section)." | 638 | "Build the association list of references (in the SEE ALSO section)." |
| @@ -645,23 +645,24 @@ The following key bindings are currently in effect in the buffer: | |||
| 645 | (point))) | 645 | (point))) |
| 646 | hyphenated | 646 | hyphenated |
| 647 | (runningpoint -1)) | 647 | (runningpoint -1)) |
| 648 | (narrow-to-region start end) | 648 | (save-restriction |
| 649 | (goto-char (point-min)) | 649 | (narrow-to-region start end) |
| 650 | (back-to-indentation) | 650 | (goto-char (point-min)) |
| 651 | (while (and (not (eobp)) (/= (point) runningpoint)) | 651 | (back-to-indentation) |
| 652 | (setq runningpoint (point)) | 652 | (while (and (not (eobp)) (/= (point) runningpoint)) |
| 653 | (let* ((eow (re-search-forward Man-reference-regexp end t)) | 653 | (setq runningpoint (point)) |
| 654 | (word (buffer-substring (match-beginning 0) (match-end 0))) | 654 | (let* ((eow (re-search-forward Man-reference-regexp end t)) |
| 655 | (len (1- (length word)))) | 655 | (word (buffer-substring |
| 656 | (if (not eow) nil | 656 | (match-beginning 0) (match-end 0))) |
| 657 | (if hyphenated | 657 | (len (1- (length word)))) |
| 658 | (setq word (concat hyphenated word) | 658 | (if (not eow) nil |
| 659 | hyphenated nil)) | 659 | (if hyphenated |
| 660 | (if (= (aref word len) ?-) | 660 | (setq word (concat hyphenated word) |
| 661 | (setq hyphenated (substring word 0 len)) | 661 | hyphenated nil)) |
| 662 | (aput 'Man-refpages-alist word)))) | 662 | (if (= (aref word len) ?-) |
| 663 | (skip-chars-forward " \t\n,")) | 663 | (setq hyphenated (substring word 0 len)) |
| 664 | )))) | 664 | (aput 'Man-refpages-alist word)))) |
| 665 | (skip-chars-forward " \t\n,"))))))) | ||
| 665 | 666 | ||
| 666 | (defun Man-build-page-list () | 667 | (defun Man-build-page-list () |
| 667 | "Build the list of separate manpages in the buffer." | 668 | "Build the list of separate manpages in the buffer." |
| @@ -680,9 +681,9 @@ The following key bindings are currently in effect in the buffer: | |||
| 680 | (goto-char (point-max)) | 681 | (goto-char (point-max)) |
| 681 | (setq page-end (point))) | 682 | (setq page-end (point))) |
| 682 | (setq Man-page-list (append Man-page-list | 683 | (setq Man-page-list (append Man-page-list |
| 683 | (list (cons page-start page-end))) | 684 | (list (cons page-start page-end))) |
| 684 | page-start page-end) | 685 | page-start page-end) |
| 685 | )))) | 686 | )))) |
| 686 | 687 | ||
| 687 | 688 | ||
| 688 | ;; ====================================================================== | 689 | ;; ====================================================================== |
| @@ -691,27 +692,30 @@ The following key bindings are currently in effect in the buffer: | |||
| 691 | (defun Man-next-section (n) | 692 | (defun Man-next-section (n) |
| 692 | "Move point to Nth next section (default 1)." | 693 | "Move point to Nth next section (default 1)." |
| 693 | (interactive "p") | 694 | (interactive "p") |
| 694 | (if (looking-at Man-heading-regexp) | 695 | (let ((case-fold-search nil)) |
| 695 | (forward-line 1)) | 696 | (if (looking-at Man-heading-regexp) |
| 696 | (if (re-search-forward Man-heading-regexp (point-max) t n) | 697 | (forward-line 1)) |
| 697 | (beginning-of-line) | 698 | (if (re-search-forward Man-heading-regexp (point-max) t n) |
| 698 | (goto-char (point-max)))) | 699 | (beginning-of-line) |
| 700 | (goto-char (point-max))))) | ||
| 699 | 701 | ||
| 700 | (defun Man-previous-section (n) | 702 | (defun Man-previous-section (n) |
| 701 | "Move point to Nth previous section (default 1)." | 703 | "Move point to Nth previous section (default 1)." |
| 702 | (interactive "p") | 704 | (interactive "p") |
| 703 | (if (looking-at Man-heading-regexp) | 705 | (let ((case-fold-search nil)) |
| 704 | (forward-line -1)) | 706 | (if (looking-at Man-heading-regexp) |
| 705 | (if (re-search-backward Man-heading-regexp (point-min) t n) | 707 | (forward-line -1)) |
| 706 | (beginning-of-line) | 708 | (if (re-search-backward Man-heading-regexp (point-min) t n) |
| 707 | (goto-char (point-min)))) | 709 | (beginning-of-line) |
| 710 | (goto-char (point-min))))) | ||
| 708 | 711 | ||
| 709 | (defun Man-find-section (section) | 712 | (defun Man-find-section (section) |
| 710 | "Move point to SECTION if it exists, otherwise don't move point. | 713 | "Move point to SECTION if it exists, otherwise don't move point. |
| 711 | Returns t if section is found, nil otherwise." | 714 | Returns t if section is found, nil otherwise." |
| 712 | (let ((curpos (point))) | 715 | (let ((curpos (point)) |
| 716 | (case-fold-search nil)) | ||
| 713 | (goto-char (point-min)) | 717 | (goto-char (point-min)) |
| 714 | (if (re-search-forward (concat "^\\s-?" section) (point-max) t) | 718 | (if (re-search-forward (concat "^[ \t]*" section) (point-max) t) |
| 715 | (progn (beginning-of-line) t) | 719 | (progn (beginning-of-line) t) |
| 716 | (goto-char curpos) | 720 | (goto-char curpos) |
| 717 | nil) | 721 | nil) |
| @@ -756,7 +760,8 @@ Prefix argument ARG is passed to `Man-getpage-in-background'." | |||
| 756 | (let ((word (current-word))) | 760 | (let ((word (current-word))) |
| 757 | ;; strip a trailing '-': | 761 | ;; strip a trailing '-': |
| 758 | (if (string-match "-$" word) | 762 | (if (string-match "-$" word) |
| 759 | (substring word 0 (match-beginning 0)) | 763 | (substring word 0 |
| 764 | (match-beginning 0)) | ||
| 760 | word))) | 765 | word))) |
| 761 | Man-refpages-alist)) | 766 | Man-refpages-alist)) |
| 762 | (aheadsym Man-refpages-alist))) | 767 | (aheadsym Man-refpages-alist))) |
| @@ -784,9 +789,10 @@ Prefix argument ARG is passed to `Man-getpage-in-background'." | |||
| 784 | (defun Man-goto-page (page) | 789 | (defun Man-goto-page (page) |
| 785 | "Go to the manual page on page PAGE." | 790 | "Go to the manual page on page PAGE." |
| 786 | (interactive | 791 | (interactive |
| 787 | (if (not Man-page-list) | 792 | (if (= (length Man-page-list) 1) |
| 788 | (error "You're looking at the only manpage in the buffer.") | 793 | (error "You're looking at the only manpage in the buffer.") |
| 789 | (format "nGo to manpage [1-%d]: " (length Man-page-list)))) | 794 | (list (read-minibuffer (format "Go to manpage [1-%d]: " |
| 795 | (length Man-page-list)))))) | ||
| 790 | (if (or (< page 1) | 796 | (if (or (< page 1) |
| 791 | (> page (length Man-page-list))) | 797 | (> page (length Man-page-list))) |
| 792 | (error "No manpage %d found" page)) | 798 | (error "No manpage %d found" page)) |