;;; finder.el --- topic & keyword-based code finder;; Copyright (C) 1992 Free Software Foundation, Inc.;; Author: Eric S. Raymond <esr@snark.thyrsus.com>;; Created: 16 Jun 1992;; Version: 1.0;; Keywords: help;; X-Modified-by: Bob Weiner <weiner@mot.com>, 4/18/95, to include Lisp;; library directory names in finder-program-info, for fast display of;; Lisp libraries and associated commentaries. Added {v}, finder-view,;; and {e}, finder-edit commands for displaying libraries.;; ;; Added user variable, 'finder-abbreviate-directory-list', used to;; abbreviate directories before they are saved to finder-program-info.;; Such relative directories can be portable from one Emacs installation;; to another. Default value is based upon the value of Emacs';; data-directory variable.;; This file is part of XEmacs.;; XEmacs is free software; you can redistribute it and/or modify it;; under the terms of the GNU General Public License as published by;; the Free Software Foundation; either version 2, or (at your option);; any later version.;; XEmacs is distributed in the hope that it will be useful, but;; WITHOUT ANY WARRANTY; without even the implied warranty of;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU;; General Public License for more details.;; You should have received a copy of the GNU General Public License;; along with XEmacs; see the file COPYING. If not, write to the Free;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA;; 02111-1307, USA.;;; Synched up with: FSF 19.34.;;; Commentary:;; This mode uses the Keywords library header to provide code-finding;; services by keyword.;;;; Things to do:;; 1. Support multiple keywords per search. This could be extremely hairy;;; there doesn't seem to be any way to get completing-read to exit on;; an EOL with no substring pending, which is what we'd want to end the loop.;; 2. Search by string in synopsis line?;; 3. Function to check finder-package-info for unknown keywords.;;; Code:(require'lisp-mnt)(condition-casenil(require'finder-inf)(tnil));; XEmacs addition(require'picture)(require'mode-motion)(defvarfinder-emacs-root-directory(file-name-directory(directory-file-namedata-directory))"Root directory of current emacs tree.")(defvarfinder-abbreviate-directory-list(listfinder-emacs-root-directory)"*List of directory roots to remove from finder-package-info directory entries.The first element in the list is used when expanding relative packagedirectories to view or extract information from package source code.")(defvarfinder-file-regexp"\\.el$""Regexp which matches file names but not Emacs Lisp finder keywords.");; Local variable in finder buffer.(defvarfinder-headmark)(defvarfinder-known-keywords`((abbrev."abbreviation handling, typing shortcuts, macros")(bib."code related to the `bib' bibliography processor")(c."C, C++, and Objective-C language support")(calendar."calendar and time management support")(comm."communications, networking, remote access to files")(data."support for editing files of data")(docs."support for Emacs documentation")(dumped."files preloaded into Emacs")(emulations."emulations of other editors")(extensions."Emacs Lisp language extensions")(faces."support for multiple fonts")(frames."support for Emacs frames and window systems")(games."games, jokes and amusements")(hardware."support for interfacing with exotic hardware")(help."support for on-line help systems")(hypermedia."support for links between text or other media types")(i18n."internationalization and alternate character-set support")(internal."code for Emacs internals, build process, defaults")(languages."specialized modes for editing programming languages")(lisp."Lisp support, including Emacs Lisp")(local."code local to your site")(maint."maintenance aids for the Emacs development group")(mail."modes for electronic-mail handling")(matching."various sorts of searching and matching")(mouse."mouse support"),(when(featurep'mule)(cons'mule"multi-language extensions"))(news."support for netnews reading and posting")(oop."support for object-oriented programming")(outlines."support for hierarchical outlining")(processes."process, subshell, compilation, and job control support")(terminals."support for terminal types")(tex."code related to the TeX formatter")(tools."programming tools")(unix."front-ends/assistants for, or emulators of, UNIX features")(vms."support code for vms")(wp."word processing")))(defvarfinder-mode-mapnil)(orfinder-mode-map(let((map(make-sparse-keymap)))(define-keymap" "'finder-select)(define-keymap"f"'finder-select)(define-keymap"\C-m"'finder-select);; XEmacs changes(define-keymap"e"'finder-edit)(define-keymap"v"'finder-view)(define-keymap"?"'finder-summary)(define-keymap"q"'finder-exit)(define-keymap"d"'finder-list-keywords);; XEmacs change(define-keymap[button2]'finder-mouse-select)(setqfinder-mode-mapmap)));;; Code for regenerating the keyword list.(defvarfinder-package-infonil"Assoc list mapping file names to description & keyword lists.")(defvarfinder-compile-keywords-quietnil"If non-nil finder-compile-keywords will not print any messages.")(defunfinder-compile-keywords(&restdirs)"Regenerate the keywords association list into the file `finder-inf.el'.Optional arguments are a list of Emacs Lisp directories to compile from; noarguments compiles from `load-path'."(save-excursion;; XEmacs change(find-file"finder-inf.el")(let((processednil)(directory-abbrev-alist(append(mapcar(function(lambda(dir)(consdir"")))finder-abbreviate-directory-list)directory-abbrev-alist))(using-load-path))(ordirs(setqdirsload-path))(setqusing-load-path(equaldirsload-path))(erase-buffer)(insert";;; finder-inf.el --- keyword-to-package mapping\n")(insert";; Keywords: help\n")(insert";;; Commentary:\n")(insert";; Don't edit this file. It's generated by finder.el\n\n")(insert";;; Code:\n")(insert"\n(setq finder-package-info '(\n")(mapcar(function(lambda(d)(mapcar(function(lambda(f)(if(not(memberfprocessed))(let(summarykeystartkeywords)(setqprocessed(consfprocessed))(if(notfinder-compile-keywords-quiet)(message"Processing %s ..."f))(save-excursion(set-buffer(get-buffer-create"*finder-scratch*"))(buffer-disable-undo(current-buffer))(erase-buffer)(insert-file-contents(expand-file-namefd))(condition-caseerr(setqsummary(lm-synopsis)keywords(lm-keywords))(t(message"finder: error processing %s %S"ferr))))(if(notsummary)nil(insert(format" (\"%s\"\n "f))(prin1summary(current-buffer))(insert"\n ")(setqkeystart(point))(insert(ifkeywords(format"(%s)"keywords)"nil"))(subst-char-in-regionkeystart(point)?,?)(insert"\n ")(prin1(abbreviate-file-named)(current-buffer))(insert")\n"))))));;;; Skip null, non-existent or relative pathnames, e.g. "./", if;; using load-path, so that they do not interfere with a scan of;; library directories only.(if(andusing-load-path(not(andd(file-name-absolute-pd)(file-exists-pd))))nil(setqd(file-name-as-directory(ord".")))(directory-filesdnil"^[^=].*\\.el$")))))dirs)(insert"))\n\n(provide 'finder-inf)\n\n;;; finder-inf.el ends here\n")(kill-buffer"*finder-scratch*")(unlessnoninteractive(eval-current-buffer)); So we get the new keyword list immediately(basic-save-buffer))))(defunfinder-compile-keywords-make-dist()"Regenerate `finder-inf.el' for the Emacs distribution."(finder-compile-keywordsdefault-directory));;; Now the retrieval code(defunfinder-insert-at-column(column&reststrings)"Insert list of STRINGS, at column COLUMN."(if(>=(current-column)column)(insert"\n"))(move-to-columncolumn)(let((col(current-column)))(if(<colcolumn)(indent-tocolumn)(if(and(/=colcolumn)(=(preceding-char)?\t))(let(indent-tabs-mode)(delete-char-1)(indent-tocol)(move-to-columncolumn)))))(apply'insertstrings))(defunfinder-list-keywords()"Display descriptions of the keywords in the Finder buffer."(interactive)(setqbuffer-read-onlynil)(erase-buffer)(mapcar(lambda(assoc)(let((keyword(carassoc)))(insert(symbol-namekeyword))(finder-insert-at-column14(concat(cdrassoc)"\n"))(cons(symbol-namekeyword)keyword)))finder-known-keywords)(goto-char(point-min))(setqfinder-headmark(point))(setqbuffer-read-onlyt)(set-buffer-modified-pnil);; XEmacs change(if(not(one-window-p))(balance-windows))(finder-summary))(defunfinder-list-matches(key)(setqbuffer-read-onlynil)(erase-buffer)(let((id(internkey)))(insert"The following packages match the keyword `"key"':\n\n")(setqfinder-headmark(point))(mapcar(lambda(x)(if(memqid(car(cdr(cdrx))))(progn(insert(carx))(finder-insert-at-column16(concat(car(cdrx))"\n")))))finder-package-info)(goto-char(point-min))(forward-line)(setqbuffer-read-onlyt)(set-buffer-modified-pnil)(shrink-window-if-larger-than-buffer)(finder-summary)));; Search for a file named FILE the same way `load' would search.(defunfinder-find-library(file)(if(file-name-absolute-pfile)file(let((dirsload-path)found)(while(anddirs(notfound))(if(file-exists-p(expand-file-name(concatfile".el")(cardirs)))(setqfound(expand-file-namefile(cardirs)))(if(file-exists-p(expand-file-namefile(cardirs)))(setqfound(expand-file-namefile(cardirs)))))(setqdirs(cdrdirs)))found)))(defunfinder-commentary(file)(interactive)(let*((str(lm-commentary(finder-find-libraryfile))))(if(nullstr)(error"Can't find any Commentary section"))(pop-to-buffer"*Finder*");; XEmacs change(setqbuffer-read-onlynilmode-motion-hook'mode-motion-highlight-line)(erase-buffer)(insertstr)(goto-char(point-min))(delete-blank-lines)(goto-char(point-max))(delete-blank-lines)(goto-char(point-min))(while(re-search-forward"^;+ ?"nilt)(replace-match""nilnil))(goto-char(point-min))(setqbuffer-read-onlyt)(set-buffer-modified-pnil)(shrink-window-if-larger-than-buffer)(finder-summary)))(defunfinder-current-item()(if(andfinder-headmark(<(point)finder-headmark))(error"No keyword or filename on this line")(save-excursion(beginning-of-line)(current-word))));; XEmacs change(defunfinder-edit()(interactive)(let((entry(finder-current-item)))(if(string-matchfinder-file-regexpentry)(let((path(finder-find-libraryentry)))(ifpath(find-file-other-windowpath)(error"Can't find Emacs Lisp library: '%s'"entry)));; a finder keyword(error"Finder-edit works on Emacs Lisp libraries only"))));; XEmacs change(defunfinder-view()(interactive)(let((entry(finder-current-item)))(if(string-matchfinder-file-regexpentry)(let((path(finder-find-libraryentry)))(ifpath(view-file-other-windowpath)(error"Can't find Emacs Lisp library: '%s'"entry)));; a finder keyword(error"Finder-view works on Emacs Lisp libraries only"))))(defunfinder-select()(interactive)(let((key(finder-current-item)));; XEmacs change(if(string-matchfinder-file-regexpkey)(finder-commentarykey)(finder-list-matcheskey))));; XEmacs change(defunfinder-mouse-select(ev)(interactive"e")(goto-char(event-pointev))(finder-select));; XEmacs change;;;###autoload(defunfinder-by-keyword()"Find packages matching a given keyword."(interactive)(finder-mode)(finder-list-keywords))(defunfinder-mode()"Major mode for browsing package documentation.\\<finder-mode-map>\\[finder-select] more help for the item on the current line\\[finder-edit] edit Lisp library in another window\\[finder-view] view Lisp library in another window\\[finder-exit] exit Finder mode and kill the Finder buffer."(interactive)(pop-to-buffer"*Finder*");; XEmacs change(setqbuffer-read-onlynilmode-motion-hook'mode-motion-highlight-line)(erase-buffer)(use-local-mapfinder-mode-map)(set-syntax-tableemacs-lisp-mode-syntax-table)(setqmode-name"Finder")(setqmajor-mode'finder-mode)(make-local-variable'finder-headmark)(setqfinder-headmarknil))(defunfinder-summary()"Summarize basic Finder commands."(interactive)(message"%s"(substitute-command-keys;; XEmacs change"\\<finder-mode-map>\\[finder-select] = select, \\[finder-list-keywords] = keywords, \\[finder-edit] = edit, \\[finder-view] = view, \\[finder-exit] = quit, \\[finder-summary] = help")))(defunfinder-exit()"Exit Finder mode and kill the buffer"(interactive);; XEmacs change(or(one-window-pt0)(delete-window))(kill-buffer"*Finder*"))(provide'finder);;; finder.el ends here