Mercurial > hg > xemacs-beta
comparison lisp/apropos.el @ 280:7df0dd720c89 r21-0b38
Import from CVS: tag r21-0b38
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:32:22 +0200 |
parents | c5d627a313b1 |
children | 558f606b08ae |
comparison
equal
deleted
inserted
replaced
279:c20b2fb5bb0a | 280:7df0dd720c89 |
---|---|
2 | 2 |
3 ;; Copyright (C) 1989, 1994, 1995 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1989, 1994, 1995 Free Software Foundation, Inc. |
4 | 4 |
5 ;; Author: Joe Wells <jbw@bigbird.bu.edu> | 5 ;; Author: Joe Wells <jbw@bigbird.bu.edu> |
6 ;; Rewritten: Daniel.Pfeiffer@Informatik.START.dbp.de, fax (+49 69) 7588-2389 | 6 ;; Rewritten: Daniel.Pfeiffer@Informatik.START.dbp.de, fax (+49 69) 7588-2389 |
7 ;; Maintainer: SL Baur <steve@altair.xemacs.org> | |
7 ;; Keywords: help | 8 ;; Keywords: help |
8 | 9 |
9 ;; This file is part of XEmacs. | 10 ;; This file is part of XEmacs. |
10 | 11 |
11 ;; XEmacs is free software; you can redistribute it and/or modify it | 12 ;; XEmacs is free software; you can redistribute it and/or modify it |
21 ;; You should have received a copy of the GNU General Public License | 22 ;; You should have received a copy of the GNU General Public License |
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the | 23 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
24 ;; Boston, MA 02111-1307, USA. | 25 ;; Boston, MA 02111-1307, USA. |
25 | 26 |
26 ;;; Synched up with: FSF 19.34. | 27 ;;; Synched up with: Last synched with FSF 19.34, diverged since. |
27 | 28 |
28 ;;; Commentary: | 29 ;;; Commentary: |
29 | 30 |
30 ;; The ideas for this package were derived from the C code in | 31 ;; The ideas for this package were derived from the C code in |
31 ;; src/keymap.c and elsewhere. The functions in this file should | 32 ;; src/keymap.c and elsewhere. The functions in this file should |
33 ;; C (as part of src/keymap.c) for speed. | 34 ;; C (as part of src/keymap.c) for speed. |
34 | 35 |
35 ;; The idea for super-apropos is based on the original implementation | 36 ;; The idea for super-apropos is based on the original implementation |
36 ;; by Lynn Slater <lrs@esl.com>. | 37 ;; by Lynn Slater <lrs@esl.com>. |
37 | 38 |
38 ;; History: | 39 ;;; ChangeLog: |
40 | |
39 ;; Fixed bug, current-local-map can return nil. | 41 ;; Fixed bug, current-local-map can return nil. |
40 ;; Change, doesn't calculate key-bindings unless needed. | 42 ;; Change, doesn't calculate key-bindings unless needed. |
41 ;; Added super-apropos capability, changed print functions. | 43 ;; Added super-apropos capability, changed print functions. |
42 ;;; Made fast-apropos and super-apropos share code. | 44 ;;; Made fast-apropos and super-apropos share code. |
43 ;;; Sped up fast-apropos again. | 45 ;;; Sped up fast-apropos again. |
138 | 140 |
139 | 141 |
140 ;; For auld lang syne: | 142 ;; For auld lang syne: |
141 ;;;###autoload | 143 ;;;###autoload |
142 (fset 'command-apropos 'apropos-command) | 144 (fset 'command-apropos 'apropos-command) |
145 | |
143 ;;;###autoload | 146 ;;;###autoload |
144 (defun apropos-command (apropos-regexp &optional do-all) | 147 (defun apropos-command (apropos-regexp &optional do-all) |
145 "Shows commands (interactively callable functions) that match REGEXP. | 148 "Shows commands (interactively callable functions) that match REGEXP. |
146 With optional prefix ARG or if `apropos-do-all' is non-nil, also show | 149 With optional prefix ARG or if `apropos-do-all' is non-nil, also show |
147 variables." | 150 variables." |
151 ;; XEmacs: All code related to special treatment of buffer has been removed | |
148 (interactive (list (read-string (concat "Apropos command " | 152 (interactive (list (read-string (concat "Apropos command " |
149 (if (or current-prefix-arg | 153 (if (or current-prefix-arg |
150 apropos-do-all) | 154 apropos-do-all) |
151 "or variable ") | 155 "or variable ") |
152 "(regexp): ")) | 156 "(regexp): ")) |
153 current-prefix-arg)) | 157 current-prefix-arg)) |
154 (let ((message | 158 (or do-all (setq do-all apropos-do-all)) |
155 (let ((standard-output (get-buffer-create "*Apropos*"))) | 159 (setq apropos-accumulator |
156 (print-help-return-message 'identity)))) | 160 (apropos-internal apropos-regexp |
157 (or do-all (setq do-all apropos-do-all)) | 161 (if do-all |
158 (setq apropos-accumulator | 162 (lambda (symbol) (or (commandp symbol) |
159 (apropos-internal apropos-regexp | 163 (user-variable-p symbol))) |
160 (if do-all | 164 'commandp))) |
161 (lambda (symbol) (or (commandp symbol) | 165 (apropos-print |
162 (user-variable-p symbol))) | 166 t |
163 'commandp))) | 167 (lambda (p) |
164 (if (apropos-print | 168 (let (doc symbol) |
165 t | 169 (while p |
166 (lambda (p) | 170 (setcar p (list |
167 (let (doc symbol) | 171 (setq symbol (car p)) |
168 (while p | 172 (if (commandp symbol) |
169 (setcar p (list | 173 (if (setq doc |
170 (setq symbol (car p)) | 174 ;; XEmacs change: if obsolete, |
171 (if (commandp symbol) | 175 ;; only mention that. |
172 (if (setq doc | 176 (or (function-obsoleteness-doc symbol) |
173 ;; XEmacs change: if obsolete, | 177 (documentation symbol t))) |
174 ;; only mention that. | 178 (substring doc 0 (string-match "\n" doc)) |
175 (or (function-obsoleteness-doc symbol) | 179 "(not documented)")) |
176 (documentation symbol t))) | 180 (and do-all |
177 (substring doc 0 (string-match "\n" doc)) | 181 (user-variable-p symbol) |
178 "(not documented)")) | 182 (if (setq doc |
179 (and do-all | 183 (or |
180 (user-variable-p symbol) | 184 ;; XEmacs change: if obsolete, |
181 (if (setq doc | 185 ;; only mention that. |
182 (or | 186 (variable-obsoleteness-doc symbol) |
183 ;; XEmacs change: if obsolete, | 187 (documentation-property |
184 ;; only mention that. | 188 symbol 'variable-documentation t))) |
185 (variable-obsoleteness-doc symbol) | 189 (substring doc 0 |
186 (documentation-property | 190 (string-match "\n" doc)))))) |
187 symbol 'variable-documentation t))) | 191 (setq p (cdr p))))) |
188 (substring doc 0 | 192 nil)) |
189 (string-match "\n" doc)))))) | |
190 (setq p (cdr p))))) | |
191 nil) | |
192 (and message (message message))))) | |
193 | 193 |
194 | 194 |
195 ;;;###autoload | 195 ;;;###autoload |
196 (defun apropos (apropos-regexp &optional do-all) | 196 (defun apropos (apropos-regexp &optional do-all) |
197 "Show all bound symbols whose names match REGEXP. | 197 "Show all bound symbols whose names match REGEXP. |
375 | 375 |
376 ;; Finds all documentation related to APROPOS-REGEXP in internal-doc-file-name. | 376 ;; Finds all documentation related to APROPOS-REGEXP in internal-doc-file-name. |
377 | 377 |
378 (defun apropos-documentation-check-doc-file () | 378 (defun apropos-documentation-check-doc-file () |
379 (let (type symbol (sepa 2) sepb beg end) | 379 (let (type symbol (sepa 2) sepb beg end) |
380 (insert ?\^_) | 380 (princ ?\^_) |
381 (backward-char) | 381 (backward-char) |
382 (insert-file-contents (concat doc-directory internal-doc-file-name)) | 382 (insert-file-contents (concat doc-directory internal-doc-file-name)) |
383 (forward-char) | 383 (forward-char) |
384 (while (save-excursion | 384 (while (save-excursion |
385 (setq sepb (search-forward "\^_")) | 385 (setq sepb (search-forward "\^_")) |
498 (and apropos-label-face | 498 (and apropos-label-face |
499 (or (symbolp apropos-label-face) | 499 (or (symbolp apropos-label-face) |
500 (facep apropos-label-face)) ; XEmacs | 500 (facep apropos-label-face)) ; XEmacs |
501 (setq apropos-label-face `(face ,apropos-label-face | 501 (setq apropos-label-face `(face ,apropos-label-face |
502 mouse-face highlight))) | 502 mouse-face highlight))) |
503 (with-output-to-temp-buffer "*Apropos*" | 503 (let ((help-buffer-prefix-string "Apropos")) |
504 (let ((p apropos-accumulator) | 504 (with-displaying-help-buffer apropos-regexp |
505 (old-buffer (current-buffer)) | 505 (with-current-buffer standard-output |
506 symbol item point1 point2) | 506 (run-hooks 'apropos-mode-hook) |
507 (set-buffer standard-output) | 507 (let ((p apropos-accumulator) |
508 (apropos-mode) | 508 (old-buffer (current-buffer)) |
509 ;; XEmacs change from (if window-system | 509 symbol item point1 point2) |
510 (if (device-on-window-system-p) | 510 ;; XEmacs change from (if window-system |
511 (insert "If you move the mouse over text that changes color,\n" | 511 (if (device-on-window-system-p) |
512 (substitute-command-keys | 512 (progn |
513 "you can click \\[apropos-mouse-follow] to get more information.\n"))) | 513 (princ "If you move the mouse over text that changes color,\n") |
514 (insert (substitute-command-keys | 514 (princ (substitute-command-keys |
515 "Type \\[apropos-follow] in this buffer to get full documentation.\n\n")) | 515 "you can click \\[apropos-mouse-follow] to get more information.\n")))) |
516 (while (consp p) | 516 (princ (substitute-command-keys |
517 (or (not spacing) (bobp) (terpri)) | 517 "Type \\[apropos-follow] in this buffer to get full documentation.\n\n")) |
518 (setq apropos-item (car p) | 518 (while (consp p) |
519 symbol (car apropos-item) | 519 (or (not spacing) (bobp) (terpri)) |
520 p (cdr p) | 520 (setq apropos-item (car p) |
521 point1 (point)) | 521 symbol (car apropos-item) |
522 (princ symbol) ; print symbol name | 522 p (cdr p) |
523 (setq point2 (point)) | 523 point1 (point)) |
524 ;; Calculate key-bindings if we want them. | 524 (princ symbol) ; print symbol name |
525 (and do-keys | 525 (setq point2 (point)) |
526 (commandp symbol) | 526 ;; Calculate key-bindings if we want them. |
527 (indent-to 30 1) | 527 (and do-keys |
528 (if (let ((keys | 528 (commandp symbol) |
529 (save-excursion | 529 (indent-to 30 1) |
530 (set-buffer old-buffer) | 530 (if (let ((keys |
531 (where-is-internal symbol))) | 531 (save-excursion |
532 filtered) | 532 (set-buffer old-buffer) |
533 ;; Copy over the list of key sequences, | 533 (where-is-internal symbol))) |
534 ;; omitting any that contain a buffer or a frame. | 534 filtered) |
535 (while keys | 535 ;; Copy over the list of key sequences, |
536 (let ((key (car keys)) | 536 ;; omitting any that contain a buffer or a frame. |
537 (i 0) | 537 (while keys |
538 loser) | 538 (let ((key (car keys)) |
539 (while (< i (length key)) | 539 (i 0) |
540 (if (or (framep (aref key i)) | 540 loser) |
541 (bufferp (aref key i))) | 541 (while (< i (length key)) |
542 (setq loser t)) | 542 (if (or (framep (aref key i)) |
543 (setq i (1+ i))) | 543 (bufferp (aref key i))) |
544 (or loser | 544 (setq loser t)) |
545 (setq filtered (cons key filtered)))) | 545 (setq i (1+ i))) |
546 (setq keys (cdr keys))) | 546 (or loser |
547 (setq item filtered)) | 547 (setq filtered (cons key filtered)))) |
548 ;; Convert the remaining keys to a string and insert. | 548 (setq keys (cdr keys))) |
549 (insert | 549 (setq item filtered)) |
550 (mapconcat | 550 ;; Convert the remaining keys to a string and insert. |
551 (lambda (key) | 551 (princ |
552 (setq key (key-description key)) | 552 (mapconcat |
553 (if apropos-keybinding-face | 553 (lambda (key) |
554 (put-text-property 0 (length key) | 554 (setq key (key-description key)) |
555 'face apropos-keybinding-face | 555 (if apropos-keybinding-face |
556 key)) | 556 (put-text-property 0 (length key) |
557 key) | 557 'face apropos-keybinding-face |
558 item ", ")) | 558 key)) |
559 (insert "Type ") | 559 key) |
560 (insert "M-x") | 560 item ", ")) |
561 (put-text-property (- (point) 3) (point) | 561 (princ "Type ") |
562 'face apropos-keybinding-face) | 562 (princ "M-x") |
563 (insert " " (symbol-name symbol) " ") | 563 (put-text-property (- (point) 3) (point) |
564 (insert "RET") | 564 'face apropos-keybinding-face) |
565 (put-text-property (- (point) 3) (point) | 565 (princ (format " %s " (symbol-name symbol))) |
566 'face apropos-keybinding-face))) | 566 (princ "RET") |
567 (terpri) | 567 (put-text-property (- (point) 3) (point) |
568 ;; only now so we don't propagate text attributes all over | 568 'face apropos-keybinding-face))) |
569 (put-text-property point1 point2 'item | 569 (terpri) |
570 (if (eval `(or ,@(cdr apropos-item))) | 570 ;; only now so we don't propagate text attributes all over |
571 (car apropos-item) | 571 (put-text-property point1 point2 'item |
572 apropos-item)) | 572 (if (eval `(or ,@(cdr apropos-item))) |
573 (if apropos-symbol-face | 573 (car apropos-item) |
574 (put-text-property point1 point2 'face apropos-symbol-face)) | 574 apropos-item)) |
575 (apropos-print-doc 'describe-function 1 | 575 (if apropos-symbol-face |
576 (if (commandp symbol) | 576 (put-text-property point1 point2 'face apropos-symbol-face)) |
577 "Command" | 577 (apropos-print-doc 'describe-function 1 |
578 (if (apropos-macrop symbol) | 578 (if (commandp symbol) |
579 "Macro" | 579 "Command" |
580 "Function")) | 580 (if (apropos-macrop symbol) |
581 do-keys) | 581 "Macro" |
582 (if (get symbol 'custom-type) | 582 "Function")) |
583 (apropos-print-doc 'customize-variable-other-window 2 | 583 do-keys) |
584 "User Option" do-keys) | 584 (if (get symbol 'custom-type) |
585 (apropos-print-doc 'describe-variable 2 | 585 (apropos-print-doc 'customize-variable-other-window 2 |
586 "Variable" do-keys)) | 586 "User Option" do-keys) |
587 (apropos-print-doc 'customize-other-window 6 "Group" do-keys) | 587 (apropos-print-doc 'describe-variable 2 |
588 (apropos-print-doc 'customize-face-other-window 5 "Face" do-keys) | 588 "Variable" do-keys)) |
589 (apropos-print-doc 'widget-browse-other-window 4 "Widget" do-keys) | 589 (apropos-print-doc 'customize-other-window 6 "Group" do-keys) |
590 (apropos-print-doc 'apropos-describe-plist 3 | 590 (apropos-print-doc 'customize-face-other-window 5 "Face" do-keys) |
591 "Plist" nil))))) | 591 (apropos-print-doc 'widget-browse-other-window 4 "Widget" do-keys) |
592 (prog1 apropos-accumulator | 592 (apropos-print-doc 'apropos-describe-plist 3 |
593 (setq apropos-accumulator ()))) ; permit gc | 593 "Plist" nil)))))) |
594 (prog1 apropos-accumulator | |
595 (setq apropos-accumulator ())))) ; permit gc | |
594 | 596 |
595 | 597 |
596 (defun apropos-macrop (symbol) | 598 (defun apropos-macrop (symbol) |
597 "Return t if SYMBOL is a Lisp macro." | 599 "Return t if SYMBOL is a Lisp macro." |
598 (and (fboundp symbol) | 600 (and (fboundp symbol) |
603 (memq (nth 4 symbol) | 605 (memq (nth 4 symbol) |
604 '(macro t)))))) | 606 '(macro t)))))) |
605 | 607 |
606 | 608 |
607 (defun apropos-print-doc (action i str do-keys) | 609 (defun apropos-print-doc (action i str do-keys) |
608 (if (stringp (setq i (nth i apropos-item))) | 610 (with-current-buffer standard-output |
609 (progn | 611 (if (stringp (setq i (nth i apropos-item))) |
610 (insert " ") | 612 (progn |
611 (put-text-property (- (point) 2) (1- (point)) | 613 (insert " ") |
612 'action action) | 614 (put-text-property (- (point) 2) (1- (point)) |
613 (insert str ": ") | 615 'action action) |
614 (if apropos-label-face | 616 (insert str ": ") |
615 (add-text-properties (- (point) (length str) 2) | 617 (if apropos-label-face |
616 (1- (point)) | 618 (add-text-properties (- (point) (length str) 2) |
617 apropos-label-face)) | 619 (1- (point)) |
618 (insert (if do-keys (substitute-command-keys i) i)) | 620 apropos-label-face)) |
619 (or (bolp) (terpri))))) | 621 (add-text-properties (- (point) (length str) 2) |
622 (1- (point)) | |
623 (list 'keymap apropos-mode-map)) | |
624 (insert (if do-keys (substitute-command-keys i) i)) | |
625 (or (bolp) (terpri)))))) | |
620 | 626 |
621 (defun apropos-mouse-follow (event) | 627 (defun apropos-mouse-follow (event) |
622 (interactive "e") | 628 (interactive "e") |
623 (let ((other (if (eq (current-buffer) (get-buffer "*Apropos*")) | 629 ;; XEmacs change: We're using the standard help buffer code now, don't |
624 () | 630 ;; do special tricks about trying to preserve current-buffer about mouse |
625 (current-buffer)))) | 631 ;; clicks. |
626 (save-excursion | 632 |
627 ;; XEmacs change from: | 633 (save-excursion |
628 ;; (set-buffer (window-buffer (posn-window (event-start event)))) | 634 ;; XEmacs change from: |
629 ;; (goto-char (posn-point (event-start event))) | 635 ;; (set-buffer (window-buffer (posn-window (event-start event)))) |
630 (set-buffer (event-buffer event)) | 636 ;; (goto-char (posn-point (event-start event))) |
631 (goto-char (event-closest-point event)) | 637 (set-buffer (event-buffer event)) |
632 ;; XEmacs change: following code seems useless | 638 (goto-char (event-closest-point event)) |
633 ;;(or (and (not (eobp)) (get-text-property (point) 'mouse-face)) | 639 ;; XEmacs change: following code seems useless |
634 ;; (and (not (bobp)) (get-text-property (1- (point)) 'mouse-face)) | 640 ;;(or (and (not (eobp)) (get-text-property (point) 'mouse-face)) |
635 ;; (error "There is nothing to follow here")) | 641 ;; (and (not (bobp)) (get-text-property (1- (point)) 'mouse-face)) |
636 (apropos-follow other)))) | 642 ;; (error "There is nothing to follow here")) |
643 (apropos-follow))) | |
637 | 644 |
638 | 645 |
639 (defun apropos-follow (&optional other) | 646 (defun apropos-follow (&optional other) |
640 (interactive) | 647 (interactive) |
641 (let* (;; Properties are always found at the beginning of the line. | 648 (let* (;; Properties are always found at the beginning of the line. |
658 | 665 |
659 | 666 |
660 | 667 |
661 (defun apropos-describe-plist (symbol) | 668 (defun apropos-describe-plist (symbol) |
662 "Display a pretty listing of SYMBOL's plist." | 669 "Display a pretty listing of SYMBOL's plist." |
663 (with-output-to-temp-buffer "*Help*" | 670 (let ((help-buffer-prefix-string "Apropos-plist")) |
664 (set-buffer standard-output) | 671 (with-displaying-help-buffer (symbol-name symbol) |
665 (princ "Symbol ") | 672 (run-hooks 'apropos-mode-hook) |
666 (prin1 symbol) | 673 (princ "Symbol ") |
667 (princ "'s plist is\n (") | 674 (prin1 symbol) |
668 (if apropos-symbol-face | 675 (princ "'s plist is\n (") |
669 (put-text-property 8 (- (point) 14) 'face apropos-symbol-face)) | 676 (with-current-buffer standard-output |
670 (insert (apropos-format-plist symbol "\n ")) | 677 (if apropos-symbol-face |
671 (princ ")") | 678 (put-text-property 8 (- (point) 14) 'face apropos-symbol-face))) |
672 (print-help-return-message))) | 679 (princ (apropos-format-plist symbol "\n ")) |
680 (princ ")") | |
681 (terpri) | |
682 (print-help-return-message)))) | |
673 | 683 |
674 (provide 'apropos) ; XEmacs | 684 (provide 'apropos) ; XEmacs |
675 | 685 |
676 ;;; apropos.el ends here | 686 ;;; apropos.el ends here |