Mercurial > emacs
comparison lisp/man.el @ 41698:722fe545e535
(man-follow-mouse): New function.
(Man-mode-map): Bind mouse-2 to it.
(Man-match-substring): Remove. Replace with `match-string'.
(man): Use the `default-value' argument to `read-string'.
(Man-fontify-manpage): Add mouse-face to cross references.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Fri, 30 Nov 2001 09:13:21 +0000 |
parents | e144797b4ece |
children | 6515e3108ceb |
comparison
equal
deleted
inserted
replaced
41697:48f16a4dc7fe | 41698:722fe545e535 |
---|---|
79 ;; not allow to understand if there was indeed a blank line at the | 79 ;; not allow to understand if there was indeed a blank line at the |
80 ;; end or beginning of a page (after the header, or before the | 80 ;; end or beginning of a page (after the header, or before the |
81 ;; footer). A different algorithm should be used. It is easy to | 81 ;; footer). A different algorithm should be used. It is easy to |
82 ;; compute how many blank lines there are before and after the page | 82 ;; compute how many blank lines there are before and after the page |
83 ;; headers, and after the page footer. But it is possible to compute | 83 ;; headers, and after the page footer. But it is possible to compute |
84 ;; the number of blank lines before the page footer by euristhics | 84 ;; the number of blank lines before the page footer by heuristics |
85 ;; only. Is it worth doing? | 85 ;; only. Is it worth doing? |
86 ;; - Allow a user option to mean that all the manpages should go in | 86 ;; - Allow a user option to mean that all the manpages should go in |
87 ;; the same buffer, where they can be browsed with M-n and M-p. | 87 ;; the same buffer, where they can be browsed with M-n and M-p. |
88 ;; - Allow completion on the manpage name when calling man. This | 88 ;; - Allow completion on the manpage name when calling man. This |
89 ;; requires a reliable list of places where manpages can be found. The | 89 ;; requires a reliable list of places where manpages can be found. The |
349 (define-key Man-mode-map "s" 'Man-goto-see-also-section) | 349 (define-key Man-mode-map "s" 'Man-goto-see-also-section) |
350 (define-key Man-mode-map "k" 'Man-kill) | 350 (define-key Man-mode-map "k" 'Man-kill) |
351 (define-key Man-mode-map "q" 'Man-quit) | 351 (define-key Man-mode-map "q" 'Man-quit) |
352 (define-key Man-mode-map "m" 'man) | 352 (define-key Man-mode-map "m" 'man) |
353 (define-key Man-mode-map "\r" 'man-follow) | 353 (define-key Man-mode-map "\r" 'man-follow) |
354 (define-key Man-mode-map [mouse-2] 'man-follow-mouse) | |
354 (define-key Man-mode-map "?" 'describe-mode) | 355 (define-key Man-mode-map "?" 'describe-mode) |
355 ) | 356 ) |
356 | 357 |
357 | 358 |
358 ;; ====================================================================== | 359 ;; ====================================================================== |
416 Man-untabify-command | 417 Man-untabify-command |
417 Man-untabify-command-args)) | 418 Man-untabify-command-args)) |
418 ))) | 419 ))) |
419 ) | 420 ) |
420 | 421 |
421 (defsubst Man-match-substring (&optional n string) | |
422 "Return the substring matched by the last search. | |
423 Optional arg N means return the substring matched by the Nth paren | |
424 grouping. Optional second arg STRING means return a substring from | |
425 that string instead of from the current buffer." | |
426 (if (null n) (setq n 0)) | |
427 (if string | |
428 (substring string (match-beginning n) (match-end n)) | |
429 (buffer-substring (match-beginning n) (match-end n)))) | |
430 | |
431 (defsubst Man-make-page-mode-string () | 422 (defsubst Man-make-page-mode-string () |
432 "Formats part of the mode line for Man mode." | 423 "Formats part of the mode line for Man mode." |
433 (format "%s page %d of %d" | 424 (format "%s page %d of %d" |
434 (or (nth 2 (nth (1- Man-current-page) Man-page-list)) | 425 (or (nth 2 (nth (1- Man-current-page) Man-page-list)) |
435 "") | 426 "") |
469 (section "") | 460 (section "") |
470 (slist Man-section-translations-alist)) | 461 (slist Man-section-translations-alist)) |
471 (cond | 462 (cond |
472 ;; "chmod(2V)" case ? | 463 ;; "chmod(2V)" case ? |
473 ((string-match (concat "^" Man-reference-regexp "$") ref) | 464 ((string-match (concat "^" Man-reference-regexp "$") ref) |
474 (setq name (Man-match-substring 1 ref) | 465 (setq name (match-string 1 ref) |
475 section (Man-match-substring 2 ref))) | 466 section (match-string 2 ref))) |
476 ;; "2v chmod" case ? | 467 ;; "2v chmod" case ? |
477 ((string-match (concat "^\\(" Man-section-regexp | 468 ((string-match (concat "^\\(" Man-section-regexp |
478 "\\) +\\(" Man-name-regexp "\\)$") ref) | 469 "\\) +\\(" Man-name-regexp "\\)$") ref) |
479 (setq name (Man-match-substring 2 ref) | 470 (setq name (match-string 2 ref) |
480 section (Man-match-substring 1 ref)))) | 471 section (match-string 1 ref)))) |
481 (if (string= name "") | 472 (if (string= name "") |
482 ref ; Return the reference as is | 473 ref ; Return the reference as is |
483 (if Man-downcase-section-letters-flag | 474 (if Man-downcase-section-letters-flag |
484 (setq section (downcase section))) | 475 (setq section (downcase section))) |
485 (while slist | 476 (while slist |
515 ;; Use `format' here to clear any text props from `word'. | 506 ;; Use `format' here to clear any text props from `word'. |
516 (format "%s%s" | 507 (format "%s%s" |
517 word | 508 word |
518 (if (looking-at | 509 (if (looking-at |
519 (concat "[ \t]*([ \t]*\\(" Man-section-regexp "\\)[ \t]*)")) | 510 (concat "[ \t]*([ \t]*\\(" Man-section-regexp "\\)[ \t]*)")) |
520 (format "(%s)" (Man-match-substring 1)) | 511 (format "(%s)" (match-string 1)) |
521 ""))))) | 512 ""))))) |
522 | 513 |
523 | 514 |
524 ;; ====================================================================== | 515 ;; ====================================================================== |
525 ;; Top level command and background process sentinel | 516 ;; Top level command and background process sentinel |
545 (list (let* ((default-entry (Man-default-man-entry)) | 536 (list (let* ((default-entry (Man-default-man-entry)) |
546 (input (read-string | 537 (input (read-string |
547 (format "Manual entry%s: " | 538 (format "Manual entry%s: " |
548 (if (string= default-entry "") | 539 (if (string= default-entry "") |
549 "" | 540 "" |
550 (format " (default %s)" default-entry)))))) | 541 (format " (default %s)" default-entry))) |
542 nil nil default-entry))) | |
551 (if (string= input "") | 543 (if (string= input "") |
552 (if (string= default-entry "") | 544 (error "No man args given") |
553 (error "No man args given") | |
554 default-entry) | |
555 input)))) | 545 input)))) |
556 | 546 |
557 ;; Possibly translate the "subject(section)" syntax into the | 547 ;; Possibly translate the "subject(section)" syntax into the |
558 ;; "section subject" syntax and possibly downcase the section. | 548 ;; "section subject" syntax and possibly downcase the section. |
559 (setq man-args (Man-translate-references man-args)) | 549 (setq man-args (Man-translate-references man-args)) |
566 (interactive (list (Man-default-man-entry))) | 556 (interactive (list (Man-default-man-entry))) |
567 (if (or (not man-args) | 557 (if (or (not man-args) |
568 (string= man-args "")) | 558 (string= man-args "")) |
569 (error "No item under point") | 559 (error "No item under point") |
570 (man man-args))) | 560 (man man-args))) |
561 | |
562 (defun man-follow-mouse (e) | |
563 "Get a Un*x manual page of the item under the mouse and put it in a buffer." | |
564 (interactive "e") | |
565 (save-excursion | |
566 (mouse-set-point e) | |
567 (call-interactively 'man-follow))) | |
571 | 568 |
572 (defun Man-getpage-in-background (topic) | 569 (defun Man-getpage-in-background (topic) |
573 "Use TOPIC to build and fire off the manpage and cleaning command." | 570 "Use TOPIC to build and fire off the manpage and cleaning command." |
574 (let* ((man-args topic) | 571 (let* ((man-args topic) |
575 (bufname (concat "*Man " man-args "*")) | 572 (bufname (concat "*Man " man-args "*")) |
711 (put-text-property (1- (point)) (point) 'face 'bold)) | 708 (put-text-property (1- (point)) (point) 'face 'bold)) |
712 (goto-char (point-min)) | 709 (goto-char (point-min)) |
713 (while (re-search-forward "[-|]\\(\b[-|]\\)+" nil t) | 710 (while (re-search-forward "[-|]\\(\b[-|]\\)+" nil t) |
714 (replace-match "+") | 711 (replace-match "+") |
715 (put-text-property (1- (point)) (point) 'face 'bold)) | 712 (put-text-property (1- (point)) (point) 'face 'bold)) |
713 (goto-char (point-min)) | |
714 ;; Try to recognize common forms of cross references. | |
715 (while (re-search-forward "\\w+([0-9].?)" nil t) | |
716 (put-text-property (match-beginning 0) (match-end 0) | |
717 'mouse-face 'highlight)) | |
716 (Man-softhyphen-to-minus) | 718 (Man-softhyphen-to-minus) |
717 (message "%s man page made up" Man-arguments)) | 719 (message "%s man page made up" Man-arguments)) |
718 | 720 |
719 (defun Man-cleanup-manpage () | 721 (defun Man-cleanup-manpage () |
720 "Remove overstriking and underlining from the current buffer." | 722 "Remove overstriking and underlining from the current buffer." |
884 (goto-char (point-min)) | 886 (goto-char (point-min)) |
885 (back-to-indentation) | 887 (back-to-indentation) |
886 (while (and (not (eobp)) (/= (point) runningpoint)) | 888 (while (and (not (eobp)) (/= (point) runningpoint)) |
887 (setq runningpoint (point)) | 889 (setq runningpoint (point)) |
888 (if (re-search-forward Man-hyphenated-reference-regexp end t) | 890 (if (re-search-forward Man-hyphenated-reference-regexp end t) |
889 (let* ((word (Man-match-substring 0)) | 891 (let* ((word (match-string 0)) |
890 (len (1- (length word)))) | 892 (len (1- (length word)))) |
891 (if hyphenated | 893 (if hyphenated |
892 (setq word (concat hyphenated word) | 894 (setq word (concat hyphenated word) |
893 hyphenated nil | 895 hyphenated nil |
894 ;; Update len, in case a reference spans | 896 ;; Update len, in case a reference spans |
910 (goto-char page-start) | 912 (goto-char page-start) |
911 ;; (switch-to-buffer (current-buffer))(debug) | 913 ;; (switch-to-buffer (current-buffer))(debug) |
912 (while (not (eobp)) | 914 (while (not (eobp)) |
913 (setq header | 915 (setq header |
914 (if (looking-at Man-page-header-regexp) | 916 (if (looking-at Man-page-header-regexp) |
915 (Man-match-substring 1) | 917 (match-string 1) |
916 nil)) | 918 nil)) |
917 ;; Go past both the current and the next Man-first-heading-regexp | 919 ;; Go past both the current and the next Man-first-heading-regexp |
918 (if (re-search-forward Man-first-heading-regexp nil 'move 2) | 920 (if (re-search-forward Man-first-heading-regexp nil 'move 2) |
919 (let ((p (progn (beginning-of-line) (point)))) | 921 (let ((p (progn (beginning-of-line) (point)))) |
920 ;; We assume that the page header is delimited by blank | 922 ;; We assume that the page header is delimited by blank |