aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiles Bader2001-10-07 11:35:09 +0000
committerMiles Bader2001-10-07 11:35:09 +0000
commite517f56d879e28ff75784bff91e52c5a4b799a2b (patch)
treedaf5701e233b056cc72ae2834319de26d0b4d6df
parentaae5b722423e09998ff42e683988d660cecfec58 (diff)
downloademacs-e517f56d879e28ff75784bff91e52c5a4b799a2b.tar.gz
emacs-e517f56d879e28ff75784bff91e52c5a4b799a2b.zip
(apropos-symbol, apropos-label): New button types.
(apropos-symbol-button-display-help) (apropos-label-button-display-help, apropos-next-label-button): New functions. (apropos-mode-map): Make button-buffer-map our parent. Don't bind mouse events. (apropos-print, apropos-print-doc): Create buttons instead of text properties. (apropos-mouse-follow): Function removed. (apropos-follow): Use buttons.
-rw-r--r--lisp/apropos.el135
1 files changed, 73 insertions, 62 deletions
diff --git a/lisp/apropos.el b/lisp/apropos.el
index 0743b9da82a..9b44c56564b 100644
--- a/lisp/apropos.el
+++ b/lisp/apropos.el
@@ -1,6 +1,6 @@
1;;; apropos.el --- apropos commands for users and programmers 1;;; apropos.el --- apropos commands for users and programmers
2 2
3;; Copyright (C) 1989, 1994, 1995 Free Software Foundation, Inc. 3;; Copyright (C) 1989, 1994, 1995, 2001 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 <occitan@esperanto.org> 6;; Rewritten: Daniel Pfeiffer <occitan@esperanto.org>
@@ -103,12 +103,14 @@ for the regexp; the part that matches gets displayed in this font."
103 103
104(defvar apropos-mode-map 104(defvar apropos-mode-map
105 (let ((map (make-sparse-keymap))) 105 (let ((map (make-sparse-keymap)))
106 (set-keymap-parent map button-buffer-map)
107 ;; Use `apropos-follow' instead of just using the button
108 ;; definition of RET, so that users can use it anywhere in an
109 ;; apropos item, not just on top of a button.
106 (define-key map "\C-m" 'apropos-follow) 110 (define-key map "\C-m" 'apropos-follow)
107 (define-key map " " 'scroll-up) 111 (define-key map " " 'scroll-up)
108 (define-key map "\177" 'scroll-down) 112 (define-key map "\177" 'scroll-down)
109 (define-key map "q" 'quit-window) 113 (define-key map "q" 'quit-window)
110 (define-key map [mouse-2] 'apropos-mouse-follow)
111 (define-key map [down-mouse-2] nil)
112 map) 114 map)
113 "Keymap used in Apropos mode.") 115 "Keymap used in Apropos mode.")
114 116
@@ -126,6 +128,49 @@ for the regexp; the part that matches gets displayed in this font."
126 128
127(defvar apropos-item () 129(defvar apropos-item ()
128 "Current item in or for `apropos-accumulator'.") 130 "Current item in or for `apropos-accumulator'.")
131
132
133;;; Button types used by apropos
134
135(define-button-type 'apropos-symbol
136 'face apropos-symbol-face
137 'help-echo "mouse-2, RET: Display more help on this symbol."
138 'action #'apropos-symbol-button-display-help)
139
140(define-button-type 'apropos-label
141 'help-echo "mouse-2, RET: Display more help on this symbol."
142 'action #'apropos-label-button-display-help)
143
144(defun apropos-symbol-button-display-help (button)
145 "Display further help for the `apropos-symbol' button BUTTON."
146 (button-activate
147 (or (apropos-next-label-button (button-start button))
148 (error "There is nothing to follow for `%s'" (button-label button)))))
149
150(defun apropos-label-button-display-help (button)
151 "Display further help for the `apropos-label' button BUTTON."
152 (funcall (button-get button 'apropos-action)
153 (button-get button 'apropos-symbol)))
154
155(defun apropos-next-label-button (pos)
156 "Returns the next `apropos-label' button after POS, or nil if there's none.
157Will also return nil if more than one `apropos-symbol' button is encountered
158before finding a label."
159 (let* ((button (next-button pos 1 nil t))
160 (already-hit-symbol nil)
161 (button-type (and button (button-get button 'type))))
162 (while (and button
163 (not (eq button-type 'apropos-label))
164 (or (not (eq button-type 'apropos-symbol))
165 (not already-hit-symbol)))
166 (when (eq button-type 'apropos-symbol)
167 (setq already-hit-symbol t))
168 (setq button (next-button (button-start button)))
169 (when button
170 (setq button-type (button-get button 'type))))
171 (and (eq button-type 'apropos-label)
172 button)))
173
129 174
130;;;###autoload 175;;;###autoload
131(define-derived-mode apropos-mode fundamental-mode "Apropos" 176(define-derived-mode apropos-mode fundamental-mode "Apropos"
@@ -504,22 +549,16 @@ alphabetically by symbol name; but this function also sets
504 (setq apropos-accumulator 549 (setq apropos-accumulator
505 (sort apropos-accumulator (lambda (a b) 550 (sort apropos-accumulator (lambda (a b)
506 (string-lessp (car a) (car b))))) 551 (string-lessp (car a) (car b)))))
507 (setq apropos-label-properties
508 (if (and apropos-label-face
509 (symbolp apropos-label-face))
510 `(face ,apropos-label-face
511 mouse-face highlight
512 help-echo "mouse-2: display help on this item")))
513 (with-output-to-temp-buffer "*Apropos*" 552 (with-output-to-temp-buffer "*Apropos*"
514 (let ((p apropos-accumulator) 553 (let ((p apropos-accumulator)
515 (old-buffer (current-buffer)) 554 (old-buffer (current-buffer))
516 symbol item point1 point2) 555 symbol item)
517 (set-buffer standard-output) 556 (set-buffer standard-output)
518 (apropos-mode) 557 (apropos-mode)
519 (if (display-mouse-p) 558 (if (display-mouse-p)
520 (insert "If moving the mouse over text changes the text's color,\n" 559 (insert "If moving the mouse over text changes the text's color,\n"
521 (substitute-command-keys 560 (substitute-command-keys
522 "you can click \\[apropos-mouse-follow] on that text to get more information.\n"))) 561 "you can click \\[push-button] on that text to get more information.\n")))
523 (insert "In this buffer, go to the name of the command, or function," 562 (insert "In this buffer, go to the name of the command, or function,"
524 " or variable,\n" 563 " or variable,\n"
525 (substitute-command-keys 564 (substitute-command-keys
@@ -528,10 +567,13 @@ alphabetically by symbol name; but this function also sets
528 (or (not spacing) (bobp) (terpri)) 567 (or (not spacing) (bobp) (terpri))
529 (setq apropos-item (car p) 568 (setq apropos-item (car p)
530 symbol (car apropos-item) 569 symbol (car apropos-item)
531 p (cdr p) 570 p (cdr p))
532 point1 (point)) 571 (insert-text-button (symbol-name symbol)
533 (princ symbol) ; print symbol name 572 'type 'apropos-symbol
534 (setq point2 (point)) 573 ;; Can't use default, since user may have
574 ;; changed the variable!
575 ;; Just say `no' to variables containing faces!
576 'face apropos-symbol-face)
535 ;; Calculate key-bindings if we want them. 577 ;; Calculate key-bindings if we want them.
536 (and do-keys 578 (and do-keys
537 (commandp symbol) 579 (commandp symbol)
@@ -577,13 +619,6 @@ alphabetically by symbol name; but this function also sets
577 (put-text-property (- (point) 3) (point) 619 (put-text-property (- (point) 3) (point)
578 'face apropos-keybinding-face))) 620 'face apropos-keybinding-face)))
579 (terpri) 621 (terpri)
580 ;; only now so we don't propagate text attributes all over
581 (put-text-property point1 point2 'item
582 (if (eval `(or ,@(cdr apropos-item)))
583 (car apropos-item)
584 apropos-item))
585 (if apropos-symbol-face
586 (put-text-property point1 point2 'face apropos-symbol-face))
587 (apropos-print-doc 'describe-function 1 622 (apropos-print-doc 'describe-function 1
588 (if (commandp symbol) 623 (if (commandp symbol)
589 "Command" 624 "Command"
@@ -623,51 +658,26 @@ alphabetically by symbol name; but this function also sets
623 (if (stringp (setq i (nth i apropos-item))) 658 (if (stringp (setq i (nth i apropos-item)))
624 (progn 659 (progn
625 (insert " ") 660 (insert " ")
626 (put-text-property (- (point) 2) (1- (point)) 661 (insert-text-button str
627 'action action) 662 'type 'apropos-label
628 (insert str ": ") 663 ;; Can't use the default button face, since
629 (if apropos-label-properties 664 ;; user may have changed the variable!
630 (add-text-properties (- (point) (length str) 2) 665 ;; Just say `no' to variables containing faces!
631 (1- (point)) 666 'face apropos-label-face
632 apropos-label-properties)) 667 'apropos-symbol (car apropos-item)
668 'apropos-action action
669 str)
670 (insert ": ")
633 (insert (if do-keys (substitute-command-keys i) i)) 671 (insert (if do-keys (substitute-command-keys i) i))
634 (or (bolp) (terpri))))) 672 (or (bolp) (terpri)))))
635 673
636 674
637(defun apropos-mouse-follow (event) 675(defun apropos-follow ()
638 (interactive "e") 676 "Invokes any button at point, otherwise invokes the nearest label button."
639 (let ((other (if (eq (current-buffer) (get-buffer "*Apropos*"))
640 ()
641 (current-buffer))))
642 (save-excursion
643 (set-buffer (window-buffer (posn-window (event-start event))))
644 (goto-char (posn-point (event-start event)))
645 (or (and (not (eobp)) (get-text-property (point) 'mouse-face))
646 (and (not (bobp)) (get-text-property (1- (point)) 'mouse-face))
647 (error "There is nothing to follow here"))
648 (apropos-follow other))))
649
650
651(defun apropos-follow (&optional other)
652 (interactive) 677 (interactive)
653 (let* (;; Properties are always found at the beginning of the line. 678 (button-activate
654 (bol (save-excursion (beginning-of-line) (point))) 679 (or (apropos-next-label-button (line-beginning-position))
655 ;; If there is no `item' property here, look behind us. 680 (error "There is nothing to follow here"))))
656 (item (get-text-property bol 'item))
657 (item-at (if item nil (previous-single-property-change bol 'item)))
658 ;; Likewise, if there is no `action' property here, look in front.
659 (action (get-text-property bol 'action))
660 (action-at (if action nil (next-single-property-change bol 'action))))
661 (and (null item) item-at
662 (setq item (get-text-property (1- item-at) 'item)))
663 (and (null action) action-at
664 (setq action (get-text-property action-at 'action)))
665 (if (not (and item action))
666 (error "There is nothing to follow here"))
667 (if (consp item) (error "There is nothing to follow in `%s'" (car item)))
668 (if other (set-buffer other))
669 (funcall action item)))
670
671 681
672 682
673(defun apropos-describe-plist (symbol) 683(defun apropos-describe-plist (symbol)
@@ -683,6 +693,7 @@ alphabetically by symbol name; but this function also sets
683 (princ ")") 693 (princ ")")
684 (print-help-return-message))) 694 (print-help-return-message)))
685 695
696
686(provide 'apropos) 697(provide 'apropos)
687 698
688;;; apropos.el ends here 699;;; apropos.el ends here