Mercurial > hg > xemacs-beta
comparison lisp/prim/help.el @ 179:9ad43877534d r20-3b16
Import from CVS: tag r20-3b16
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:52:19 +0200 |
parents | 6075d714658b |
children | e121b013d1f0 |
comparison
equal
deleted
inserted
replaced
178:e703507b8a00 | 179:9ad43877534d |
---|---|
1290 (while cmd | 1290 (while cmd |
1291 (princ (car cmd) stream) | 1291 (princ (car cmd) stream) |
1292 (setq cmd (cdr cmd)) | 1292 (setq cmd (cdr cmd)) |
1293 (if cmd (princ " " stream))))) | 1293 (if cmd (princ " " stream))))) |
1294 (terpri stream))))))) | 1294 (terpri stream))))))) |
1295 | |
1296 (defvar find-function-function 'ff-function-at-point | |
1297 "The function used by `find-function' to select the function near | |
1298 point. | |
1299 | |
1300 For example `ff-function-at-point' or `function-called-at-point'.") | |
1301 | |
1302 (defvar find-function-source-path nil | |
1303 "The default list of directories where find-function searches. | |
1304 | |
1305 If this variable is `nil' then find-function searches `load-path' by | |
1306 default.") | |
1307 | |
1308 ;;; Code: | |
1309 | |
1310 (defun find-function-noselect (function &optional path) | |
1311 "Put point at the definition of the function at point and return the buffer. | |
1312 | |
1313 Finds the emacs-lisp package containing the definition of FUNCTION | |
1314 into a buffer and place point before the definition. The buffer is | |
1315 not selected. | |
1316 | |
1317 If the optional argument PATH is given, the package where FUNCTION is | |
1318 defined is searched in PATH instead of `load-path' (see | |
1319 `find-function-source-path')." | |
1320 (and (subrp (symbol-function function)) | |
1321 (error "%s is a primitive function" function)) | |
1322 (if (not function) | |
1323 (error "You didn't specify a function")) | |
1324 (let ((def (symbol-function function)) | |
1325 package aliases) | |
1326 (while (symbolp def) | |
1327 (or (eq def function) | |
1328 (if aliases | |
1329 (setq aliases (concat aliases | |
1330 (format ", which is an alias for %s" | |
1331 (symbol-name def)))) | |
1332 (setq aliases (format "an alias for %s" (symbol-name | |
1333 def))))) | |
1334 (setq function (symbol-function function) | |
1335 def (symbol-function function))) | |
1336 (if aliases | |
1337 (message aliases)) | |
1338 (setq package | |
1339 (cond ((eq (car-safe def) 'autoload) | |
1340 (nth 1 def)) | |
1341 ((describe-function-find-file function)) | |
1342 ((and (compiled-function-p def) | |
1343 (fboundp 'compiled-function-annotation)) | |
1344 (substring (compiled-function-annotation def) 0 -4)))) | |
1345 (if (null package) | |
1346 (error "Can't find package")) | |
1347 (if (string-match "\\(\\.elc?\\'\\)" package) | |
1348 (setq package (substring package 0 (match-beginning 1)))) | |
1349 (setq package (concat package ".el")) | |
1350 (let ((filename (locate-library package t | |
1351 (if path | |
1352 path | |
1353 find-function-source-path))) | |
1354 (calling-buffer (current-buffer))) | |
1355 (if (not filename) | |
1356 (error "The package \"%s\" is not in the path." package)) | |
1357 (set-buffer (find-file-noselect filename)) | |
1358 (save-match-data | |
1359 (let ((p (point)) | |
1360 ;; avoid defconst, defgroup, defvar (any others?) | |
1361 (re (format "^(def[^cgv\W]\\w+\\s-+%s\\s-" function)) | |
1362 (syntable (syntax-table))) | |
1363 (set-syntax-table emacs-lisp-mode-syntax-table) | |
1364 (goto-char (point-min)) | |
1365 (if (prog1 | |
1366 (re-search-forward re nil t) | |
1367 (set-syntax-table syntable)) | |
1368 (prog2 | |
1369 (beginning-of-line) | |
1370 (current-buffer) | |
1371 (set-buffer calling-buffer)) | |
1372 (goto-char p) | |
1373 (set-buffer calling-buffer) | |
1374 (error "Cannot find definition of %s" function))))))) | |
1375 | |
1376 (defun ff-function-at-point () | |
1377 (condition-case () | |
1378 (let ((stab (syntax-table))) | |
1379 (unwind-protect | |
1380 (save-excursion | |
1381 (set-syntax-table emacs-lisp-mode-syntax-table) | |
1382 (or (not (zerop (skip-syntax-backward "_w"))) | |
1383 (eq (char-syntax (char-after (point))) ?w) | |
1384 (eq (char-syntax (char-after (point))) ?_) | |
1385 (forward-sexp -1)) | |
1386 (skip-chars-forward "'") | |
1387 (let ((obj (read (current-buffer)))) | |
1388 (and (symbolp obj) (fboundp obj) obj))) | |
1389 (set-syntax-table stab))) | |
1390 (error nil))) | |
1391 | |
1392 (defun ff-read-function () | |
1393 "Read and return a function, defaulting to the one near point. | |
1394 | |
1395 The function named by `find-function-function' is used to select the | |
1396 default function." | |
1397 (let ((fn (funcall find-function-function)) | |
1398 (enable-recursive-minibuffers t) | |
1399 val) | |
1400 (setq val (completing-read | |
1401 (if fn | |
1402 (format "Find function (default %s): " fn) | |
1403 "Find function: ") | |
1404 obarray 'fboundp t)) | |
1405 (list (if (equal val "") | |
1406 fn (intern val))))) | |
1407 | |
1408 | |
1409 (defun find-function (function &optional path) | |
1410 "Find the definition of the function near point in the current window. | |
1411 | |
1412 Finds the emacs-lisp package containing the definition of the function | |
1413 near point (selected by `find-function-function') and places point | |
1414 before the definition. | |
1415 | |
1416 If the optional argument PATH is given, the package where FUNCTION is | |
1417 defined is searched in PATH instead of `load-path'" | |
1418 (interactive (ff-read-function)) | |
1419 (switch-to-buffer | |
1420 (find-function-noselect function path))) | |
1421 | |
1422 (defun find-function-other-window (function &optional path) | |
1423 "Find the definition of the function near point in the other window. | |
1424 | |
1425 Finds the emacs-lisp package containing the definition of the function | |
1426 near point (selected by `find-function-function') and places point | |
1427 before the definition. | |
1428 | |
1429 If the optional argument PATH is given, the package where FUNCTION is | |
1430 defined is searched in PATH instead of `load-path'" | |
1431 (interactive (ff-read-function)) | |
1432 (switch-to-buffer-other-window | |
1433 (find-function-noselect function path))) | |
1434 | |
1435 (defun find-function-other-frame (function &optional path) | |
1436 "Find the definition of the function near point in the another frame. | |
1437 | |
1438 Finds the emacs-lisp package containing the definition of the function | |
1439 near point (selected by `find-function-function') and places point | |
1440 before the definition. | |
1441 | |
1442 If the optional argument PATH is given, the package where FUNCTION is | |
1443 defined is searched in PATH instead of `load-path'" | |
1444 (interactive (ff-read-function)) | |
1445 (switch-to-buffer-other-frame | |
1446 (find-function-noselect function path))) | |
1447 | |
1448 (define-key mode-specific-map "f" 'find-function) | |
1449 (define-key ctl-x-4-map "F" 'find-function-other-window) | |
1450 (define-key ctl-x-5-map "F" 'find-function-other-frame) | |
1451 | |
1452 ;;; help.el ends here |