diff options
| -rw-r--r-- | lisp/finder.el | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/lisp/finder.el b/lisp/finder.el new file mode 100644 index 00000000000..de761b14267 --- /dev/null +++ b/lisp/finder.el | |||
| @@ -0,0 +1,156 @@ | |||
| 1 | ;;; finder.el --- topic & keyword-based code finder | ||
| 2 | |||
| 3 | ;; Copyright (C) 1992 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; Author: Eric S. Raymond <esr@snark.thyrsus.com> | ||
| 6 | ;; Created: 16 Jun 1992 | ||
| 7 | ;; Version: 1.0 | ||
| 8 | ;; Keywords: help | ||
| 9 | |||
| 10 | ;; This file is part of GNU Emacs. | ||
| 11 | |||
| 12 | ;; GNU Emacs is free software; you can redistribute it and/or modify | ||
| 13 | ;; it under the terms of the GNU General Public License as published by | ||
| 14 | ;; the Free Software Foundation; either version 1, or (at your option) | ||
| 15 | ;; any later version. | ||
| 16 | |||
| 17 | ;; GNU Emacs is distributed in the hope that it will be useful, | ||
| 18 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 19 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 20 | ;; GNU General Public License for more details. | ||
| 21 | |||
| 22 | ;; You should have received a copy of the GNU General Public License | ||
| 23 | ;; along with GNU Emacs; see the file COPYING. If not, write to | ||
| 24 | ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | ||
| 25 | |||
| 26 | ;; Commentary: | ||
| 27 | |||
| 28 | ;; This mode uses the Keywords library header to provide code-finding | ||
| 29 | ;; services by keyword. | ||
| 30 | ;; | ||
| 31 | ;; Things to do: | ||
| 32 | ;; 1. Support multiple keywords per search. This could be extremely hairy; | ||
| 33 | ;; there doesn't seem to be any way to get completing-read to exit on | ||
| 34 | ;; an EOL with no substring pending, which is what we'd want to end the loop. | ||
| 35 | ;; 2. Search by string in synopsis line? | ||
| 36 | ;; 3. Function to check finder-package-info for unknown keywords. | ||
| 37 | |||
| 38 | ;;; Code: | ||
| 39 | |||
| 40 | (require 'lisp-mnt) | ||
| 41 | (require 'finder-inf) | ||
| 42 | (require 'picture) | ||
| 43 | |||
| 44 | (defvar finder-known-keywords | ||
| 45 | '( | ||
| 46 | (bib . "code related to the bib(1) bibliography processor") | ||
| 47 | (c . "C and C++ language support") | ||
| 48 | (calendar . "calendar and time management support") | ||
| 49 | (docs . "support for Emacs documentation") | ||
| 50 | (emulations . "emulations of other editors") | ||
| 51 | (extensions . "Emacs Lisp language extensions") | ||
| 52 | (games . "games, jokes and amusements") | ||
| 53 | (hardware . "support for interfacing with exotic hardware") | ||
| 54 | (help . "support for on-line help systems") | ||
| 55 | (i14n . "internationalization and alternate character-set support") | ||
| 56 | (internal . "code for Emacs internals, build process, defaults") | ||
| 57 | (languages . "specialized modes for editing programming languages") | ||
| 58 | (lisp . "Lisp support, including Emacs Lisp") | ||
| 59 | (local . "code local to your site") | ||
| 60 | (maint . "maintenance aids for the Emacs development group") | ||
| 61 | (mail . "modes for electronic-mail handling") | ||
| 62 | (news . "support for netnews reading and posting") | ||
| 63 | (processes . "process, subshell, compilation, and job control support") | ||
| 64 | (terminals . "support for terminal types") | ||
| 65 | (tex . "code related to the TeX formatter") | ||
| 66 | (tools . "programming tools") | ||
| 67 | (unix . "front-ends/assistants for, or emulators of, UNIX features") | ||
| 68 | (vms . "support code for vms") | ||
| 69 | (wp . "word processing") | ||
| 70 | )) | ||
| 71 | |||
| 72 | ;;; Code for regenerating the keyword list. | ||
| 73 | |||
| 74 | (defvar finder-package-info nil | ||
| 75 | "Assoc list mapping file names to description & keyword lists.") | ||
| 76 | |||
| 77 | (defun finder-compile-keywords (&rest dirs) | ||
| 78 | "Regenerate the keywords association list into the file finder-inf.el. | ||
| 79 | Optional arguments are a list of Emacs Lisp directories to compile from; no | ||
| 80 | arguments compiles from load-path." | ||
| 81 | (save-excursion | ||
| 82 | (find-file "finder-inf.el") | ||
| 83 | (erase-buffer) | ||
| 84 | (insert ";;; Don't edit this file. It's generated by finder.el\n\n") | ||
| 85 | (insert "\n(setq finder-package-info '(\n") | ||
| 86 | (mapcar | ||
| 87 | (function (lambda (d) | ||
| 88 | (mapcar | ||
| 89 | (function (lambda (f) | ||
| 90 | (if (string-match "\\.el$" f) | ||
| 91 | (let (summary keystart) | ||
| 92 | (save-excursion | ||
| 93 | (set-buffer (get-buffer-create "*finder-scratch*")) | ||
| 94 | (erase-buffer) | ||
| 95 | (insert-file-contents | ||
| 96 | (concat (file-name-as-directory d) f)) | ||
| 97 | (setq summary (lm-synopsis)) | ||
| 98 | (setq keywords (lm-keywords))) | ||
| 99 | (insert | ||
| 100 | (format " (\"%s\"\n " f) | ||
| 101 | (if summary (format "\"%s\"" summary) "nil") | ||
| 102 | "\n ") | ||
| 103 | (setq keystart (point)) | ||
| 104 | (insert | ||
| 105 | (if keywords (format "(%s)" keywords) "nil") | ||
| 106 | ")\n") | ||
| 107 | (subst-char-in-region keystart (point) ?, ? ) | ||
| 108 | ) | ||
| 109 | ))) | ||
| 110 | (directory-files (or d "."))) | ||
| 111 | )) | ||
| 112 | (or dirs load-path)) | ||
| 113 | (insert "))\n\n(provide 'finder-inf)\n") | ||
| 114 | (kill-buffer "*finder-scratch*") | ||
| 115 | (basic-save-buffer) | ||
| 116 | )) | ||
| 117 | |||
| 118 | ;;; Now the retrieval code | ||
| 119 | |||
| 120 | (defun finder-by-keyword () | ||
| 121 | "Find packages matching a given keyword." | ||
| 122 | (interactive) | ||
| 123 | (pop-to-buffer "*Help*") | ||
| 124 | (erase-buffer) | ||
| 125 | (mapcar | ||
| 126 | (function (lambda (x) | ||
| 127 | (insert (symbol-name (car x))) | ||
| 128 | (insert-at-column 14 (cdr x) "\n") | ||
| 129 | )) | ||
| 130 | finder-known-keywords) | ||
| 131 | (goto-char (point-min)) | ||
| 132 | (let (key | ||
| 133 | (known (mapcar (function (lambda (x) (car x))) finder-known-keywords))) | ||
| 134 | (let ((key (intern (completing-read | ||
| 135 | "Package keyword: " | ||
| 136 | (vconcat known) | ||
| 137 | (function (lambda (arg) (memq arg known))) | ||
| 138 | t)))) | ||
| 139 | (erase-buffer) | ||
| 140 | (insert | ||
| 141 | "The following packages match the keyword `" (symbol-name key) "':\n\n") | ||
| 142 | (mapcar | ||
| 143 | (function (lambda (x) | ||
| 144 | (if (memq key (car (cdr (cdr x)))) | ||
| 145 | (progn | ||
| 146 | (insert (car x)) | ||
| 147 | (insert-at-column 16 (car (cdr x)) "\n") | ||
| 148 | )) | ||
| 149 | )) | ||
| 150 | finder-package-info) | ||
| 151 | (goto-char (point-min)) | ||
| 152 | ))) | ||
| 153 | |||
| 154 | (provide 'finder) | ||
| 155 | |||
| 156 | ;;; finder.el ends here | ||