comparison lisp/prim/help.el @ 195:a2f645c6b9f8 r20-3b24

Import from CVS: tag r20-3b24
author cvs
date Mon, 13 Aug 2007 09:59:05 +0200
parents f53b5ca2e663
children acd284d43ca1
comparison
equal deleted inserted replaced
194:2947057885e5 195:a2f645c6b9f8
65 65
66 (define-key help-map "b" 'describe-bindings) 66 (define-key help-map "b" 'describe-bindings)
67 (define-key help-map "B" 'describe-beta) 67 (define-key help-map "B" 'describe-beta)
68 (define-key help-map "\C-p" 'describe-pointer) 68 (define-key help-map "\C-p" 'describe-pointer)
69 69
70 (define-key help-map "C" 'customize)
70 (define-key help-map "c" 'describe-key-briefly) 71 (define-key help-map "c" 'describe-key-briefly)
71 (define-key help-map "k" 'describe-key) 72 (define-key help-map "k" 'describe-key)
72 73
73 (define-key help-map "d" 'describe-function) 74 (define-key help-map "d" 'describe-function)
74 (define-key help-map "e" 'describe-last-error) 75 (define-key help-map "e" 'describe-last-error)
183 Commands: 184 Commands:
184 \\{help-mode-map}" 185 \\{help-mode-map}"
185 ) 186 )
186 187
187 (define-key help-mode-map "q" 'help-mode-quit) 188 (define-key help-mode-map "q" 'help-mode-quit)
188 (define-key help-mode-map 'delete 'scroll-down) 189 (define-key help-mode-map "f" 'find-function-at-point)
190
191 (defun describe-function-at-point ()
192 "Describe directly the function at point in the other window."
193 (interactive)
194 (let ((symb (function-at-point)))
195 (when symb
196 (describe-function symb))))
197 (defun describe-variable-at-point ()
198 "Describe directly the variable at point in the other window."
199 (interactive)
200 (let ((symb (variable-at-point)))
201 (when symb
202 (describe-variable symb))))
203 (defun help-next-symbol ()
204 "Move point to the next quoted symbol."
205 (interactive)
206 (search-forward "`" nil t))
207 (defun help-prev-symbol ()
208 "Move point to the previous quoted symbol."
209 (interactive)
210 (search-backward "'" nil t))
211 (define-key help-mode-map "d" 'describe-function-at-point)
212 (define-key help-mode-map "v" 'describe-variable-at-point)
213 (define-key help-mode-map [tab] 'help-next-symbol)
214 (define-key help-mode-map [(shift tab)] 'help-prev-symbol)
215
189 216
190 (defun help-mode-quit () 217 (defun help-mode-quit ()
191 "Exits from help mode, possibly restoring the previous window configuration. 218 "Exits from help mode, possibly restoring the previous window configuration.
192 Bury the help buffer to the end of the buffer list." 219 Bury the help buffer to the end of the buffer list."
193 (interactive) 220 (interactive)
779 (defun describe-function-find-file (function) 806 (defun describe-function-find-file (function)
780 (let ((files load-history) 807 (let ((files load-history)
781 file) 808 file)
782 (while files 809 (while files
783 (if (memq function (cdr (car files))) 810 (if (memq function (cdr (car files)))
784 (setq file (car (car files)) files nil)) 811 (setq file (car (car files))
812 files nil))
785 (setq files (cdr files))) 813 (setq files (cdr files)))
786 file)) 814 file))
787 815
788 (defun describe-function (function) 816 (defun describe-function (function)
789 "Display the full documentation of FUNCTION (a symbol)." 817 "Display the full documentation of FUNCTION (a symbol).
818 When run interactively, it defaults to any function found by the
819 value of `find-function-function'."
790 (interactive 820 (interactive
791 (let* ((fn (funcall find-function-function)) 821 (let* ((fn (funcall find-function-function))
792 (val (let ((enable-recursive-minibuffers t)) 822 (val (let ((enable-recursive-minibuffers t))
793 (completing-read 823 (completing-read
794 (if fn 824 (if fn
795 (format (gettext "Describe function (default %s): ") 825 (format (gettext "Describe function (default %s): ")
796 fn) 826 fn)
797 (gettext "Describe function: ")) 827 (gettext "Describe function: "))
798 obarray 'fboundp t)))) 828 obarray 'fboundp t nil 'function-history))))
799 (list (if (equal val "") fn (intern val))))) 829 (list (if (equal val "") fn (intern val)))))
800 (with-displaying-help-buffer 830 (with-displaying-help-buffer
801 (lambda () 831 (lambda ()
802 (describe-function-1 function standard-output) 832 (describe-function-1 function standard-output)
803 (save-excursion 833 (save-excursion
1069 (val (let ((enable-recursive-minibuffers t)) 1099 (val (let ((enable-recursive-minibuffers t))
1070 (completing-read 1100 (completing-read
1071 (if v 1101 (if v
1072 (format "Describe variable (default %s): " v) 1102 (format "Describe variable (default %s): " v)
1073 (gettext "Describe variable: ")) 1103 (gettext "Describe variable: "))
1074 obarray 'boundp t)))) 1104 obarray 'boundp t nil 'variable-history))))
1075 (list (if (equal val "") v (intern val))))) 1105 (list (if (equal val "") v (intern val)))))
1076 (with-displaying-help-buffer 1106 (with-displaying-help-buffer
1077 (lambda () 1107 (lambda ()
1078 (let ((origvar variable) 1108 (let ((origvar variable)
1079 aliases) 1109 aliases)
1159 (< (length x) (length y)))) 1189 (< (length x) (length y))))
1160 (or separator ", "))) 1190 (or separator ", ")))
1161 1191
1162 (defun where-is (definition) 1192 (defun where-is (definition)
1163 "Print message listing key sequences that invoke specified command. 1193 "Print message listing key sequences that invoke specified command.
1164 Argument is a command definition, usually a symbol with a function definition." 1194 Argument is a command definition, usually a symbol with a function definition.
1195 When run interactively, it defaults to any function found by the
1196 value of `find-function-function'."
1165 (interactive 1197 (interactive
1166 (let ((fn (funcall find-function-function)) 1198 (let ((fn (funcall find-function-function))
1167 (enable-recursive-minibuffers t) 1199 (enable-recursive-minibuffers t)
1168 val) 1200 val)
1169 (setq val (read-command 1201 (setq val (read-command
1299 1331
1300 1332
1301 ;; find-function stuff 1333 ;; find-function stuff
1302 1334
1303 (defvar find-function-function 'function-at-point 1335 (defvar find-function-function 'function-at-point
1304 "*The function used by `find-function' to select the function near 1336 "*The function used by `describe-function', `where-is' and
1305 point. 1337 `find-function' to select the function near point.
1306 1338
1307 For example `function-at-point' or `function-called-at-point'.") 1339 For example `function-at-point' or `function-called-at-point'.")
1308 1340
1309 (defvar find-function-source-path nil 1341 (defvar find-function-source-path nil
1310 "The default list of directories where find-function searches. 1342 "The default list of directories where find-function searches.
1311 1343
1312 If this variable is `nil' then find-function searches `load-path' by 1344 If this variable is `nil' then find-function searches `load-path' by
1313 default.") 1345 default.")
1314 1346
1315 1347
1316 (defun find-function-noselect (function &optional path) 1348 (defun find-function-noselect (function)
1317 "Returns list `(buffer point)' pointing to the definition of FUNCTION. 1349 "Returns a pair `(buffer . point)' pointing to the definition of FUNCTION.
1318 1350
1319 Finds the emacs-lisp library containing the definition of FUNCTION 1351 Finds the Emacs Lisp library containing the definition of FUNCTION
1320 in a buffer and places point before the definition. The buffer is 1352 in a buffer and the point of the definition. The buffer is
1321 not selected. 1353 not selected.
1322 1354
1323 If the optional argument PATH is given, the library where FUNCTION is 1355 The library where FUNCTION is defined is searched for in
1324 defined is searched in PATH instead of `load-path' (see 1356 `find-function-source-path', if non `nil', otherwise in `load-path'."
1325 `find-function-source-path')."
1326 (and (subrp (symbol-function function)) 1357 (and (subrp (symbol-function function))
1327 (error "%s is a primitive function" function)) 1358 (error "%s is a primitive function" function))
1328 (if (not function) 1359 (if (not function)
1329 (error "You didn't specify a function")) 1360 (error "You didn't specify a function"))
1330 (let ((def (symbol-function function)) 1361 (let ((def (symbol-function function))
1331 library aliases) 1362 library aliases)
1332 (while (symbolp def) 1363 (while (symbolp def)
1333 (or (eq def function) 1364 (or (eq def function)
1334 (if aliases 1365 (if aliases
1335 (setq aliases (concat aliases 1366 (setq aliases (concat aliases
1336 (format ", which is an alias for %s" 1367 (format ", which is an alias for %s"
1337 (symbol-name def)))) 1368 (symbol-name def))))
1338 (setq aliases (format "an alias for %s" (symbol-name 1369 (setq aliases (format "an alias for %s" (symbol-name
1339 def))))) 1370 def)))))
1340 (setq function (symbol-function function) 1371 (setq function (symbol-function function)
1341 def (symbol-function function))) 1372 def (symbol-function function)))
1342 (if aliases 1373 (if aliases
1343 (message aliases)) 1374 (message aliases))
1344 (setq library 1375 (setq library
1346 (nth 1 def)) 1377 (nth 1 def))
1347 ((describe-function-find-file function)) 1378 ((describe-function-find-file function))
1348 ((compiled-function-p def) 1379 ((compiled-function-p def)
1349 (substring (compiled-function-annotation def) 0 -4)))) 1380 (substring (compiled-function-annotation def) 0 -4))))
1350 (if (null library) 1381 (if (null library)
1351 (error "Can't find library")) 1382 (error (format "Don't know where `%s' is defined" function)))
1352 (if (string-match "\\(\\.elc?\\'\\)" library) 1383 (if (string-match "\\.el\\(c\\)\\'" library)
1353 (setq library (substring library 0 (match-beginning 1)))) 1384 (setq library (substring library 0 (match-beginning 1))))
1354 (let* ((path (or path find-function-source-path)) 1385 (let* ((path (or path find-function-source-path))
1355 (compression (or (rassq 'jka-compr-handler file-name-handler-alist) 1386 (filename (or (locate-library (concat library ".el") t path)
1356 (member 'crypt-find-file-hook find-file-hooks))) 1387 (locate-library library t path))))
1357 (filename (or (locate-library (concat library ".el")
1358 t path)
1359 (locate-library library t path)
1360 (if compression
1361 (or (locate-library (concat library ".el.gz")
1362 t path)
1363 (locate-library (concat library ".gz")
1364 t path))))))
1365 (if (not filename) 1388 (if (not filename)
1366 (error "The library \"%s\" is not in the path." library)) 1389 (error "The library \"%s\" is not in the path." library))
1367 (save-excursion 1390 (with-current-buffer (find-file-noselect filename)
1368 (set-buffer (find-file-noselect filename))
1369 (save-match-data 1391 (save-match-data
1370 (let (;; avoid defconst, defgroup, defvar (any others?) 1392 (let (;; avoid defconst, defgroup, defvar (any others?)
1371 (re (format "^\\s-*(def[^cgv\W]\\w+\\s-+%s\\s-" function)) 1393 (regexp
1394 (format "^\\s-*(def[^cgv\W]\\w+\\*?\\s-+%s\\s-" function))
1372 (syntable (syntax-table))) 1395 (syntable (syntax-table)))
1373 (set-syntax-table emacs-lisp-mode-syntax-table) 1396 (set-syntax-table emacs-lisp-mode-syntax-table)
1374 (goto-char (point-min)) 1397 (goto-char (point-min))
1375 (if (prog1 1398 (if (prog1
1376 (re-search-forward re nil t) 1399 (re-search-forward regexp nil t)
1377 (set-syntax-table syntable)) 1400 (set-syntax-table syntable))
1378 (progn 1401 (progn
1379 (beginning-of-line) 1402 (beginning-of-line)
1380 (list (current-buffer) (point))) 1403 (cons (current-buffer) (point)))
1381 (error "Cannot find definition of %s" function)))))))) 1404 (error "Cannot find definition of `%s'" function))))))))
1382 1405
1383 (defun function-at-point () 1406 (defun function-at-point ()
1384 (or (condition-case () 1407 (or (condition-case ()
1385 (let ((stab (syntax-table))) 1408 (let ((stab (syntax-table)))
1386 (unwind-protect 1409 (unwind-protect
1410 "Read and return a function, defaulting to the one near point. 1433 "Read and return a function, defaulting to the one near point.
1411 1434
1412 The function named by `find-function-function' is used to select the 1435 The function named by `find-function-function' is used to select the
1413 default function." 1436 default function."
1414 (let ((fn (funcall find-function-function)) 1437 (let ((fn (funcall find-function-function))
1415 (enable-recursive-minibuffers t) 1438 (enable-recursive-minibuffers t)
1416 val) 1439 val)
1417 (setq val (completing-read 1440 (setq val (completing-read
1418 (if fn 1441 (if fn
1419 (format "Find function (default %s): " fn) 1442 (format "Find function (default %s): " fn)
1420 "Find function: ") 1443 "Find function: ")
1421 obarray 'fboundp t)) 1444 obarray 'fboundp t nil 'function-history))
1422 (list (if (equal val "") 1445 (list (if (equal val "")
1423 fn (intern val))))) 1446 fn (intern val)))))
1424 1447
1425 1448 (defun find-function-do-it (function switch-fn)
1426 (defun find-function (function &optional path) 1449 "find elisp FUNCTION in a buffer and display it with SWITCH-FN.
1427 "Find the definition of the function near point in the current window. 1450 Point is saved in the buffer if it is one of the current buffers."
1428 1451 (let ((orig-point (point))
1429 Finds the emacs-lisp library containing the definition of the function 1452 (orig-buffers (buffer-list))
1430 near point (selected by `find-function-function') and places point 1453 (buffer-point (find-function-noselect function)))
1431 before the definition.
1432
1433 If the optional argument PATH is given, the library where FUNCTION is
1434 defined is searched in PATH instead of `load-path'"
1435 (interactive (find-function-read-function))
1436 (let ((buffer-point (find-function-noselect function path)))
1437 (if buffer-point 1454 (if buffer-point
1438 (progn 1455 (progn
1439 (switch-to-buffer (car buffer-point)) 1456 (funcall switch-fn (car buffer-point))
1440 (goto-char (cadr buffer-point)) 1457 (if (memq (car buffer-point) orig-buffers)
1458 (push-mark orig-point))
1459 (goto-char (cdr buffer-point))
1441 (recenter 0))))) 1460 (recenter 0)))))
1442 1461
1443 (defun find-function-other-window (function &optional path) 1462 (defun find-function (function)
1463 "Find the definition of the function near point in the current window.
1464
1465 Finds the Emacs Lisp library containing the definition of the function
1466 near point (selected by `find-function-function') in a buffer and
1467 places point before the definition. Point is saved in the buffer if
1468 it is one of the current buffers.
1469
1470 The library where FUNCTION is defined is searched for in
1471 `find-function-source-path', if non `nil', otherwise in `load-path'."
1472 (interactive (find-function-read-function))
1473 (find-function-do-it function 'switch-to-buffer))
1474
1475 (defun find-function-other-window (function)
1444 "Find the definition of the function near point in the other window. 1476 "Find the definition of the function near point in the other window.
1445 1477
1446 Finds the emacs-lisp library containing the definition of the function 1478 Finds the Emacs Lisp library containing the definition of the function
1447 near point (selected by `find-function-function') and places point 1479 near point (selected by `find-function-function') in a buffer and
1448 before the definition. 1480 places point before the definition. Point is saved in the buffer if
1449 1481 it is one of the current buffers.
1450 If the optional argument PATH is given, the library where FUNCTION is 1482
1451 defined is searched in PATH instead of `load-path'" 1483 The library where FUNCTION is defined is searched for in
1484 `find-function-source-path', if non `nil', otherwise in `load-path'."
1452 (interactive (find-function-read-function)) 1485 (interactive (find-function-read-function))
1453 (let ((buffer-point (find-function-noselect function path))) 1486 (find-function-do-it function 'switch-to-buffer-other-window))
1454 (if buffer-point 1487
1455 (progn 1488 (defun find-function-other-frame (function)
1456 (switch-to-buffer-other-window (car buffer-point))
1457 (goto-char (cadr buffer-point))
1458 (recenter 0)))))
1459
1460 (defun find-function-other-frame (function &optional path)
1461 "Find the definition of the function near point in the another frame. 1489 "Find the definition of the function near point in the another frame.
1462 1490
1463 Finds the emacs-lisp library containing the definition of the function 1491 Finds the Emacs Lisp library containing the definition of the function
1464 near point (selected by `find-function-function') and places point 1492 near point (selected by `find-function-function') in a buffer and
1465 before the definition. 1493 places point before the definition. Point is saved in the buffer if
1466 1494 it is one of the current buffers.
1467 If the optional argument PATH is given, the library where FUNCTION is 1495
1468 defined is searched in PATH instead of `load-path'" 1496 The library where FUNCTION is defined is searched for in
1497 `find-function-source-path', if non `nil', otherwise in `load-path'."
1469 (interactive (find-function-read-function)) 1498 (interactive (find-function-read-function))
1470 (let ((buffer-point (find-function-noselect function path))) 1499 (find-function-do-it function 'switch-to-buffer-other-frame))
1471 (if buffer-point
1472 (progn
1473 (switch-to-buffer-other-frame (car buffer-point))
1474 (goto-char (cadr buffer-point))
1475 (recenter 0)))))
1476 1500
1477 (defun find-function-on-key (key) 1501 (defun find-function-on-key (key)
1478 "Find the function that KEY invokes. KEY is a string." 1502 "Find the function that KEY invokes. KEY is a string.
1503 Point is saved if FUNCTION is in the current buffer."
1479 (interactive "kFind function on key: ") 1504 (interactive "kFind function on key: ")
1480 (let ((defn (key-or-menu-binding key))) 1505 (let ((defn (key-or-menu-binding key)))
1481 (if (or (null defn) (integerp defn)) 1506 (if (or (null defn) (integerp defn))
1482 (message "%s is undefined" (key-description key)) 1507 (message "%s is undefined" (key-description key))
1483 (if (and (consp defn) (not (eq 'lambda (car-safe defn)))) 1508 (if (and (consp defn) (not (eq 'lambda (car-safe defn))))
1484 (message "runs %s" (prin1-to-string defn)) 1509 (message "runs %s" (prin1-to-string defn))
1485 (find-function-other-window defn))))) 1510 (find-function-other-window defn)))))
1486 1511
1512 (defun find-function-at-point ()
1513 "Find directly the function at point in the other window."
1514 (interactive)
1515 (let ((symb (function-at-point)))
1516 (when symb
1517 (find-function-other-window symb))))
1518
1487 (define-key ctl-x-map "F" 'find-function) 1519 (define-key ctl-x-map "F" 'find-function)
1488 (define-key ctl-x-4-map "F" 'find-function-other-window) 1520 (define-key ctl-x-4-map "F" 'find-function-other-window)
1489 (define-key ctl-x-5-map "F" 'find-function-other-frame) 1521 (define-key ctl-x-5-map "F" 'find-function-other-frame)
1490 1522
1491 ;;; help.el ends here 1523 ;;; help.el ends here