0
|
1 ;;!emacs
|
|
2 ;;
|
|
3 ;; FILE: hmouse-tag.el
|
|
4 ;; SUMMARY: Smart Key support of programming language tags location.
|
|
5 ;; USAGE: GNU Emacs Lisp Library
|
|
6 ;; KEYWORDS: c, hypermedia, mouse, oop, tools
|
|
7 ;;
|
|
8 ;; AUTHOR: Bob Weiner
|
100
|
9 ;; ORG: InfoDock Associates
|
0
|
10 ;;
|
|
11 ;; ORIG-DATE: 24-Aug-91
|
100
|
12 ;; LAST-MOD: 17-Feb-97 at 15:31:50 by Bob Weiner
|
0
|
13 ;;; ************************************************************************
|
|
14 ;;; Other required Elisp libraries
|
|
15 ;;; ************************************************************************
|
|
16
|
100
|
17 (require 'hpath)
|
|
18 (require 'hbut)
|
|
19
|
0
|
20 (if (cond ((or (featurep 'etags) (featurep 'tags))
|
|
21 nil)
|
|
22 ((or hyperb:lemacs-p hyperb:emacs19-p)
|
|
23 ;; Force use of .elc file here since otherwise the bin/etags
|
|
24 ;; executable might be found in a user's load-path by the load
|
|
25 ;; command.
|
|
26 (or (load "etags.elc" t nil t)
|
|
27 (load "tags-fix" t)))
|
|
28 ((load "tags" t)))
|
|
29 (provide 'tags))
|
|
30
|
|
31 ;;; ************************************************************************
|
|
32 ;;; Public variables
|
|
33 ;;; ************************************************************************
|
|
34
|
|
35 (defvar smart-asm-include-dirs nil
|
|
36 "*Ordered list of directories to search for assembly language include files.
|
|
37 Each directory must end with a directory separator.")
|
|
38
|
|
39 (defconst smart-asm-include-regexp
|
|
40 "[ \t*#|;]*\\(include\\|lib\\)[ \t]+\\([^ \t\n\^M]+\\)"
|
|
41 "Regexp to match to assembly language include file lines.
|
|
42 Include keyword matched is grouping 1. File name is grouping 2 but may be
|
|
43 missing its suffix, so add \".ins\" or \".inc\" if need be.
|
|
44 Examples include:
|
|
45 INCLUDE GLOBALS
|
|
46 should jump to file \"globals.ins\"
|
|
47 lib conditionals_equ.inc
|
|
48 should include \"conditionals_equ.inc\"")
|
|
49
|
|
50 (defvar smart-c-cpp-include-dirs '("/usr/include/")
|
|
51 "*Ordered list of include directories by default searched by C/C++ preprocessor.
|
|
52 Each directory must end with a directory separator. See also
|
|
53 'smart-c-include-dirs'.")
|
|
54
|
|
55 (defvar smart-c-include-dirs nil
|
|
56 "*Ordered list of directories to search for C/C++ include files.
|
|
57 Each directory must end with a directory separator. Directories normally
|
|
58 searched by the C/C++ pre-processor should be set instead in
|
100
|
59 `smart-c-cpp-include-dirs'.")
|
0
|
60
|
|
61 (defvar smart-c-use-lib-man nil
|
100
|
62 "When non-nil makes `smart-c' and `smart-c++' display man pages for recognized lib symbols.
|
|
63 When nil, `smart-c' and `smart-c++' look up only symbols defined in an etags
|
0
|
64 TAGS file.
|
|
65
|
|
66 Create the file ~/.CLIBS-LIST and populate it with the full pathnames (one per
|
|
67 line) of all of the C/C++ libraries whose symbols you want to match against.
|
|
68 Your MANPATH environment variable must include paths for the man pages of
|
|
69 these libraries also.
|
|
70
|
|
71 Your smart-clib-sym executable script must output a 1 if a symbol is from a
|
|
72 C/C++ library listed in ~/.CLIBS-LIST or 0 if not! Otherwise, don't set this
|
|
73 variable to t.")
|
|
74
|
|
75 (defconst smart-c-include-regexp
|
|
76 "[ \t/*]*#[ \t]*\\(include\\|import\\)[ \t]+\\([\"<]\\)\\([^\">]+\\)[\">]"
|
|
77 "Regexp to match to C, C++, or Objective-C include file lines.
|
|
78 Include keyword matched is grouping 1. Type of include, user-specified via
|
100
|
79 double quote, or system-related starting with `<' is given by grouping 2.
|
0
|
80 File name is grouping 3.")
|
|
81
|
100
|
82 (defvar smart-java-package-dirs
|
|
83 (and (fboundp 'getenv) (getenv "JAVA_HOME")
|
|
84 (list (expand-file-name "src/" (file-name-as-directory (getenv "JAVA_HOME")))))
|
|
85 "*Ordered list of directories to search for imported Java packages.
|
|
86 Each directory must end with a directory separator.")
|
|
87
|
|
88 (defconst smart-java-package-regexp
|
|
89 "[ \t/*]*\\(package\\|import\\)[ \t]+\\([^; \t\n\r\f]+\\)"
|
|
90 "Regexp to match to Java `package' and `import' lines.
|
|
91 Keyword matched is grouping 1. Referent is grouping 2.")
|
|
92
|
0
|
93 (defvar smart-emacs-tags-file nil
|
|
94 "*Full path name of etags file for GNU Emacs source.")
|
|
95
|
|
96 ;;; ************************************************************************
|
|
97 ;;; Public functions
|
|
98 ;;; ************************************************************************
|
|
99
|
|
100 (defun smart-asm (&optional identifier next)
|
|
101 "Jumps to the definition of optional assembly IDENTIFIER or the one at point.
|
|
102 Optional second arg NEXT means jump to next matching assembly tag.
|
|
103
|
|
104 It assumes that its caller has already checked that the key was pressed in an
|
|
105 appropriate buffer and has moved the cursor to the selected buffer.
|
|
106
|
|
107 If:
|
|
108 (1) on an include statement, the include file is displayed;
|
100
|
109 Look for include file in directory list `smart-asm-include-dirs'.
|
0
|
110 (2) on an identifier, the identifier definition is displayed,
|
100
|
111 assuming the identifier is found within an `etags' generated tag file
|
0
|
112 in the current directory or any of its ancestor directories."
|
|
113
|
|
114 (interactive)
|
|
115 (or
|
|
116 (if identifier nil (smart-asm-include-file))
|
|
117 (let ((tag (or identifier (smart-asm-at-tag-p))))
|
100
|
118 ;; Set free variable tags-file-name so that next `find-tag' command uses
|
0
|
119 ;; whatever tags file is set here.
|
|
120 (setq tags-file-name (smart-tags-file buffer-file-name))
|
100
|
121 (message "Looking for `%s' in `%s'..." tag tags-file-name)
|
0
|
122 (condition-case ()
|
|
123 (progn
|
100
|
124 (smart-tags-display tag next)
|
|
125 (message "Found definition for `%s'." tag))
|
|
126 (error (message "`%s' not found in `%s'." tag tags-file-name)
|
0
|
127 (beep))))))
|
|
128
|
|
129 ;;;###autoload
|
|
130 (defun smart-asm-at-tag-p ()
|
|
131 "Return assembly tag name that point is within, else nil."
|
|
132 (let* ((identifier-chars "_.$a-zA-Z0-9")
|
|
133 (identifier (concat "[_.$a-zA-Z][" identifier-chars "]*")))
|
|
134 (save-excursion
|
|
135 (skip-chars-backward identifier-chars)
|
|
136 (if (looking-at identifier)
|
100
|
137 (smart-flash-tag
|
|
138 (buffer-substring (point) (match-end 0))
|
|
139 (point) (match-end 0))))))
|
|
140
|
|
141 (defun smart-c (&optional identifier next)
|
|
142 "Jumps to the definition of optional C IDENTIFIER or the one at point.
|
|
143 Optional second arg NEXT means jump to next matching C tag.
|
|
144
|
|
145 It assumes that its caller has already checked that the key was pressed in an
|
|
146 appropriate buffer and has moved the cursor to the selected buffer.
|
|
147
|
|
148 If:
|
|
149 (1) on a `#include' statement, the include file is displayed;
|
|
150 Look for include file in directory lists `smart-c-cpp-include-dirs'
|
|
151 and `smart-c-include-dirs'.
|
|
152 (2) on a C identifier, the identifier definition is displayed,
|
|
153 assuming the identifier is found within an `etags' generated tag file
|
|
154 in the current directory or any of its ancestor directories.
|
|
155 (3) if `smart-c-use-lib-man' is non-nil, the C identifier is
|
|
156 recognized as a library symbol, and a man page is found for the
|
|
157 identifier, then the man page is displayed."
|
|
158
|
|
159 (interactive)
|
|
160 (or
|
|
161 (if identifier nil (smart-c-include-file))
|
|
162 (let ((tag (or identifier (smart-c-at-tag-p))))
|
|
163 ;; Set free variable tags-file-name so that next `find-tag' command uses
|
|
164 ;; whatever tags file is set here.
|
|
165 (setq tags-file-name (smart-tags-file buffer-file-name))
|
|
166 (message "Looking for `%s' in `%s'..." tag tags-file-name)
|
|
167 (condition-case ()
|
|
168 (progn
|
|
169 (smart-tags-display tag next)
|
|
170 (message "Found definition for `%s'." tag))
|
|
171 (error
|
|
172 (if (not smart-c-use-lib-man)
|
|
173 (progn (message "`%s' not found in `%s'." tag tags-file-name)
|
|
174 (beep))
|
|
175 (message "Checking if `%s' is a C library function..." tag)
|
|
176 (if (smart-library-symbol tag)
|
|
177 (progn (message "Displaying C library man page for `%s'." tag)
|
|
178 (manual-entry tag))
|
|
179 (message "`%s' not found in `%s' or C libraries."
|
|
180 tag tags-file-name)
|
|
181 (beep))))))))
|
|
182
|
|
183 ;;;###autoload
|
|
184 (defun smart-c-at-tag-p ()
|
|
185 "Return C tag name that point is within, else nil."
|
|
186 (let* ((identifier-chars "_a-zA-Z0-9")
|
|
187 (identifier (concat "[_a-zA-Z][" identifier-chars "]*")))
|
|
188 (save-excursion
|
|
189 (skip-chars-backward identifier-chars)
|
|
190 (if (looking-at identifier)
|
|
191 (smart-flash-tag
|
|
192 (buffer-substring (point) (match-end 0))
|
|
193 (point) (match-end 0))))))
|
|
194
|
|
195 ;;;###autoload
|
|
196 (defun smart-c++ (&optional identifier next)
|
|
197 "Jumps to the definition of optional C++ IDENTIFIER or the one at point.
|
|
198 Optional second arg NEXT means jump to next matching C++ tag.
|
|
199
|
|
200 It assumes that its caller has already checked that the key was pressed in an
|
|
201 appropriate buffer and has moved the cursor to the selected buffer.
|
|
202
|
|
203 If:
|
|
204 (1) on a `#include' statement, the include file is displayed;
|
|
205 Look for include file in directory lists `smart-c-cpp-include-dirs'
|
|
206 and `smart-c-include-dirs'.
|
|
207 (2) on a C++ identifier, the identifier definition is displayed,
|
|
208 assuming the identifier is found within an `etags' generated tag file
|
|
209 in the current directory or any of its ancestor directories.
|
|
210 (3) if `smart-c-use-lib-man' is non-nil, the C++ identifier is
|
|
211 recognized as a library symbol, and a man page is found for the
|
|
212 identifier, then the man page is displayed."
|
|
213
|
|
214 (interactive)
|
|
215 (if (fboundp 'c++-to-definition)
|
|
216 ;; Only fboundp if OO-Browser has been loaded.
|
|
217 (smart-c++-oo-browser)
|
|
218 (or
|
|
219 (if identifier nil (smart-c-include-file))
|
|
220 (let ((tag (or identifier (smart-c++-at-tag-p))))
|
|
221 ;; Set free variable tags-file-name so that next `find-tag' command uses
|
|
222 ;; whatever tags file is set here.
|
|
223 (setq tags-file-name (smart-tags-file buffer-file-name))
|
|
224 (message "Looking for `%s' in `%s'..." tag tags-file-name)
|
|
225 (condition-case ()
|
|
226 (progn
|
|
227 (smart-tags-display tag next)
|
|
228 (message "Found definition for `%s'." tag))
|
|
229 (error
|
|
230 (if (not smart-c-use-lib-man)
|
|
231 (progn (message "`%s' not found in `%s'." tag tags-file-name)
|
|
232 (beep))
|
|
233 (message "Checking if `%s' is a C++ library function..." tag)
|
|
234 (if (smart-library-symbol tag)
|
|
235 (progn (message "Displaying C++ library man page for `%s'." tag)
|
|
236 (manual-entry tag))
|
|
237 (message "`%s' not found in `%s' or C++ libraries."
|
|
238 tag tags-file-name)
|
|
239 (beep)))))))))
|
|
240
|
|
241 ;;; The following should be called only if the OO-Browser is available.
|
|
242 (defun smart-c++-oo-browser (&optional junk)
|
|
243 "Jumps to the definition of selected C++ construct via OO-Browser support.
|
|
244 Optional JUNK is ignored. Does nothing if the OO-Browser is not available.
|
|
245
|
|
246 It assumes that its caller has already checked that the key was pressed in an
|
|
247 appropriate buffer and has moved the cursor to the selected buffer.
|
|
248
|
|
249 If key is pressed:
|
|
250 (1) on a `#include' statement, the include file is displayed;
|
|
251 Look for include file in directory lists `smart-c-cpp-include-dirs'
|
|
252 and `smart-c-include-dirs'.
|
|
253 (2) within a method declaration, its definition is displayed;
|
|
254 (3) on a class name, the class definition is shown.
|
|
255
|
|
256 (2) and (3) require that an OO-Browser Environment has been loaded with
|
|
257 the {M-x br-env-load RET} command."
|
|
258
|
|
259 (interactive)
|
|
260 (c++-to-definition t))
|
|
261
|
|
262 (defun smart-c++-at-tag-p ()
|
|
263 "Return C++ tag name that point is within, else nil."
|
|
264 (let* ((identifier-chars "_:~<>a-zA-Z0-9")
|
|
265 (identifier (concat "\\([_~:<a-zA-Z][" identifier-chars "]*"
|
|
266 "[ \t]*[^]) \t:;.,?~{}][^[( \t:;.,~^!|?{}]?[=*]?\\)[ \t\n]*(")))
|
|
267 (save-excursion
|
|
268 (skip-chars-backward identifier-chars)
|
|
269 (if (looking-at identifier)
|
|
270 (smart-flash-tag
|
|
271 (buffer-substring (match-beginning 1) (match-end 1))
|
|
272 (match-beginning 1) (match-end 1))))))
|
|
273
|
|
274 (defun smart-emacs-lisp-mode-p ()
|
|
275 "Return t if in a mode which uses Emacs Lisp symbols."
|
|
276 (or (memq major-mode '(emacs-lisp-mode lisp-interaction-mode debugger-mode))
|
|
277 ;; Emacs Lisp symbols appear in Help buffers frequently.
|
|
278 (string-match "Help\\*$" (buffer-name))))
|
|
279
|
|
280 (defun smart-fortran (&optional identifier next)
|
|
281 "Jumps to the definition of optional Fortran IDENTIFIER or the one at point.
|
|
282 Optional second arg NEXT means jump to next matching Fortran tag.
|
|
283
|
|
284 It assumes that its caller has already checked that the key was pressed in an
|
|
285 appropriate buffer and has moved the cursor to the selected buffer.
|
|
286
|
|
287 If on a Fortran identifier, the identifier definition is displayed,
|
|
288 assuming the identifier is found within an `etags' generated tag file
|
|
289 in the current directory or any of its ancestor directories."
|
|
290 (interactive)
|
|
291 (let ((tag (or identifier (smart-fortran-at-tag-p))))
|
|
292 ;; Set free variable tags-file-name so that next `find-tag' command uses
|
|
293 ;; whatever tags file is set here.
|
|
294 (setq tags-file-name (smart-tags-file buffer-file-name))
|
|
295 (message "Looking for `%s' in `%s'..." tag tags-file-name)
|
|
296 (condition-case ()
|
|
297 (progn
|
|
298 (smart-tags-display tag next)
|
|
299 (message "Found definition for `%s'." tag))
|
|
300 (error
|
|
301 (message "`%s' not found in `%s'." tag tags-file-name)
|
|
302 (beep)))))
|
|
303
|
|
304 ;;;###autoload
|
|
305 (defun smart-fortran-at-tag-p ()
|
|
306 "Return Fortran tag name that point is within, else nil."
|
|
307 (let* ((identifier-chars "_a-zA-Z0-9")
|
|
308 (identifier (concat "[_a-zA-Z][" identifier-chars "]*")))
|
|
309 (save-excursion
|
|
310 (skip-chars-backward identifier-chars)
|
|
311 (if (looking-at identifier)
|
|
312 (smart-flash-tag
|
|
313 (buffer-substring (point) (match-end 0))
|
|
314 (point) (match-end 0))))))
|
|
315
|
|
316 ;;;###autoload
|
|
317 (defun smart-java (&optional identifier next)
|
|
318 "Jumps to the definition of optional Java IDENTIFIER or the one at point.
|
|
319 Optional second arg NEXT means jump to next matching Java tag.
|
|
320
|
|
321 It assumes that its caller has already checked that the key was pressed in an
|
|
322 appropriate buffer and has moved the cursor to the selected buffer.
|
|
323
|
|
324 If:
|
|
325 (1) within a commented @see cross-reference, the referent is displayed;
|
|
326 (2) on a `package' or `import' statement, the referent is displayed;
|
|
327 Look for referent files in the directory list `smart-java-package-dirs'.
|
|
328 (3) on an Java identifier, the identifier definition is displayed,
|
|
329 assuming the identifier is found within an `etags' generated tag file
|
|
330 in the current directory or any of its ancestor directories."
|
|
331
|
|
332 (interactive)
|
|
333 (if (fboundp 'java-to-definition)
|
|
334 ;; Only fboundp if OO-Browser has been loaded.
|
|
335 (smart-java-oo-browser)
|
|
336 (or
|
|
337 (if identifier nil (or (smart-java-cross-reference) (smart-java-packages)))
|
|
338 (let ((tag (or identifier (smart-java-at-tag-p))))
|
|
339 ;; Set free variable tags-file-name so that next `find-tag' command uses
|
|
340 ;; whatever tags file is set here.
|
|
341 (setq tags-file-name (smart-tags-file buffer-file-name))
|
|
342 (message "Looking for `%s' in `%s'..." tag tags-file-name)
|
|
343 (condition-case ()
|
|
344 (progn
|
|
345 (smart-tags-display tag next)
|
|
346 (message "Found definition for `%s'." tag))
|
|
347 (error (progn (message "`%s' not found in `%s'." tag tags-file-name)
|
|
348 (beep))))))))
|
|
349
|
|
350 ;;; The following should be called only if the OO-Browser is available.
|
|
351 (defun smart-java-oo-browser (&optional junk)
|
|
352 "Jumps to the definition of selected Java construct via OO-Browser support.
|
|
353 Optional JUNK is ignored. Does nothing if the OO-Browser is not available.
|
|
354
|
|
355 It assumes that its caller has already checked that the key was pressed in an
|
|
356 appropriate buffer and has moved the cursor to the selected buffer.
|
|
357
|
|
358 If key is pressed:
|
|
359 (1) within a commented @see cross-reference, the referent is displayed;
|
|
360 (2) on a `package' or `import' statement, the referent is displayed;
|
|
361 Look for referent files in the directory list `smart-java-package-dirs'.
|
|
362 (3) within a method declaration, its definition is displayed;
|
|
363 (4) on a class name, the class definition is shown."
|
|
364
|
|
365 (interactive)
|
|
366 (or (smart-java-cross-reference)
|
|
367 (smart-java-packages)
|
|
368 (java-to-definition t)))
|
|
369
|
|
370 ;;;###autoload
|
|
371 (defun smart-java-at-tag-p ()
|
|
372 "Return Java tag name that point is within, else nil."
|
|
373 (let* ((identifier-chars "_$.a-zA-Z0-9")
|
|
374 (identifier
|
|
375 (concat "[_$a-zA-Z][" identifier-chars "]*")))
|
|
376 (save-excursion
|
|
377 (skip-chars-backward identifier-chars)
|
|
378 (if (looking-at identifier)
|
|
379 (smart-flash-tag
|
|
380 (buffer-substring (point) (match-end 0))
|
|
381 (point) (match-end 0))))))
|
|
382
|
|
383 (defun smart-lisp (&optional next)
|
|
384 "Jumps to the definition of any selected Lisp construct.
|
|
385 If on an Emacs Lisp require, load, or autoload clause and `find-library'
|
|
386 from load-library package by Hallvard Furuseth (hallvard@ifi.uio.no) has
|
|
387 been loaded, jumps to library source, if possible.
|
|
388
|
|
389 Otherwise, the construct must be found within an `etags' generated tag file
|
|
390 in the current directory or any of its ancestor directories in order for its
|
|
391 definition to be located.
|
|
392
|
|
393 Optional NEXT means jump to next matching Lisp tag. When matching to an Emacs
|
|
394 Lisp tag using `wtags' (Bob Weiner's personal modifications to `etags'),
|
|
395 there is no next tag, so display documentation for current tag instead.
|
|
396
|
|
397 This command assumes that its caller has already checked that the key was
|
|
398 pressed in an appropriate buffer and has moved the cursor to the selected
|
|
399 buffer."
|
|
400
|
|
401 (interactive)
|
|
402 ;; Handle `require', `load', and `autoload' clauses in Emacs Lisp.
|
|
403 (or (and (fboundp 'find-library)
|
|
404 (smart-emacs-lisp-mode-p)
|
|
405 (let ((req)
|
|
406 (opoint (point)))
|
|
407 (setq req (and (search-backward "\(" nil t)
|
|
408 (looking-at (concat
|
|
409 "(\\(require\\|load\\|autoload\\)"
|
|
410 "[ \t]+.*['\"]"
|
|
411 "\\([^][() \t\n\^M`'\"]+\\)"))))
|
|
412 (goto-char opoint)
|
|
413 (if req (progn
|
|
414 (setq req (buffer-substring (match-beginning 2)
|
|
415 (match-end 2)))
|
|
416 (hpath:display-buffer (current-buffer))
|
|
417 (find-library req)
|
|
418 t))))
|
|
419 (let ((tag (smart-lisp-at-tag-p)))
|
|
420 ;; Set free variable tags-file-name so that next `find-tag' command
|
|
421 ;; uses whatever tags file is set here.
|
|
422 (setq tags-file-name (smart-tags-file default-directory))
|
|
423 ;; This part only works properly for Emacs Lisp, so is conditionalized.
|
|
424 (if (and next (smart-emacs-lisp-mode-p) (featurep 'wtags))
|
|
425 (progn (setq tag (intern tag))
|
|
426 (cond ((fboundp tag) (describe-function tag))
|
|
427 ((boundp tag) (describe-variable tag))
|
|
428 (t (error "(smart-lisp): Unbound symbol: %s" tag))))
|
|
429 (condition-case ()
|
|
430 (smart-tags-display tag next)
|
|
431 (error (if (equal tags-file-name smart-emacs-tags-file)
|
|
432 (progn (message "`%s' not found in `%s'."
|
|
433 tag tags-file-name)
|
|
434 (beep))
|
|
435 (setq tags-file-name smart-emacs-tags-file)
|
|
436 (smart-tags-display tag next))))))))
|
|
437
|
|
438 (defun smart-lisp-at-tag-p ()
|
|
439 "Returns Lisp tag name that point is within, else nil.
|
|
440 Returns nil when point is within a Lisp `def' keyword."
|
|
441 (let* ((identifier-chars "-_*:+%$#!<>a-zA-Z0-9")
|
|
442 (identifier (concat "[-<*a-zA-Z][" identifier-chars "]*"))
|
|
443 (opoint (point)))
|
|
444 (save-excursion
|
|
445 (beginning-of-line)
|
|
446 (if (and (looking-at "\\(;*[ \t]*\\)?(def[^- \n\t]+")
|
|
447 (< opoint (match-end 0)))
|
|
448 nil
|
|
449 (goto-char opoint)
|
|
450 (skip-chars-backward identifier-chars)
|
|
451 (if (looking-at identifier)
|
|
452 (smart-flash-tag
|
|
453 (buffer-substring (point) (match-end 0))
|
|
454 (point) (match-end 0)))))))
|
|
455
|
|
456 ;;;###autoload
|
|
457 (defun smart-lisp-mode-p ()
|
|
458 "Return t if in a mode which uses Lisp symbols."
|
|
459 (or (smart-emacs-lisp-mode-p)
|
|
460 (memq major-mode '(lisp-mode scheme-mode))))
|
|
461
|
|
462 ;;;###autoload
|
|
463 (defun smart-objc (&optional identifier next)
|
|
464 "Jumps to the definition of optional Objective-C IDENTIFIER or the one at point.
|
|
465 Optional second arg NEXT means jump to next matching Objective-C tag.
|
|
466
|
|
467 It assumes that its caller has already checked that the key was pressed in an
|
|
468 appropriate buffer and has moved the cursor to the selected buffer.
|
|
469
|
|
470 If:
|
|
471 (1) on a `#include' statement, the include file is displayed;
|
|
472 Look for include file in directory lists `smart-c-cpp-include-dirs'
|
|
473 and `smart-c-include-dirs'.
|
|
474 (2) on an Objective-C identifier, the identifier definition is displayed,
|
|
475 assuming the identifier is found within an `etags' generated tag file
|
|
476 in the current directory or any of its ancestor directories.
|
|
477 (3) if `smart-c-use-lib-man' is non-nil, the Objective-C identifier is
|
|
478 recognized as a library symbol, and a man page is found for the
|
|
479 identifier, then the man page is displayed."
|
|
480
|
|
481 (interactive)
|
|
482
|
|
483 (if (fboundp 'objc-to-definition)
|
|
484 ;; Only fboundp if OO-Browser has been loaded.
|
|
485 (smart-objc-oo-browser)
|
|
486 (or
|
|
487 (if identifier nil (smart-c-include-file))
|
|
488 (let ((tag (or identifier (smart-objc-at-tag-p))))
|
|
489 ;; Set free variable tags-file-name so that next `find-tag' command uses
|
|
490 ;; whatever tags file is set here.
|
|
491 (setq tags-file-name (smart-tags-file buffer-file-name))
|
|
492 (message "Looking for `%s' in `%s'..." tag tags-file-name)
|
|
493 (condition-case ()
|
|
494 (progn
|
|
495 (smart-tags-display tag next)
|
|
496 (message "Found definition for `%s'." tag))
|
|
497 (error
|
|
498 (if (not smart-c-use-lib-man)
|
|
499 (progn (message "`%s' not found in `%s'." tag tags-file-name)
|
|
500 (beep))
|
|
501 (message
|
|
502 "Checking if `%s' is an Objective-C library function..." tag)
|
|
503 (if (smart-library-symbol tag)
|
|
504 (progn
|
|
505 (message
|
|
506 "Displaying Objective-C library man page for `%s'." tag)
|
|
507 (manual-entry tag))
|
|
508 (message "`%s' not found in `%s' or Objective-C libraries."
|
|
509 tag tags-file-name)
|
|
510 (beep)))))))))
|
|
511
|
|
512 ;;; The following should be called only if the OO-Browser is available.
|
|
513 (defun smart-objc-oo-browser (&optional junk)
|
|
514 "Jumps to the definition of selected Objective-C construct via OO-Browser support.
|
|
515 Optional JUNK is ignored. Does nothing if the OO-Browser is not available.
|
|
516
|
|
517 It assumes that its caller has already checked that the key was pressed in an
|
|
518 appropriate buffer and has moved the cursor to the selected buffer.
|
|
519
|
|
520 If key is pressed:
|
|
521 (1) on a `#include' statement, the include file is displayed;
|
|
522 Look for include file in directory lists `smart-c-cpp-include-dirs'
|
|
523 and `smart-c-include-dirs'.
|
|
524 (2) within a method declaration, its definition is displayed;
|
|
525 (3) on a class name, the class definition is shown.
|
|
526
|
|
527 (2) and (3) require that an OO-Browser Environment has been loaded with
|
|
528 the {M-x br-env-load RET} command."
|
|
529
|
|
530 (interactive)
|
|
531 (objc-to-definition t))
|
|
532
|
|
533 (defun smart-objc-at-tag-p ()
|
|
534 "Return Objective-C tag name that point is within, else nil."
|
|
535 (let* ((identifier-chars "_a-zA-Z0-9")
|
|
536 (identifier
|
|
537 (concat "\\([-+][ \t]*\\)?\\([_a-zA-Z][" identifier-chars "]*\\)")))
|
|
538 (save-excursion
|
|
539 (skip-chars-backward identifier-chars)
|
|
540 (if (looking-at identifier)
|
|
541 (smart-flash-tag
|
|
542 (buffer-substring (match-beginning 2) (match-end 2))
|
|
543 (match-beginning 2) (match-end 2))))))
|
|
544
|
|
545 ;;; ************************************************************************
|
|
546 ;;; Private functions
|
|
547 ;;; ************************************************************************
|
0
|
548
|
|
549 (defun smart-asm-include-file ()
|
|
550 "If point is on an include file line, tries to display file.
|
|
551 Returns non-nil iff on an include file line, even if file is not found.
|
100
|
552 Look for include file in `smart-asm-include-dirs' and add suffix \".ins\" or
|
0
|
553 \".inc\" to filename if it lacks a suffix."
|
|
554 (let ((opoint (point)))
|
|
555 ;; Some assemblers utilize the C preprocessor, so try that first.
|
|
556 (cond ((smart-c-include-file))
|
|
557 ((progn (beginning-of-line)
|
|
558 (looking-at smart-asm-include-regexp))
|
|
559 (let ((file (buffer-substring (match-beginning 2) (match-end 2)))
|
|
560 (path)
|
|
561 (dir-list smart-asm-include-dirs))
|
|
562 (goto-char opoint)
|
|
563 (setq dir-list (cons (file-name-directory buffer-file-name)
|
|
564 dir-list))
|
|
565 (if (string-match "\\." file)
|
|
566 (setq file (regexp-quote file))
|
|
567 (setq file (concat (regexp-quote file) "\\.in[sc]$")))
|
|
568 (while dir-list
|
|
569 (setq dir-list
|
|
570 (if (setq path (car (directory-files
|
100
|
571 (car dir-list) t file)))
|
0
|
572 nil
|
|
573 (cdr dir-list))))
|
|
574 ;;
|
|
575 ;; If path exists, display file
|
|
576 ;;
|
|
577 (if path
|
|
578 (if (and (file-readable-p path)
|
|
579 (progn
|
100
|
580 (hpath:find path)
|
0
|
581 (cond ((featurep 'asm-mode) t)
|
|
582 ((load "asm-mode" nil 'nomessage)
|
|
583 (provide 'asm-mode))
|
|
584 (t
|
100
|
585 (beep)
|
|
586 (message
|
|
587 "(smart-asm-include-file): asm-mode undefined.")
|
|
588 nil
|
|
589 ))))
|
0
|
590 nil
|
|
591 (beep)
|
100
|
592 (message "(smart-asm-include-file): `%s' unreadable." path))
|
0
|
593 (beep)
|
100
|
594 (message "(smart-asm-include-file): `%s' not found." file))
|
0
|
595 path))
|
|
596 ;; not on an include file line
|
|
597 (t (goto-char opoint)
|
|
598 nil))))
|
|
599
|
|
600
|
|
601 (defun smart-c-include-file ()
|
|
602 "If point is on an include file line, tries to display file.
|
|
603 Returns non-nil iff on an include file line, even if file is not found.
|
100
|
604 Look for include file in `smart-c-cpp-include-dirs' and in directory list
|
|
605 `smart-c-include-dirs'."
|
0
|
606 (let ((opoint (point)))
|
|
607 (beginning-of-line)
|
|
608 (if (looking-at smart-c-include-regexp)
|
|
609 (let ((incl-type (string-to-char
|
|
610 (buffer-substring (match-beginning 2)
|
|
611 (1+ (match-beginning 2)))))
|
|
612 (file (buffer-substring (match-beginning 3) (match-end 3)))
|
|
613 (path)
|
|
614 (dir-list smart-c-include-dirs)
|
|
615 (found))
|
|
616 (goto-char opoint)
|
|
617 (setq dir-list (if (= incl-type ?<)
|
|
618 (append dir-list smart-c-cpp-include-dirs)
|
|
619 (cons (file-name-directory buffer-file-name)
|
|
620 dir-list)))
|
|
621 (while dir-list
|
|
622 (setq path (expand-file-name file (car dir-list))
|
|
623 dir-list (if (setq found (file-exists-p path))
|
|
624 nil
|
|
625 (cdr dir-list))))
|
|
626 ;;
|
|
627 ;; If found, display file
|
|
628 ;;
|
|
629 (if found
|
|
630 (if (and (file-readable-p path)
|
|
631 (progn
|
100
|
632 (hpath:find path)
|
0
|
633 (cond ((or (featurep 'cc-mode)
|
|
634 (featurep 'c-mode))
|
|
635 t)
|
|
636 ((or (load "cc-mode" 'missing-ok 'nomessage)
|
|
637 (load "c-mode" 'missing-ok 'nomessage))
|
|
638 (provide 'c-mode))
|
|
639 (t
|
|
640 (beep)
|
|
641 (message
|
|
642 "(smart-c-include-file): c-mode undefined.")
|
|
643 nil
|
|
644 ))))
|
|
645 nil
|
|
646 (beep)
|
100
|
647 (message "(smart-c-include-file): `%s' unreadable." path))
|
0
|
648 (beep)
|
100
|
649 (message "(smart-c-include-file): `%s' not found." file))
|
0
|
650 path)
|
|
651 (goto-char opoint)
|
|
652 nil)))
|
|
653
|
100
|
654 (defun smart-flash-tag (tag start end)
|
|
655 "Tries to flash TAG at START to END in buffer, to indicate that it is serving as a hyperlink button.
|
|
656 Returns TAG."
|
|
657 ;; Button flashing code might not yet have been loaded if the whole
|
|
658 ;; Hyperbole system has not been started.
|
|
659 (if (fboundp 'hui:but-flash)
|
|
660 (progn
|
|
661 (ibut:label-set tag start end)
|
|
662 (hui:but-flash)))
|
|
663 tag)
|
0
|
664
|
100
|
665 (defun smart-java-cross-reference ()
|
|
666 "If within a Java @see comment, displays the associated definition for editing and returns non-nil, else nil.
|
|
667 Non-nil is returned even if the @see referent cannot be found.
|
0
|
668
|
100
|
669 Does nothing if the `oo-browser' command is undefined, since it requires that
|
|
670 package for class and feature lookups."
|
|
671 ;;
|
|
672 ;; Valid forms of @see cross-references are:
|
|
673 ;; * @see #getComponent - current class attribute
|
|
674 ;; * @see #waitForAll() - current class method, no arguments
|
|
675 ;; * @see #checkID(int, boolean) - current class method, with arguments
|
|
676 ;; * @see java.awt.ColorModel#getRGBdefault - library class method
|
|
677 ;; * @see Component#paintAll - class method
|
|
678 ;; * @see java.awt.GridBagLayout - library class
|
|
679 ;; * @see Container - class
|
|
680 ;;
|
|
681 ;; For simplicity sake, this code ignores the library path given with any
|
|
682 ;; class in favor of the OO-Browser's lookup tables. It also ignores any
|
|
683 ;; parameters associated with a method, and thus cannot distinguish between
|
|
684 ;; methods with the same name within a single class, which we believe to be
|
|
685 ;; fairly bad form anyway.
|
|
686 ;;
|
|
687 (let ((opoint (point)))
|
|
688 (if (and (eq major-mode 'java-mode) buffer-file-name
|
|
689 (fboundp 'br-env-load)
|
|
690 (or (looking-at "@see[ \t]+")
|
|
691 (and (re-search-backward "[@\n\r\f]" nil t)
|
|
692 (looking-at "@see[ \t]+"))))
|
|
693 (let ((class) (feature))
|
|
694 ;; Ignore any library path preceding a classname (grouping 1)
|
|
695 (cond
|
|
696 ((looking-at
|
|
697 "@see[ \t]+\\(#\\)?\\([^][(){} \t\n\r\f#]+[.]\\)?\\([^][(){} \t\n\r\f#.]+\\)[][(){} \t\n\r\f]")
|
|
698 (if (match-beginning 1)
|
|
699 (setq class nil
|
|
700 feature (buffer-substring (match-beginning 3)
|
|
701 (match-end 3)))
|
|
702 (setq class (buffer-substring (match-beginning 3) (match-end 3))
|
|
703 feature nil)))
|
|
704 ((looking-at
|
|
705 "@see[ \t]+\\([^][(){} \t\n\r\f#]+[.]\\)?\\([^][(){} \t\n\r\f#.]+\\)#\\([^][(){} \t\n\r\f#.]+\\)")
|
|
706 (setq class (buffer-substring (match-beginning 2)
|
|
707 (match-end 2))
|
|
708 feature (buffer-substring (match-beginning 3)
|
|
709 (match-end 3)))))
|
|
710 ;; Return to original point.
|
|
711 (goto-char opoint)
|
|
712 ;; Lookup class / feature.
|
|
713 (cond
|
|
714 ((and (null class) (null feature))
|
|
715 ;; Invalid or unrecognized @see format, so ignore.
|
|
716 (message "(smart-java-cross-reference): Invalid @see cross-reference format.")
|
|
717 (beep)
|
|
718 t)
|
|
719 ;; Ensure that a Java OO-Browser environment has been loaded.
|
|
720 (t (if (or (and (boundp 'br-lang-prefix)
|
|
721 (equal br-lang-prefix "java-")
|
|
722 (boundp 'br-env-file) (stringp br-env-file)
|
|
723 (null br-env-spec))
|
|
724 ;; Load an existing Environment based on current
|
|
725 ;; buffer or prompt to build one. This also
|
|
726 ;; loads the "br-java.el" library in which the
|
|
727 ;; `java-class-def-regexp' variable used below
|
|
728 ;; is defined.
|
|
729 (and (br-env-load
|
|
730 (smart-tags-file
|
|
731 buffer-file-name
|
|
732 (if (boundp 'br-env-default-file)
|
|
733 br-env-default-file "OOBR")))
|
|
734 (equal br-lang-prefix "java-")))
|
|
735 (cond ((null feature)
|
|
736 (br-edit nil class))
|
|
737 (t
|
|
738 (if (null class)
|
|
739 (if (save-excursion
|
|
740 (or (re-search-backward java-class-def-regexp nil t)
|
|
741 (re-search-forward java-class-def-regexp nil t)))
|
|
742 (setq class (buffer-substring
|
|
743 (match-beginning java-class-def-name-grpn)
|
|
744 (match-end java-class-def-name-grpn)))
|
|
745 (error "(smart-java-cross-reference): This @see must be in a class definition.")))
|
|
746 (br-edit-feature class feature t)))
|
|
747 (error "(smart-java-cross-reference): The OO-Browser failed to load a Java environment.")))))
|
|
748 ;; Return to original point.
|
|
749 (goto-char opoint)
|
|
750 nil)))
|
0
|
751
|
100
|
752 (defun smart-java-library-path (library-name)
|
|
753 "Search up directory tree from current directory for a match to LIBRARY-NAME."
|
|
754 (let ((path default-directory)
|
|
755 (library-path)
|
|
756 (library-regexp (if (string-match "\\.\\|'//" library-name)
|
|
757 (regexp-quote
|
|
758 (concat (file-name-as-directory "")
|
|
759 (substring library-name 0 (match-beginning 0))
|
|
760 (file-name-as-directory "")))))
|
|
761 (start 0))
|
|
762 ;; Return rightmost match to first part of library-name.
|
|
763 (if library-regexp
|
|
764 (while (string-match library-regexp path start)
|
|
765 (setq start (1+ (match-beginning 0))
|
|
766 library-path (substring path 0 (match-beginning 0)))))
|
|
767 library-path))
|
0
|
768
|
100
|
769 (defun smart-java-packages ()
|
|
770 "If point is on a `package' or `import' line, this tries to display the associated referent.
|
|
771 Returns non-nil iff on such a line, even if the referent is not found.
|
|
772 Look for packages in `smart-java-package-dirs'."
|
|
773 (let ((opoint (point)))
|
|
774 (beginning-of-line)
|
|
775 (if (looking-at smart-java-package-regexp)
|
|
776 (let ((keyword-type (buffer-substring
|
|
777 (match-beginning 1) (match-end 1)))
|
|
778 (referent (buffer-substring (match-beginning 2) (match-end 2)))
|
|
779 (found)
|
|
780 (subpath)
|
|
781 dir-list path subfile)
|
|
782 (goto-char opoint)
|
|
783 (if (string-equal keyword-type "package")
|
|
784 (let ((library-path (smart-java-library-path referent)))
|
|
785 (if library-path
|
|
786 (hpath:find (expand-file-name
|
|
787 (hypb:replace-match-string
|
|
788 "\\." referent (file-name-as-directory "") t)
|
|
789 library-path))
|
|
790 ;; Show the current directory, which should contain this package.
|
|
791 (hpath:find default-directory)))
|
|
792 ;; This is an `import' statement. If it includes a *, show the
|
|
793 ;; associated library directory, otherwise, show the specific
|
|
794 ;; package.
|
|
795 (if (string-match "\\.\\*" referent)
|
|
796 (setq subfile (substring referent 0 (match-beginning 0))
|
|
797 subfile (hypb:replace-match-string
|
|
798 "\\." subfile (file-name-as-directory "") t))
|
|
799 (setq subpath (hypb:replace-match-string
|
|
800 "\\." referent (file-name-as-directory "") t)
|
|
801 subfile (concat subpath ".java")))
|
|
802 ;;
|
|
803 ;; Try to find the path containing referent.
|
|
804 ;;
|
|
805 ;; Search up the current directory tree for a possible matching
|
|
806 ;; directory below which the referent library might live and add
|
|
807 ;; this to smart-java-package-dirs for searching.
|
|
808 (let ((library-path (smart-java-library-path referent)))
|
|
809 (if library-path
|
|
810 (setq dir-list (cons library-path smart-java-package-dirs))))
|
0
|
811
|
100
|
812 (while dir-list
|
|
813 (setq path (expand-file-name subfile (car dir-list))
|
|
814 dir-list (if (setq found (file-exists-p path))
|
|
815 nil
|
|
816 (cdr dir-list))))
|
|
817 (if (and (not found) subpath hyperb:microcruft-os-p)
|
|
818 ;; Try .jav suffix.
|
|
819 (progn (setq subfile (concat subpath ".jav")
|
|
820 dir-list smart-java-package-dirs)
|
|
821 (while dir-list
|
|
822 (setq path (expand-file-name subfile (car dir-list))
|
|
823 dir-list (if (setq found (file-exists-p path))
|
|
824 nil
|
|
825 (cdr dir-list))))))
|
|
826 ;;
|
|
827 ;; If found, display file
|
|
828 ;;
|
|
829 (if found
|
|
830 (if (file-readable-p path)
|
|
831 (hpath:find path)
|
|
832 (beep)
|
|
833 (message "(smart-java-packages): `%s' unreadable." path))
|
|
834 (beep)
|
|
835 (message "(smart-java-packages): `%s' not found." referent))
|
|
836 path))
|
|
837 (goto-char opoint)
|
|
838 nil)))
|
0
|
839
|
|
840 (defun smart-library-symbol (tag)
|
|
841 "Return non-nil if TAG is a library symbol listed in cache of such symbols.
|
|
842 See the \"${hyperb:dir}/smart-clib-sym\" script for more information."
|
|
843 (let ((buf (get-buffer-create "*junk*"))
|
|
844 (found))
|
|
845 (save-excursion
|
|
846 (set-buffer buf)
|
|
847 (setq buffer-read-only nil)
|
|
848 (erase-buffer)
|
|
849 (call-process (expand-file-name "smart-clib-sym" hyperb:dir)
|
|
850 nil buf nil tag)
|
|
851 (setq found (string-equal (buffer-substring 1 2) "1"))
|
|
852 (set-buffer-modified-p nil)
|
|
853 (kill-buffer buf)
|
|
854 found)))
|
|
855
|
100
|
856 (defun smart-tags-display (tag next)
|
|
857 (if next (setq tag nil))
|
|
858 (let ((func (or (if (fboundp 'find-tag-internal) 'find-tag-internal)
|
|
859 (if (fboundp 'find-tag-noselect) 'find-tag-noselect)))
|
|
860 ;; For XEmacs
|
|
861 (tags-always-exact t)
|
|
862 ;; For Emacs 19
|
|
863 (find-tag-tag-order (if (boundp 'find-tag-tag-order)
|
|
864 find-tag-tag-order)))
|
|
865 (if find-tag-tag-order
|
|
866 (if next nil (setq find-tag-tag-order '(tag-exact-match-p)))
|
|
867 ;; For InfoDock (XEmacs may also take this branch), force exact match.
|
|
868 (if (stringp tag) (setq tag (list tag))))
|
|
869 (if (and func (funcall func tag))
|
|
870 (hpath:display-buffer (current-buffer)))
|
|
871 ;; Signals an error if tag is not found which is caught by many callers
|
|
872 ;; of this function.
|
|
873 (find-tag tag)))
|
|
874
|
0
|
875 ;;;###autoload
|
|
876 (defun smart-tags-file-path (file)
|
|
877 "Expand relative FILE name by looking it up in the nearest tags file.
|
|
878 Return FILE unchanged if it exists relative to the current directory or
|
|
879 cannot be expanded via a tags file."
|
|
880 (or (cond ((or (file-exists-p file) (file-name-absolute-p file)) file)
|
|
881 (t (let ((tags-file (smart-tags-file default-directory))
|
|
882 (file-regexp
|
|
883 (concat "\^L\n\\(.*/\\)?" (regexp-quote file) ",")))
|
|
884 (if tags-file
|
|
885 (progn
|
|
886 (set-buffer (find-file-noselect tags-file))
|
|
887 (goto-char (point-min))
|
|
888 (if (re-search-forward file-regexp nil t)
|
|
889 (expand-file-name
|
|
890 (buffer-substring (1- (match-end 0))
|
|
891 (progn (beginning-of-line)
|
|
892 (point))))))))))
|
|
893 file))
|
|
894
|
|
895 ;;;###autoload
|
100
|
896 (defun smart-tags-file (curr-filename &optional name-of-tags-file)
|
|
897 "Return appropriate tags file name for CURR-FILENAME or `tags-file-name'.
|
|
898 Optional NAME-OF-TAGS-FILE is the literal filename for which to look."
|
0
|
899 (let ((path curr-filename)
|
|
900 (tags-file))
|
|
901 (while (and
|
|
902 (stringp path)
|
|
903 (setq path (file-name-directory path))
|
|
904 (setq path (directory-file-name path))
|
|
905 ;; Not at root directory
|
|
906 (not (string-match ":?/\\'" path))
|
|
907 ;; No tags file
|
|
908 (not (file-exists-p
|
100
|
909 (setq tags-file (expand-file-name (or name-of-tags-file "TAGS") path)))))
|
0
|
910 (setq tags-file nil))
|
|
911 (if (and (not tags-file)
|
|
912 (stringp curr-filename)
|
|
913 (smart-emacs-lisp-mode-p)
|
|
914 (let ((path (file-name-directory curr-filename)))
|
|
915 (delq nil (mapcar
|
|
916 (function
|
|
917 (lambda (p)
|
|
918 (and p (equal (file-name-as-directory p)
|
|
919 path))))
|
|
920 load-path))))
|
|
921 (setq tags-file smart-emacs-tags-file))
|
|
922 (or tags-file tags-file-name
|
|
923 (call-interactively 'visit-tags-table))))
|
|
924
|
|
925 ;;; ************************************************************************
|
|
926 ;;; Private variables
|
|
927 ;;; ************************************************************************
|
|
928
|
|
929 (provide 'hmouse-tag)
|