annotate lisp/packages/man-xref.el @ 4:b82b59fe008d r19-15b3

Import from CVS: tag r19-15b3
author cvs
date Mon, 13 Aug 2007 08:46:56 +0200
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1 ;;; man-xref.el --- cross reference selection functions for man mode
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
2
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
3 ;; Author: Mark Hood <hood@eng.sun.com>
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
4 ;; @(#)man-xref.el 1.15
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
5
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
6 ;; This file is part of XEmacs.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
7
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
8 ;; XEmacs is free software; you can redistribute it and/or modify it
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
9 ;; under the terms of the GNU General Public License as published by
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
10 ;; the Free Software Foundation; either version 2, or (at your option)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
11 ;; any later version.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
12
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
13 ;; XEmacs is distributed in the hope that it will be useful, but
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
14 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
16 ;; General Public License for more details.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
17
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
18 ;; You should have received a copy of the GNU General Public License
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
19 ;; along with XEmacs; see the file COPYING. If not, write to the Free
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
20 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
21 ;; 02111-1307, USA.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
22
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
23 ;;; Synched up with: FSF 19.35.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
24
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
25 ;;; Commentary:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
26
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
27 ;; This package is an add-on to the man.el that comes with Emacs
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
28 ;; 19.34. It renders manpage cross references in bold, sets them up
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
29 ;; for mouse highlighting, and allows selection via keystrokes or
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
30 ;; mouse. All strings matching Man-reference-regexp in the text of
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
31 ;; the man page are set up, in addition to the ones in the See Also
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
32 ;; section.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
33
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
34 ;; To use this package, put something like the following in your Emacs
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
35 ;; initialization file. This example causes tab and M-tab to go to
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
36 ;; the next and previous manual cross references, causes carriage
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
37 ;; return to display a man page for the reference under point, and
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
38 ;; allows mouse button 2 to invoke a man page display.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
39
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
40 ;; (add-hook 'Man-mode-hook
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
41 ;; '(lambda ()
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
42 ;; (Man-mouseify-xrefs)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
43 ;; (define-key Man-mode-map "\r" 'Man-do-manual-reference)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
44 ;; (define-key Man-mode-map "\t" 'Man-next-manual-reference)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
45 ;; (define-key Man-mode-map "\e\t" 'Man-prev-manual-reference)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
46 ;; (define-key Man-mode-map [mouse-2] 'Man-mouse-manual-reference)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
47 ;; ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
48 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
49 ;; (autoload 'Man-mouseify-xrefs "~/emacs/man-xref")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
50
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
51 (eval-when-compile (require 'cl))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
52
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
53 (defvar Man-word-syntax "w_()" "Syntax for words in a man buffer.")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
54
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
55 (defun Man-current-word ()
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
56 "Return word under point, using `Man-word-syntax' for word syntax."
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
57 (save-excursion
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
58 (let ((s (+ (point) (skip-syntax-backward Man-word-syntax))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
59 (skip-syntax-forward Man-word-syntax)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
60 (buffer-substring s (point)))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
61
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
62 (defun Man-prev-word-hyphen-p ()
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
63 "Return nil if previous word is not hyphenated.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
64 Non-nil value is the buffer position of the beginning of the hyphenated word."
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
65 (save-excursion
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
66 (skip-syntax-backward Man-word-syntax)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
67 (skip-chars-backward " \t")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
68 (cond ((and (> (point) (1+ (point-min)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
69 (string-equal "-\n" (buffer-substring (- (point) 2) (point))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
70 (backward-char)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
71 (skip-syntax-backward Man-word-syntax)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
72 (point)))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
73
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
74 (defun Man-next-manual-reference ()
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
75 "Move point to the beginning of the next manual reference."
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
76 (interactive)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
77 (let ((current (point))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
78 (end (re-search-forward (concat "[ \t]" Man-reference-regexp) nil t))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
79 (start (or (Man-prev-word-hyphen-p) (1+ (match-beginning 0)))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
80 (cond ((eq end nil))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
81 ((> start current)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
82 (goto-char start))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
83 ;; current is in the pre-hyphen portion of a hyphenated reference
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
84 ((re-search-forward Man-reference-regexp nil t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
85 (goto-char (or (Man-prev-word-hyphen-p) (match-beginning 0))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
86 ((goto-char current)))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
87
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
88 (defun Man-prev-manual-reference ()
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
89 "Move point to the beginning of the previous manual reference."
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
90 (interactive)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
91 (if (re-search-backward (concat "[ \t]" Man-reference-regexp) nil t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
92 (goto-char (or (Man-prev-word-hyphen-p) (1+ (match-beginning 0))))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
93
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
94 (defun Man-mouseify-xrefs ()
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
95 "Render man cross references in bold font and set up mouse highlighting.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
96 Add these cross references to `Man-refpages-alist'."
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
97 (let (start end xref hyphen alist)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
98 (goto-char (point-min))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
99 (forward-line 1)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
100 (while (re-search-forward Man-reference-regexp nil t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
101 (setq start (match-beginning 0))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
102 (setq end (match-end 0))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
103 (setq xref (buffer-substring start end))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
104 (cond ((setq hyphen (Man-prev-word-hyphen-p))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
105 (setq start hyphen)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
106 (goto-char hyphen)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
107 (setq xref (concat (substring (Man-current-word) 0 -1) xref))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
108 (goto-char end)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
109 (setq Man-refpages-alist (cons (list xref) Man-refpages-alist))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
110 (Man-boldify-mouse-region start end))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
111 (setq Man-refpages-alist
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
112 (sort Man-refpages-alist
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
113 (function (lambda (a b) (string< (car a) (car b))))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
114 ;; delete duplicate entries in the alist
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
115 (setq alist Man-refpages-alist)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
116 (while alist
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
117 (cond ((string= (car (car alist)) (car (car (cdr alist))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
118 (setcdr alist (cdr (cdr alist))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
119 ((setq alist (cdr alist)))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
120 (goto-char (point-min))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
121 (forward-line 1)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
122
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
123 (defun Man-mouse-manual-reference (mouse)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
124 "Move point to mouse position and run `Man-getpage-in-background' there."
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
125 (interactive "e")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
126 (select-window (car (car (cdr mouse))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
127 (goto-char (car (cdr (car (cdr mouse)))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
128 (Man-do-manual-reference))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
129
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
130 (defun Man-do-manual-reference ()
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
131 "Run `Man-getpage-in-background' on cross reference under point.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
132 Word under point is checked for a match with `Man-reference-regexp'.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
133 If point is not over a word, try to use previous word for a match."
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
134 (interactive)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
135 (save-excursion
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
136 (let ((xref (Man-current-word)) (hyphen (Man-prev-word-hyphen-p)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
137 (if (and (zerop (length xref))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
138 (setq xref " ")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
139 (skip-syntax-backward " ")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
140 (not (eq (point) (point-min))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
141 (Man-do-manual-reference)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
142 (cond ((string-equal "-" (substring xref -1))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
143 (skip-syntax-forward Man-word-syntax)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
144 (skip-syntax-forward " ")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
145 (setq xref (concat (substring xref 0 -1) (Man-current-word))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
146 (hyphen
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
147 (goto-char hyphen)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
148 (setq xref (concat (substring (Man-current-word) 0 -1) xref))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
149 (if (string-match Man-reference-regexp xref)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
150 (Man-getpage-in-background
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
151 (Man-translate-references
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
152 (substring xref (match-beginning 0) (match-end 0))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
153 (message "No cross reference found under point."))))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
154
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
155 (eval-and-compile
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
156 (when (string-match "XEmacs\\|Lucid" emacs-version)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
157 (fset 'make-overlay 'make-extent)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
158 (fset 'overlay-put 'set-extent-property)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
159
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
160 (defun Man-boldify-mouse-region (beg end)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
161 "Render region text in bold with mouse highlighting."
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
162 (let ((overlay (make-overlay beg end)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
163 (overlay-put overlay 'face 'bold)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
164 (overlay-put overlay 'mouse-face 'highlight)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
165 (overlay-put overlay 'hilit t)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
166