aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman2005-01-05 01:08:24 +0000
committerRichard M. Stallman2005-01-05 01:08:24 +0000
commit0acffda1d3f09f708ce4909c53576dcce57babc0 (patch)
tree8a4f9c5ab6283089fb15ce54fc84523fd4fea735
parentdd496df6bc596b61391e296bedf577659bdd5132 (diff)
downloademacs-0acffda1d3f09f708ce4909c53576dcce57babc0.tar.gz
emacs-0acffda1d3f09f708ce4909c53576dcce57babc0.zip
Doc fixes.
(find-face-regexp): New variable. (find-function-regexp-alist): New variable. (find-function-C-source): Third arg is now TYPE. (find-function-search-for-symbol): Handle general TYPE. (find-function-read, find-function-do-it): Handle general TYPE. (find-definition-noselect, find-face): New functions. (function-at-point): Alias deleted.
-rw-r--r--lisp/emacs-lisp/find-func.el163
1 files changed, 108 insertions, 55 deletions
diff --git a/lisp/emacs-lisp/find-func.el b/lisp/emacs-lisp/find-func.el
index 8b3125db50b..d6cc8be7062 100644
--- a/lisp/emacs-lisp/find-func.el
+++ b/lisp/emacs-lisp/find-func.el
@@ -78,7 +78,8 @@ Please send improvements and fixes to the maintainer."
78(defcustom find-variable-regexp 78(defcustom find-variable-regexp
79 (concat"^\\s-*(def[^fumag]\\(\\w\\|\\s_\\)+\\*?" find-function-space-re "%s\\(\\s-\\|$\\)") 79 (concat"^\\s-*(def[^fumag]\\(\\w\\|\\s_\\)+\\*?" find-function-space-re "%s\\(\\s-\\|$\\)")
80 "The regexp used by `find-variable' to search for a variable definition. 80 "The regexp used by `find-variable' to search for a variable definition.
81It should match right up to the variable name. The default value 81Note it must contain a `%s' at the place where `format'
82should insert the variable name. The default value
82avoids `defun', `defmacro', `defalias', `defadvice', `defgroup', `defface'. 83avoids `defun', `defmacro', `defalias', `defadvice', `defgroup', `defface'.
83 84
84Please send improvements and fixes to the maintainer." 85Please send improvements and fixes to the maintainer."
@@ -86,6 +87,26 @@ Please send improvements and fixes to the maintainer."
86 :group 'find-function 87 :group 'find-function
87 :version "21.1") 88 :version "21.1")
88 89
90(defcustom find-face-regexp
91 (concat"^\\s-*(defface" find-function-space-re "%s\\(\\s-\\|$\\)")
92 "The regexp used by `find-face' to search for a face definition.
93Note it must contain a `%s' at the place where `format'
94should insert the face name.
95
96Please send improvements and fixes to the maintainer."
97 :type 'regexp
98 :group 'find-function
99 :version "21.4")
100
101(defvar find-function-regexp-alist
102 '((nil . find-function-regexp)
103 (defvar . find-variable-regexp)
104 (defface . find-face-regexp))
105 "Alist mapping definition types into regexp variables.
106Each regexp variable's value should actually be a format string
107to be used to substitute the desired symbol name into the regexp.")
108(put 'find-function-regexp-alist 'risky-local-variable t)
109
89(defcustom find-function-source-path nil 110(defcustom find-function-source-path nil
90 "The default list of directories where `find-function' searches. 111 "The default list of directories where `find-function' searches.
91 112
@@ -136,9 +157,9 @@ See the functions `find-function' and `find-variable'."
136If nil, do not try to find the source code of functions and variables 157If nil, do not try to find the source code of functions and variables
137defined in C.") 158defined in C.")
138 159
139(defun find-function-C-source (fun-or-var file variable-p) 160(defun find-function-C-source (fun-or-var file type)
140 "Find the source location where SUBR-OR-VAR is defined in FILE. 161 "Find the source location where SUBR-OR-VAR is defined in FILE.
141VARIABLE-P should be non-nil for a variable or nil for a subroutine." 162TYPE should be nil to find a function, or `defvar' to find a variable."
142 (unless find-function-C-source-directory 163 (unless find-function-C-source-directory
143 (setq find-function-C-source-directory 164 (setq find-function-C-source-directory
144 (read-directory-name "Emacs C source dir: " nil nil t))) 165 (read-directory-name "Emacs C source dir: " nil nil t)))
@@ -146,12 +167,12 @@ VARIABLE-P should be non-nil for a variable or nil for a subroutine."
146 (unless (file-readable-p file) 167 (unless (file-readable-p file)
147 (error "The C source file %s is not available" 168 (error "The C source file %s is not available"
148 (file-name-nondirectory file))) 169 (file-name-nondirectory file)))
149 (unless variable-p 170 (unless type
150 (setq fun-or-var (indirect-function fun-or-var))) 171 (setq fun-or-var (indirect-function fun-or-var)))
151 (with-current-buffer (find-file-noselect file) 172 (with-current-buffer (find-file-noselect file)
152 (goto-char (point-min)) 173 (goto-char (point-min))
153 (unless (re-search-forward 174 (unless (re-search-forward
154 (if variable-p 175 (if type
155 (concat "DEFVAR[A-Z_]*[ \t\n]*([ \t\n]*\"" 176 (concat "DEFVAR[A-Z_]*[ \t\n]*([ \t\n]*\""
156 (regexp-quote (symbol-name fun-or-var)) 177 (regexp-quote (symbol-name fun-or-var))
157 "\"") 178 "\"")
@@ -175,10 +196,12 @@ VARIABLE-P should be non-nil for a variable or nil for a subroutine."
175 (condition-case nil (switch-to-buffer buf) (error (pop-to-buffer buf))))) 196 (condition-case nil (switch-to-buffer buf) (error (pop-to-buffer buf)))))
176 197
177;;;###autoload 198;;;###autoload
178(defun find-function-search-for-symbol (symbol variable-p library) 199(defun find-function-search-for-symbol (symbol type library)
179 "Search for SYMBOL. 200 "Search for SYMBOL's definition of type TYPE in LIBRARY.
180If VARIABLE-P is nil, `find-function-regexp' is used, otherwise 201If TYPE is nil, look for a function definition.
181`find-variable-regexp' is used. The search is done in library LIBRARY." 202Otherwise, TYPE specifies the kind of definition,
203and it is interpreted via `find-function-regexp-alist'.
204The search is done in the source for library LIBRARY."
182 (if (null library) 205 (if (null library)
183 (error "Don't know where `%s' is defined" symbol)) 206 (error "Don't know where `%s' is defined" symbol))
184 ;; Some functions are defined as part of the construct 207 ;; Some functions are defined as part of the construct
@@ -186,14 +209,13 @@ If VARIABLE-P is nil, `find-function-regexp' is used, otherwise
186 (while (and (symbolp symbol) (get symbol 'definition-name)) 209 (while (and (symbolp symbol) (get symbol 'definition-name))
187 (setq symbol (get symbol 'definition-name))) 210 (setq symbol (get symbol 'definition-name)))
188 (if (string-match "\\`src/\\(.*\\.c\\)\\'" library) 211 (if (string-match "\\`src/\\(.*\\.c\\)\\'" library)
189 (find-function-C-source symbol (match-string 1 library) variable-p) 212 (find-function-C-source symbol (match-string 1 library) type)
190 (if (string-match "\\.el\\(c\\)\\'" library) 213 (if (string-match "\\.el\\(c\\)\\'" library)
191 (setq library (substring library 0 (match-beginning 1)))) 214 (setq library (substring library 0 (match-beginning 1))))
192 (let* ((filename (find-library-name library))) 215 (let* ((filename (find-library-name library))
216 (regexp-symbol (cdr (assq type find-function-regexp-alist))))
193 (with-current-buffer (find-file-noselect filename) 217 (with-current-buffer (find-file-noselect filename)
194 (let ((regexp (format (if variable-p 218 (let ((regexp (format (symbol-value regexp-symbol)
195 find-variable-regexp
196 find-function-regexp)
197 (regexp-quote (symbol-name symbol)))) 219 (regexp-quote (symbol-name symbol))))
198 (case-fold-search)) 220 (case-fold-search))
199 (with-syntax-table emacs-lisp-mode-syntax-table 221 (with-syntax-table emacs-lisp-mode-syntax-table
@@ -245,55 +267,53 @@ in `load-path'."
245 ((symbol-file function 'defun))))) 267 ((symbol-file function 'defun)))))
246 (find-function-search-for-symbol function nil library)))) 268 (find-function-search-for-symbol function nil library))))
247 269
248(defalias 'function-at-point 'function-called-at-point) 270(defun find-function-read (&optional type)
249
250(defun find-function-read (&optional variable-p)
251 "Read and return an interned symbol, defaulting to the one near point. 271 "Read and return an interned symbol, defaulting to the one near point.
252 272
253If the optional VARIABLE-P is nil, then a function is gotten 273If TYPE is nil, insist on a symbol with a function definition.
254defaulting to the value of the function `function-at-point', otherwise 274Otherwise TYPE should be `defvar' or `defface'.
255a variable is asked for, with the default coming from 275If TYPE is nil, defaults using `function-called-at-point',
256`variable-at-point'." 276otherwise uses `variable-at-point'."
257 (let ((symb (funcall (if variable-p 277 (let ((symb (if (null type)
258 'variable-at-point 278 (function-called-at-point)
259 'function-at-point))) 279 (if (eq type 'defvar)
280 (variable-at-point)
281 (variable-at-point t))))
282 (predicate (cdr (assq type '((nil . fboundp) (defvar . boundp)
283 (defface . facep)))))
284 (prompt (cdr (assq type '((nil . "function") (defvar . "variable")
285 (defface . "face")))))
260 (enable-recursive-minibuffers t) 286 (enable-recursive-minibuffers t)
261 val) 287 val)
262 (if (equal symb 0) 288 (if (equal symb 0)
263 (setq symb nil)) 289 (setq symb nil))
264 (setq val (if variable-p 290 (setq val (completing-read
265 (completing-read 291 (concat "Find "
266 (concat "Find variable" 292 prompt
267 (if symb 293 (if symb
268 (format " (default %s)" symb)) 294 (format " (default %s)" symb))
269 ": ") 295 ": ")
270 obarray 'boundp t nil) 296 obarray predicate t nil))
271 (completing-read
272 (concat "Find function"
273 (if symb
274 (format " (default %s)" symb))
275 ": ")
276 obarray 'fboundp t nil)))
277 (list (if (equal val "") 297 (list (if (equal val "")
278 symb 298 symb
279 (intern val))))) 299 (intern val)))))
280 300
281(defun find-function-do-it (symbol variable-p switch-fn) 301(defun find-function-do-it (symbol type switch-fn)
282 "Find Emacs Lisp SYMBOL in a buffer and display it. 302 "Find Emacs Lisp SYMBOL in a buffer and display it.
283If VARIABLE-P is nil, a function definition is searched for, otherwise 303TYPE is nil to search for a function definition,
284a variable definition is searched for. The start of a definition is 304or else `defvar' or `defface'.
285centered according to the variable `find-function-recenter-line'. 305
286See also `find-function-after-hook' It is displayed with function SWITCH-FN. 306The variable `find-function-recenter-line' controls how
307to recenter the display. SWITCH-FN is the function to call
308to display and select the buffer.
309See also `find-function-after-hook'.
287 310
288Point is saved in the buffer if it is one of the current buffers." 311Set mark before moving, if the buffer already existed."
289 (let* ((orig-point (point)) 312 (let* ((orig-point (point))
290 (orig-buf (window-buffer)) 313 (orig-buf (window-buffer))
291 (orig-buffers (buffer-list)) 314 (orig-buffers (buffer-list))
292 (buffer-point (save-excursion 315 (buffer-point (save-excursion
293 (funcall (if variable-p 316 (find-definition-noselect symbol type)))
294 'find-variable-noselect
295 'find-function-noselect)
296 symbol)))
297 (new-buf (car buffer-point)) 317 (new-buf (car buffer-point))
298 (new-point (cdr buffer-point))) 318 (new-point (cdr buffer-point)))
299 (when buffer-point 319 (when buffer-point
@@ -310,8 +330,8 @@ Point is saved in the buffer if it is one of the current buffers."
310 330
311Finds the Emacs Lisp library containing the definition of the function 331Finds the Emacs Lisp library containing the definition of the function
312near point (selected by `function-at-point') in a buffer and 332near point (selected by `function-at-point') in a buffer and
313places point before the definition. Point is saved in the buffer if 333places point before the definition.
314it is one of the current buffers. 334Set mark before moving, if the buffer already existed.
315 335
316The library where FUNCTION is defined is searched for in 336The library where FUNCTION is defined is searched for in
317`find-function-source-path', if non nil, otherwise in `load-path'. 337`find-function-source-path', if non nil, otherwise in `load-path'.
@@ -340,15 +360,15 @@ See `find-function' for more details."
340 "Return a pair `(BUFFER . POINT)' pointing to the definition of SYMBOL. 360 "Return a pair `(BUFFER . POINT)' pointing to the definition of SYMBOL.
341 361
342Finds the Emacs Lisp library containing the definition of SYMBOL 362Finds the Emacs Lisp library containing the definition of SYMBOL
343in a buffer and the point of the definition. The buffer is 363in a buffer, and the point of the definition. It does not switch
344not selected. 364to the buffer or display it.
345 365
346The library where VARIABLE is defined is searched for in FILE or 366The library where VARIABLE is defined is searched for in FILE or
347`find-function-source-path', if non nil, otherwise in `load-path'." 367`find-function-source-path', if non nil, otherwise in `load-path'."
348 (if (not variable) 368 (if (not variable)
349 (error "You didn't specify a variable")) 369 (error "You didn't specify a variable"))
350 (let ((library (or file (symbol-file variable 'defvar)))) 370 (let ((library (or file (symbol-file variable 'defvar))))
351 (find-function-search-for-symbol variable 'variable library))) 371 (find-function-search-for-symbol variable 'defvar library)))
352 372
353;;;###autoload 373;;;###autoload
354(defun find-variable (variable) 374(defun find-variable (variable)
@@ -356,8 +376,9 @@ The library where VARIABLE is defined is searched for in FILE or
356 376
357Finds the Emacs Lisp library containing the definition of the variable 377Finds the Emacs Lisp library containing the definition of the variable
358near point (selected by `variable-at-point') in a buffer and 378near point (selected by `variable-at-point') in a buffer and
359places point before the definition. Point is saved in the buffer if 379places point before the definition.
360it is one of the current buffers. 380
381Set mark before moving, if the buffer already existed.
361 382
362The library where VARIABLE is defined is searched for in 383The library where VARIABLE is defined is searched for in
363`find-function-source-path', if non nil, otherwise in `load-path'. 384`find-function-source-path', if non nil, otherwise in `load-path'.
@@ -382,9 +403,41 @@ See `find-variable' for more details."
382 (find-function-do-it variable t 'switch-to-buffer-other-frame)) 403 (find-function-do-it variable t 'switch-to-buffer-other-frame))
383 404
384;;;###autoload 405;;;###autoload
406(defun find-definition-noselect (symbol type &optional file)
407 "Return a pair `(BUFFER . POINT)' pointing to the definition of SYMBOL.
408TYPE says what type of definition: nil for a function,
409`defvar' or `defface' for a variable or face. This functoin
410does not switch to the buffer or display it.
411
412The library where SYMBOL is defined is searched for in FILE or
413`find-function-source-path', if non nil, otherwise in `load-path'."
414 (if (not symbol)
415 (error "You didn't specify a symbol"))
416 (if (null type)
417 (find-function-noselect symbol)
418 (let ((library (or file (symbol-file symbol type))))
419 (find-function-search-for-symbol symbol type library))))
420
421;;;###autoload
422(defun find-face (face)
423 "Find the definition of FACE. FACE defaults to the name near point.
424
425Finds the Emacs Lisp library containing the definition of the face
426near point (selected by `variable-at-point') in a buffer and
427places point before the definition.
428
429Set mark before moving, if the buffer already existed.
430
431The library where FACE is defined is searched for in
432`find-function-source-path', if non nil, otherwise in `load-path'.
433See also `find-function-recenter-line' and `find-function-after-hook'."
434 (interactive (find-function-read 'defface))
435 (find-function-do-it face 'defface 'switch-to-buffer))
436
437;;;###autoload
385(defun find-function-on-key (key) 438(defun find-function-on-key (key)
386 "Find the function that KEY invokes. KEY is a string. 439 "Find the function that KEY invokes. KEY is a string.
387Point is saved if FUNCTION is in the current buffer." 440Set mark before moving, if the buffer already existed."
388 (interactive "kFind function on key: ") 441 (interactive "kFind function on key: ")
389 (let (defn) 442 (let (defn)
390 (save-excursion 443 (save-excursion