annotate lisp/hyperbole/hmouse-tag.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children 4103f0995bd7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;!emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; FILE: hmouse-tag.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; SUMMARY: Smart Key support of programming language tags location.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; USAGE: GNU Emacs Lisp Library
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; KEYWORDS: c, hypermedia, mouse, oop, tools
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; AUTHOR: Bob Weiner
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; ORG: Brown U.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; ORIG-DATE: 24-Aug-91
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; LAST-MOD: 11-Sep-95 at 18:19:48 by Bob Weiner
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; This file is part of Hyperbole.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; Available for use and distribution under the same terms as GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; Copyright (C) 1991-1995, Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; Developed with support from Motorola Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; DESCRIPTION:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; Supports C, C++, Objective-C, Lisp, Fortran, and Assembly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;; See the GNU Emacs manual for information on how to create a TAGS file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;; from the `etags' program.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;; Does not support the `ctags' tags file format.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;; YOU MUST APPROPRIATELY SET THE PUBLIC VARIABLES BELOW BEFORE USE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; DESCRIP-END.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;;; Other required Elisp libraries
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 (if (cond ((or (featurep 'etags) (featurep 'tags))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ((or hyperb:lemacs-p hyperb:emacs19-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;; Force use of .elc file here since otherwise the bin/etags
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;; executable might be found in a user's load-path by the load
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;; command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (or (load "etags.elc" t nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (load "tags-fix" t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ((load "tags" t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (provide 'tags))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;;; Public variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (defvar smart-asm-include-dirs nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 "*Ordered list of directories to search for assembly language include files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 Each directory must end with a directory separator.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (defconst smart-asm-include-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 "[ \t*#|;]*\\(include\\|lib\\)[ \t]+\\([^ \t\n\^M]+\\)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 "Regexp to match to assembly language include file lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 Include keyword matched is grouping 1. File name is grouping 2 but may be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 missing its suffix, so add \".ins\" or \".inc\" if need be.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 Examples include:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 INCLUDE GLOBALS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 should jump to file \"globals.ins\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 lib conditionals_equ.inc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 should include \"conditionals_equ.inc\"")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (defvar smart-c-cpp-include-dirs '("/usr/include/")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 "*Ordered list of include directories by default searched by C/C++ preprocessor.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 Each directory must end with a directory separator. See also
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 'smart-c-include-dirs'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (defvar smart-c-include-dirs nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 "*Ordered list of directories to search for C/C++ include files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 Each directory must end with a directory separator. Directories normally
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 searched by the C/C++ pre-processor should be set instead in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 'smart-c-cpp-include-dirs'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (defvar smart-c-use-lib-man nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 "When non-nil makes 'smart-c' and 'smart-c++' display man pages for recognized lib symbols.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 When nil, 'smart-c' and 'smart-c++' look up only symbols defined in an etags
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 TAGS file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 Create the file ~/.CLIBS-LIST and populate it with the full pathnames (one per
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 line) of all of the C/C++ libraries whose symbols you want to match against.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 Your MANPATH environment variable must include paths for the man pages of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 these libraries also.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 Your smart-clib-sym executable script must output a 1 if a symbol is from a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 C/C++ library listed in ~/.CLIBS-LIST or 0 if not! Otherwise, don't set this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 variable to t.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (defconst smart-c-include-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 "[ \t/*]*#[ \t]*\\(include\\|import\\)[ \t]+\\([\"<]\\)\\([^\">]+\\)[\">]"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 "Regexp to match to C, C++, or Objective-C include file lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 Include keyword matched is grouping 1. Type of include, user-specified via
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 double quote, or system-related starting with '<' is given by grouping 2.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 File name is grouping 3.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (defvar smart-emacs-tags-file nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 "*Full path name of etags file for GNU Emacs source.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 ;;; Public functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (defun smart-asm (&optional identifier next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 "Jumps to the definition of optional assembly IDENTIFIER or the one at point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 Optional second arg NEXT means jump to next matching assembly tag.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 It assumes that its caller has already checked that the key was pressed in an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 appropriate buffer and has moved the cursor to the selected buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 If:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (1) on an include statement, the include file is displayed;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 Look for include file in directory list 'smart-asm-include-dirs'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (2) on an identifier, the identifier definition is displayed,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 assuming the identifier is found within an 'etags' generated tag file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 in the current directory or any of its ancestor directories."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (if identifier nil (smart-asm-include-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (let ((tag (or identifier (smart-asm-at-tag-p))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 ;; Set free variable tags-file-name so that next 'find-tag' command uses
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 ;; whatever tags file is set here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (setq tags-file-name (smart-tags-file buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (message "Looking for '%s' in '%s'..." tag tags-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (funcall (if (br-in-browser)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 'find-tag 'find-tag-other-window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 tag next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (message "Found definition for '%s'." tag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (error (message "'%s' not found in '%s'." tag tags-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (beep))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (defun smart-asm-at-tag-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 "Return assembly tag name that point is within, else nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (let* ((identifier-chars "_.$a-zA-Z0-9")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (identifier (concat "[_.$a-zA-Z][" identifier-chars "]*")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (skip-chars-backward identifier-chars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (if (looking-at identifier)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (buffer-substring (point) (match-end 0))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (defun smart-asm-include-file ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 "If point is on an include file line, tries to display file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 Returns non-nil iff on an include file line, even if file is not found.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 Look for include file in 'smart-asm-include-dirs' and add suffix \".ins\" or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 \".inc\" to filename if it lacks a suffix."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (let ((opoint (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 ;; Some assemblers utilize the C preprocessor, so try that first.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (cond ((smart-c-include-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 ((progn (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (looking-at smart-asm-include-regexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (let ((file (buffer-substring (match-beginning 2) (match-end 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (dir-list smart-asm-include-dirs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (goto-char opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (setq dir-list (cons (file-name-directory buffer-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 dir-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (if (string-match "\\." file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (setq file (regexp-quote file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (setq file (concat (regexp-quote file) "\\.in[sc]$")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (while dir-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (setq dir-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (if (setq path (car (directory-files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (car dir-list) t file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (cdr dir-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 ;; If path exists, display file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (if path
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (if (and (file-readable-p path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (if (br-in-browser)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (find-file path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (find-file-other-window path))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (cond ((featurep 'asm-mode) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 ((load "asm-mode" nil 'nomessage)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (provide 'asm-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (beep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 "(smart-asm-include-file): asm-mode undefined.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (beep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (message "(smart-asm-include-file): '%s' unreadable." path))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (beep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (message "(smart-asm-include-file): '%s' not found." file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 path))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 ;; not on an include file line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (t (goto-char opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (defun smart-c (&optional identifier next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 "Jumps to the definition of optional C IDENTIFIER or the one at point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 Optional second arg NEXT means jump to next matching C tag.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 It assumes that its caller has already checked that the key was pressed in an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 appropriate buffer and has moved the cursor to the selected buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 If:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (1) on a '#include' statement, the include file is displayed;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 Look for include file in directory lists 'smart-c-cpp-include-dirs'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 and 'smart-c-include-dirs'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (2) on a C identifier, the identifier definition is displayed,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 assuming the identifier is found within an 'etags' generated tag file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 in the current directory or any of its ancestor directories.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (3) if 'smart-c-use-lib-man' is non-nil, the C identifier is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 recognized as a library symbol, and a man page is found for the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 identifier, then the man page is displayed."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (if identifier nil (smart-c-include-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (let ((tag (or identifier (smart-c-at-tag-p))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 ;; Set free variable tags-file-name so that next 'find-tag' command uses
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 ;; whatever tags file is set here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (setq tags-file-name (smart-tags-file buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (message "Looking for '%s' in '%s'..." tag tags-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (funcall (if (br-in-browser)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 'find-tag 'find-tag-other-window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 tag next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (message "Found definition for '%s'." tag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (if (not smart-c-use-lib-man)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (progn (message "'%s' not found in '%s'." tag tags-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (beep))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (message "Checking if '%s' is a C library function..." tag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (if (smart-library-symbol tag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (progn (message "Displaying C library man page for '%s'." tag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (manual-entry tag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (message "'%s' not found in '%s' or C libraries."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 tag tags-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (beep))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (defun smart-c-at-tag-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 "Return C tag name that point is within, else nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (let* ((identifier-chars "_a-zA-Z0-9")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (identifier (concat "[_a-zA-Z][" identifier-chars "]*")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (skip-chars-backward identifier-chars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (if (looking-at identifier)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (buffer-substring (point) (match-end 0))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (defun smart-c-include-file ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 "If point is on an include file line, tries to display file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 Returns non-nil iff on an include file line, even if file is not found.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 Look for include file in 'smart-c-cpp-include-dirs' and in directory list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 'smart-c-include-dirs'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (let ((opoint (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (if (looking-at smart-c-include-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (let ((incl-type (string-to-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (buffer-substring (match-beginning 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (1+ (match-beginning 2)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (file (buffer-substring (match-beginning 3) (match-end 3)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (dir-list smart-c-include-dirs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (found))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (goto-char opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (setq dir-list (if (= incl-type ?<)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (append dir-list smart-c-cpp-include-dirs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (cons (file-name-directory buffer-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 dir-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (while dir-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (setq path (expand-file-name file (car dir-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 dir-list (if (setq found (file-exists-p path))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (cdr dir-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 ;; If found, display file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (if found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (if (and (file-readable-p path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (if (br-in-browser)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (find-file path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (find-file-other-window path))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (cond ((or (featurep 'cc-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (featurep 'c-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 ((or (load "cc-mode" 'missing-ok 'nomessage)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (load "c-mode" 'missing-ok 'nomessage))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (provide 'c-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (beep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 "(smart-c-include-file): c-mode undefined.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (beep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (message "(smart-c-include-file): '%s' unreadable." path))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (beep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (message "(smart-c-include-file): '%s' not found." file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (goto-char opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (defun smart-c++ (&optional identifier next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 "Jumps to the definition of optional C++ IDENTIFIER or the one at point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 Optional second arg NEXT means jump to next matching C++ tag.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 It assumes that its caller has already checked that the key was pressed in an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 appropriate buffer and has moved the cursor to the selected buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 If:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (1) on a '#include' statement, the include file is displayed;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 Look for include file in directory lists 'smart-c-cpp-include-dirs'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 and 'smart-c-include-dirs'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (2) on a C++ identifier, the identifier definition is displayed,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 assuming the identifier is found within an 'etags' generated tag file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 in the current directory or any of its ancestor directories.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (3) if 'smart-c-use-lib-man' is non-nil, the C++ identifier is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 recognized as a library symbol, and a man page is found for the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 identifier, then the man page is displayed."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (if identifier nil (smart-c-include-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (let ((tag (or identifier (smart-c++-at-tag-p))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 ;; Set free variable tags-file-name so that next 'find-tag' command uses
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 ;; whatever tags file is set here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (setq tags-file-name (smart-tags-file buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (message "Looking for '%s' in '%s'..." tag tags-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (funcall (if (br-in-browser)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 'find-tag 'find-tag-other-window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 tag next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (message "Found definition for '%s'." tag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (if (not smart-c-use-lib-man)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (progn (message "'%s' not found in '%s'." tag tags-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (beep))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (message "Checking if '%s' is a C++ library function..." tag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (if (smart-library-symbol tag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (progn (message "Displaying C++ library man page for '%s'." tag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (manual-entry tag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (message "'%s' not found in '%s' or C++ libraries."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 tag tags-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 (beep))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 ;;; The following should be called only if the OO-Browser is available.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (defun smart-c++-oobr (&optional junk)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 "Jumps to the definition of selected C++ construct via OO-Browser support.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 Optional JUNK is ignored. Does nothing if the OO-Browser is not available.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 It assumes that its caller has already checked that the key was pressed in an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 appropriate buffer and has moved the cursor to the selected buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 If key is pressed:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (1) on a '#include' statement, the include file is displayed;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 Look for include file in directory lists 'smart-c-cpp-include-dirs'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 and 'smart-c-include-dirs'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 (2) within a method declaration, its definition is displayed;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 (3) on a class name, the class definition is shown.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 (2) and (3) require that an OO-Browser Environment has been loaded with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 the {M-x br-env-load RTN} command."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (c++-to-definition 'other-win))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (defun smart-c++-at-tag-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 "Return C++ tag name that point is within, else nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (let* ((identifier-chars "_:~<>a-zA-Z0-9")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (identifier (concat "\\([_~:<a-zA-Z][" identifier-chars "]*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 "[ \t]*[^]) \t:;.,?~{}][^[( \t:;.,~^!|?{}]?[=*]?\\)[ \t\n]*(")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 (skip-chars-backward identifier-chars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 (if (looking-at identifier)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 (buffer-substring (point) (match-end 1))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 (defun smart-emacs-lisp-mode-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 "Return t if in a mode which uses Emacs Lisp symbols."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 (or (eq major-mode 'emacs-lisp-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (eq major-mode 'lisp-interaction-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 (eq major-mode 'debugger-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 ;; Emacs Lisp symbols appear in Help buffers frequently.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 (string-match "Help\\*$" (buffer-name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (defun smart-fortran (&optional identifier next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 "Jumps to the definition of optional Fortran IDENTIFIER or the one at point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 Optional second arg NEXT means jump to next matching Fortran tag.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 It assumes that its caller has already checked that the key was pressed in an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 appropriate buffer and has moved the cursor to the selected buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 If on a Fortran identifier, the identifier definition is displayed,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 assuming the identifier is found within an 'etags' generated tag file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 in the current directory or any of its ancestor directories."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (let ((tag (or identifier (smart-fortran-at-tag-p))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 ;; Set free variable tags-file-name so that next 'find-tag' command uses
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 ;; whatever tags file is set here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 (setq tags-file-name (smart-tags-file buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (message "Looking for '%s' in '%s'..." tag tags-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (funcall (if (br-in-browser)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 'find-tag 'find-tag-other-window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 tag next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (message "Found definition for '%s'." tag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (message "'%s' not found in '%s'." tag tags-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 (beep)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 (defun smart-fortran-at-tag-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 "Return Fortran tag name that point is within, else nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 (let* ((identifier-chars "_a-zA-Z0-9")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (identifier (concat "[_a-zA-Z][" identifier-chars "]*")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (skip-chars-backward identifier-chars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (if (looking-at identifier)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (buffer-substring (point) (match-end 0))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (defun smart-lisp (&optional next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 "Jumps to the definition of any selected Lisp construct.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 If on an Emacs Lisp require, load, or autoload clause and 'find-library'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 from load-library package by Hallvard Furuseth (hallvard@ifi.uio.no) has
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 been loaded, jumps to library source, if possible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 Otherwise, the construct must be found within an 'etags' generated tag file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 in the current directory or any of its ancestor directories in order for its
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 definition to be located.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 Optional NEXT means jump to next matching Lisp tag. When matching to an Emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 Lisp tag using 'wtags' (Bob Weiner's personal modifications to 'etags'),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 there is no next tag, so display documentation for current tag instead.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 This command assumes that its caller has already checked that the key was
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 pressed in an appropriate buffer and has moved the cursor to the selected
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 ;; Handle 'require', 'load', and 'autoload' clauses in Emacs Lisp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (or (and (fboundp 'find-library)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (smart-emacs-lisp-mode-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 (let ((req)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 (opoint (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 (setq req (and (search-backward "\(" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (looking-at (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 "(\\(require\\|load\\|autoload\\)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 "[ \t]+.*['\"]"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 "\\([^][() \t\n\^M`'\"]+\\)"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (goto-char opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (if req (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 (setq req (buffer-substring (match-beginning 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (match-end 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 (pop-to-buffer nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (find-library req)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 (let ((tag (smart-lisp-at-tag-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 ;; Set free variable tags-file-name so that next 'find-tag' command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 ;; uses whatever tags file is set here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 (setq tags-file-name (smart-tags-file default-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 ;; This part only works properly for Emacs Lisp, so is conditionalized.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (if (and next (smart-emacs-lisp-mode-p) (featurep 'wtags))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 (progn (setq tag (intern tag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (cond ((fboundp tag) (describe-function tag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 ((boundp tag) (describe-variable tag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (t (error "(smart-lisp): Unbound symbol: %s" tag))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (funcall (if (br-in-browser)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 'find-tag 'find-tag-other-window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 tag next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (error (if (equal tags-file-name smart-emacs-tags-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (setq tags-file-name smart-emacs-tags-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 (funcall (if (br-in-browser)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 'find-tag 'find-tag-other-window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 tag next))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (defun smart-lisp-at-tag-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 "Returns Lisp tag name that point is within, else nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 Returns nil when point is on the first line of a 'def' form past the first 4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 characters."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (let* ((identifier-chars "-_*:+%$#!<>a-zA-Z0-9")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 (identifier (concat "[-<*a-zA-Z][" identifier-chars "]*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 (opoint (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (if (and (looking-at "\\(;*[ \t]*\\)?(def[^- \n\t]+[ \n\t]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (> opoint (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 (goto-char opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 (skip-chars-backward identifier-chars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (if (looking-at identifier)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 (buffer-substring (point) (match-end 0)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 (defun smart-lisp-mode-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 "Return t if in a mode which uses Lisp symbols."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 (or (smart-emacs-lisp-mode-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 (eq major-mode 'lisp-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 (eq major-mode 'scheme-mode)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 (defun smart-objc (&optional identifier next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 "Jumps to the definition of optional Objective-C IDENTIFIER or the one at point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 Optional second arg NEXT means jump to next matching Objective-C tag.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 It assumes that its caller has already checked that the key was pressed in an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 appropriate buffer and has moved the cursor to the selected buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 If:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 (1) on a '#include' statement, the include file is displayed;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 Look for include file in directory lists 'smart-c-cpp-include-dirs'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 and 'smart-c-include-dirs'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 (2) on an Objective-C identifier, the identifier definition is displayed,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 assuming the identifier is found within an 'etags' generated tag file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 in the current directory or any of its ancestor directories.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (3) if 'smart-c-use-lib-man' is non-nil, the Objective-C identifier is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 recognized as a library symbol, and a man page is found for the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 identifier, then the man page is displayed."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 (or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 (if identifier nil (smart-c-include-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 (let ((tag (or identifier (smart-objc-at-tag-p))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 ;; Set free variable tags-file-name so that next 'find-tag' command uses
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 ;; whatever tags file is set here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 (setq tags-file-name (smart-tags-file buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 (message "Looking for '%s' in '%s'..." tag tags-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 (funcall (if (br-in-browser)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 'find-tag 'find-tag-other-window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 tag next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 (message "Found definition for '%s'." tag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 (if (not smart-c-use-lib-man)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 (progn (message "'%s' not found in '%s'." tag tags-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 (beep))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 (message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 "Checking if '%s' is an Objective-C library function..." tag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 (if (smart-library-symbol tag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 (message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 "Displaying Objective-C library man page for '%s'." tag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 (manual-entry tag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 (message "'%s' not found in '%s' or Objective-C libraries."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 tag tags-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 (beep))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 ;;; The following should be called only if the OO-Browser is available.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 (defun smart-objc-oobr (&optional junk)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 "Jumps to the definition of selected Objective-C construct via OO-Browser support.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 Optional JUNK is ignored. Does nothing if the OO-Browser is not available.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 It assumes that its caller has already checked that the key was pressed in an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 appropriate buffer and has moved the cursor to the selected buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 If key is pressed:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 (1) on a '#include' statement, the include file is displayed;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 Look for include file in directory lists 'smart-c-cpp-include-dirs'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 and 'smart-c-include-dirs'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 (2) within a method declaration, its definition is displayed;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 (3) on a class name, the class definition is shown.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 (2) and (3) require that an OO-Browser Environment has been loaded with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 the {M-x br-env-load RTN} command."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 (objc-to-definition 'other-win))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 (defun smart-objc-at-tag-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 "Return Objective-C tag name that point is within, else nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 (let* ((identifier-chars "_a-zA-Z0-9")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 (identifier
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 (concat "\\([-+][ \t]*\\)?\\([_a-zA-Z][" identifier-chars "]*\\)")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 (skip-chars-backward identifier-chars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 (if (looking-at identifier)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 (buffer-substring (match-beginning 2) (match-end 2))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 ;;; Private functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 (defun smart-library-symbol (tag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 "Return non-nil if TAG is a library symbol listed in cache of such symbols.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 See the \"${hyperb:dir}/smart-clib-sym\" script for more information."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 (let ((buf (get-buffer-create "*junk*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 (found))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 (setq buffer-read-only nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 (call-process (expand-file-name "smart-clib-sym" hyperb:dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 nil buf nil tag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 (setq found (string-equal (buffer-substring 1 2) "1"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 (set-buffer-modified-p nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 (kill-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 found)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 (defun smart-tags-file-path (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 "Expand relative FILE name by looking it up in the nearest tags file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 Return FILE unchanged if it exists relative to the current directory or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 cannot be expanded via a tags file."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 (or (cond ((or (file-exists-p file) (file-name-absolute-p file)) file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 (t (let ((tags-file (smart-tags-file default-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 (file-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 (concat "\^L\n\\(.*/\\)?" (regexp-quote file) ",")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 (if tags-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 (set-buffer (find-file-noselect tags-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 (if (re-search-forward file-regexp nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 (expand-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 (buffer-substring (1- (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 (progn (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 (point))))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 (defun smart-tags-file (curr-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 "Return appropriate tags file name for CURR-FILENAME or 'tags-file-name'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 (let ((path curr-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 (tags-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 (while (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 (stringp path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 (setq path (file-name-directory path))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 (setq path (directory-file-name path))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 ;; Not at root directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 (not (string-match ":?/\\'" path))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 ;; No tags file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 (not (file-exists-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 (setq tags-file (expand-file-name "TAGS" path)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 (setq tags-file nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 (if (and (not tags-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 (stringp curr-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 (smart-emacs-lisp-mode-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 (let ((path (file-name-directory curr-filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 (delq nil (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 (lambda (p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 (and p (equal (file-name-as-directory p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 path))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 load-path))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 (setq tags-file smart-emacs-tags-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 (or tags-file tags-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 (call-interactively 'visit-tags-table))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 ;;; Private variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 (provide 'hmouse-tag)