From 2e3d43acd9c6e5b06f8bd1d4a0c8abc66dbc0e1f Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Sun, 8 Jun 2008 04:32:43 +0000 Subject: [PATCH] (apropos-library): New command and new button. (apropos-library-button): New function. --- etc/NEWS | 2 ++ lisp/ChangeLog | 3 +++ lisp/apropos.el | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+) diff --git a/etc/NEWS b/etc/NEWS index 4be44175e73..73c6dacecf3 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -63,6 +63,8 @@ default toolkit, but you can use --with-x-toolkit=gtk if necessary. * Changes in Emacs 23.1 +** `apropos-library' describes the elements defined in a given library. + ** scroll-preserve-screen-position also preserves the column position. ** Completion. *** `completion-styles' can be customized to choose your favorite completion. diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 91c276b2ba7..f7bb9fc3205 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,5 +1,8 @@ 2008-06-08 Stefan Monnier + * apropos.el (apropos-library): New command and new button. + (apropos-library-button): New function. + * apropos.el: Remove spurious * in docstrings. (apropos-label-face): Use variable pitch. (apropos-print): Use dolist and with-current-buffer. diff --git a/lisp/apropos.el b/lisp/apropos.el index a073d293524..d453cb89de8 100644 --- a/lisp/apropos.el +++ b/lisp/apropos.el @@ -250,6 +250,12 @@ term, and the rest of the words are alternative terms.") 'action (lambda (button) (apropos-describe-plist (button-get button 'apropos-symbol)))) +(define-button-type 'apropos-library + 'help-echo "mouse-2, RET: Display more help on this library" + 'follow-link t + 'action (lambda (button) + (apropos-library (button-get button 'apropos-symbol)))) + (defun apropos-next-label-button (pos) "Return the next apropos label button after POS, or nil if there's none. Will also return nil if more than one `apropos-symbol' button is encountered @@ -531,6 +537,66 @@ Returns list of symbols and documentation found." (symbol-plist symbol))))) (or do-all apropos-do-all))) +(defun apropos-library-button (sym) + (if (null sym) + "" + (let ((name (copy-sequence (symbol-name sym)))) + (make-text-button name nil + 'type 'apropos-library + 'face apropos-symbol-face + 'apropos-symbol name) + name))) + +;;;###autoload +(defun apropos-library (file) + "List the variables and functions defined by library FILE. +FILE should be one of the libraries currently loaded and should +thus be found in `load-history'." + (interactive + (let ((libs + (nconc (delq nil + (mapcar + (lambda (l) + (setq l (file-name-nondirectory l)) + (while + (not (equal (setq l (file-name-sans-extension l)) + l))) + l) + (mapcar 'car load-history))) + (mapcar 'car load-history)))) + (list (completing-read "Describe library: " libs nil t)))) + (let ((symbols nil) + ;; (autoloads nil) + (provides nil) + (requires nil) + (lh-entry (assoc file load-history))) + (unless lh-entry + ;; `file' may be the "shortname". + (let ((lh load-history) + (re (concat "\\(?:\\`\\|[\\/]\\)" (regexp-quote file) + "\\(\\.\\|\\'\\)"))) + (while (and lh (null lh-entry)) + (if (string-match re (caar lh)) + (setq lh-entry (car lh)) + (setq lh (cdr lh))))) + (unless lh-entry (error "Unknown library `%s'" file))) + (dolist (x (cdr lh-entry)) + (case (car-safe x) + ;; (autoload (push (cdr x) autoloads)) + (require (push (cdr x) requires)) + (provide (push (cdr x) provides)) + (t (push (or (cdr-safe x) x) symbols)))) + (let ((apropos-pattern "")) ;Dummy binding for apropos-symbols-internal. + (apropos-symbols-internal + symbols apropos-do-all + (concat + (format "Library `%s' provides: %s\nand requires: %s" + file + (mapconcat 'apropos-library-button + (or provides '(nil)) " and ") + (mapconcat 'apropos-library-button + (or requires '(nil)) " and "))))))) + (defun apropos-symbols-internal (symbols keys &optional text) ;; Filter out entries that are marked as apropos-inhibit. (let ((all nil)) -- 2.39.2