Mercurial > emacs
comparison lisp/man.el @ 91304:c938ab6810a4
Merge from emacs--devo--0
Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-308
author | Miles Bader <miles@gnu.org> |
---|---|
date | Wed, 02 Jan 2008 04:13:39 +0000 |
parents | 56a72e2bd635 14d4ce301149 |
children | 606f2d163a64 |
comparison
equal
deleted
inserted
replaced
91303:1ae1f4066439 | 91304:c938ab6810a4 |
---|---|
640 (search-forward "--local-file" nil t)) | 640 (search-forward "--local-file" nil t)) |
641 t))))) | 641 t))))) |
642 | 642 |
643 | 643 |
644 ;; ====================================================================== | 644 ;; ====================================================================== |
645 ;; default man entry: get word under point | 645 ;; default man entry: get word near point |
646 | 646 |
647 (defsubst Man-default-man-entry (&optional pos) | 647 (defun Man-default-man-entry (&optional pos) |
648 "Make a guess at a default manual entry based on the text at POS. | 648 "Guess default manual entry based on the text near position POS. |
649 If POS is nil, the current point is used." | 649 POS defaults to `point'." |
650 (let (word start original-pos distance) | 650 (let (word start pos column distance) |
651 (save-excursion | 651 (save-excursion |
652 (if pos (goto-char pos)) | 652 (when pos (goto-char pos)) |
653 ;; Default man entry title is any word the cursor is on, or if | 653 (setq pos (point)) |
654 ;; cursor not on a word, nearest preceding or next word-like | 654 ;; The default title is the nearest entry-like object before or |
655 ;; object on this line. | 655 ;; after POS. |
656 (if (not (zerop (skip-chars-backward "-a-zA-Z0-9._+:"))) | 656 (if (and (skip-chars-backward " \ta-zA-Z0-9+") |
657 (not (zerop (skip-chars-backward "("))) | |
658 ;; Try to handle the special case where POS is on a | |
659 ;; section number. | |
660 (looking-at | |
661 (concat "([ \t]*\\(" Man-section-regexp "\\)[ \t]*)")) | |
662 ;; We skipped a valid section number backwards, look at | |
663 ;; preceding text. | |
664 (or (and (skip-chars-backward ",; \t") | |
665 (not (zerop (skip-chars-backward "-a-zA-Z0-9._+:")))) | |
666 ;; Not a valid entry, move POS after closing paren. | |
667 (not (setq pos (match-end 0))))) | |
668 ;; We have a candidate, make `start' record its starting | |
669 ;; position. | |
657 (setq start (point)) | 670 (setq start (point)) |
658 (setq original-pos (point)) | 671 ;; Otherwise look at char before POS. |
659 (setq distance (abs (skip-chars-backward ",; \t"))) | 672 (goto-char pos) |
660 (if (not (zerop (skip-chars-backward "-a-zA-Z0-9._+:"))) | 673 (if (not (zerop (skip-chars-backward "-a-zA-Z0-9._+:"))) |
661 (progn | 674 ;; Our candidate is just before or around POS. |
662 (setq start (point)) | 675 (setq start (point)) |
663 (goto-char original-pos) | 676 ;; Otherwise record the current column and look backwards. |
664 (if (and (< (skip-chars-forward ",; \t") distance) | 677 (setq column (current-column)) |
665 (looking-at "[-a-zA-Z0-9._+:]")) | 678 (skip-chars-backward ",; \t") |
666 (setq start (point)) | 679 ;; Record the distance travelled. |
667 (goto-char start))) | 680 (setq distance (- column (current-column))) |
668 (skip-chars-forward ",; \t") | 681 (when (looking-back |
669 (setq start (point)))) | 682 (concat "([ \t]*\\(?:" Man-section-regexp "\\)[ \t]*)")) |
683 ;; Skip section number backwards. | |
684 (goto-char (match-beginning 0)) | |
685 (skip-chars-backward " \t")) | |
686 (if (not (zerop (skip-chars-backward "-a-zA-Z0-9._+:"))) | |
687 (progn | |
688 ;; We have a candidate before POS ... | |
689 (setq start (point)) | |
690 (goto-char pos) | |
691 (if (and (skip-chars-forward ",; \t") | |
692 (< (- (current-column) column) distance) | |
693 (looking-at "[-a-zA-Z0-9._+:]")) | |
694 ;; ... but the one after POS is better. | |
695 (setq start (point)) | |
696 ;; ... and anything after POS is worse. | |
697 (goto-char start))) | |
698 ;; No candidate before POS. | |
699 (goto-char pos) | |
700 (skip-chars-forward ",; \t") | |
701 (setq start (point))))) | |
702 ;; We have found a suitable starting point, try to skip at least | |
703 ;; one character. | |
670 (skip-chars-forward "-a-zA-Z0-9._+:") | 704 (skip-chars-forward "-a-zA-Z0-9._+:") |
671 (setq word (buffer-substring-no-properties start (point))) | 705 (setq word (buffer-substring-no-properties start (point))) |
672 ;; If there is a continuation at the end of line, check the | 706 ;; If there is a continuation at the end of line, check the |
673 ;; following line too, eg: | 707 ;; following line too, eg: |
674 ;; see this- | 708 ;; see this- |
675 ;; command-here(1) | 709 ;; command-here(1) |
710 ;; Note: This code gets executed iff our entry is after POS. | |
676 (when (looking-at "[ \t\r\n]+\\([-a-zA-Z0-9._+:]+\\)([0-9])") | 711 (when (looking-at "[ \t\r\n]+\\([-a-zA-Z0-9._+:]+\\)([0-9])") |
677 (setq word (concat word (match-string-no-properties 1)))) | 712 (setq word (concat word (match-string-no-properties 1))) |
713 ;; Make sure the section number gets included by the code below. | |
714 (goto-char (match-end 1))) | |
678 (when (string-match "[._]+$" word) | 715 (when (string-match "[._]+$" word) |
679 (setq word (substring word 0 (match-beginning 0)))) | 716 (setq word (substring word 0 (match-beginning 0)))) |
680 ;; If looking at something like *strcat(... , remove the '*' | 717 ;; The following was commented out since the preceding code |
681 (when (string-match "^*" word) | 718 ;; should not produce a leading "*" in the first place. |
682 (setq word (substring word 1))) | 719 ;;; ;; If looking at something like *strcat(... , remove the '*' |
683 ;; If looking at something like ioctl(2) or brc(1M), include the | 720 ;;; (when (string-match "^*" word) |
684 ;; section number in the returned value. Remove text properties. | 721 ;;; (setq word (substring word 1))) |
685 (concat word | 722 (concat |
686 (if (looking-at | 723 word |
687 (concat "[ \t]*([ \t]*\\(" Man-section-regexp "\\)[ \t]*)")) | 724 (and (not (string-equal word "")) |
688 (format "(%s)" (match-string-no-properties 1))))))) | 725 ;; If looking at something like ioctl(2) or brc(1M), |
726 ;; include the section number in the returned value. | |
727 (looking-at | |
728 (concat "[ \t]*([ \t]*\\(" Man-section-regexp "\\)[ \t]*)")) | |
729 (format "(%s)" (match-string-no-properties 1))))))) | |
689 | 730 |
690 | 731 |
691 ;; ====================================================================== | 732 ;; ====================================================================== |
692 ;; Top level command and background process sentinel | 733 ;; Top level command and background process sentinel |
693 | 734 |