annotate lisp/finder.el @ 2983:2997ff5f2aba

[xemacs-hg @ 2005-10-09 10:41:37 by adrian] xemacs-21.5-clean: finder-find-library to return filename actually searched for -------------------- ChangeLog entries follow: -------------------- lisp/ChangeLog addition: 2005-10-09 Adrian Aichner <adrian@xemacs.org> * finder.el (finder-find-library): Return filename actually searched for.
author adrian
date Sun, 09 Oct 2005 10:41:38 +0000
parents 70921960b980
children ffa5a6e7f2dd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2983
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
1 ;;; finder.el --- topic & keyword-based code finder
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
2
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
3 ;; Copyright (C) 1992 Free Software Foundation, Inc.
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
4
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
5 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com>
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
6 ;; Created: 16 Jun 1992
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
7 ;; Version: 1.0
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
8 ;; Keywords: help
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
9 ;; X-Modified-by: Bob Weiner <weiner@mot.com>, 4/18/95, to include Lisp
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
10 ;; library directory names in finder-program-info, for fast display of
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
11 ;; Lisp libraries and associated commentaries. Added {v}, finder-view,
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
12 ;; and {e}, finder-edit commands for displaying libraries.
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
13 ;;
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
14 ;; Added user variable, 'finder-abbreviate-directory-list', used to
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
15 ;; abbreviate directories before they are saved to finder-program-info.
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
16 ;; Such relative directories can be portable from one Emacs installation
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
17 ;; to another. Default value is based upon the value of Emacs'
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
18 ;; data-directory variable.
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
19
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
20 ;; This file is part of XEmacs.
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
21
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
22 ;; XEmacs is free software; you can redistribute it and/or modify it
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
23 ;; under the terms of the GNU General Public License as published by
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
24 ;; the Free Software Foundation; either version 2, or (at your option)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
25 ;; any later version.
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
26
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
27 ;; XEmacs is distributed in the hope that it will be useful, but
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
28 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
29 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
30 ;; General Public License for more details.
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
31
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
32 ;; You should have received a copy of the GNU General Public License
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
33 ;; along with XEmacs; see the file COPYING. If not, write to the Free
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
34 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
35 ;; 02111-1307, USA.
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
36
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
37 ;;; Synched up with: FSF 19.34.
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
38
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
39 ;;; Commentary:
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
40
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
41 ;; This mode uses the Keywords library header to provide code-finding
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
42 ;; services by keyword.
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
43 ;;
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
44 ;; Things to do:
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
45 ;; 1. Support multiple keywords per search. This could be extremely hairy;
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
46 ;; there doesn't seem to be any way to get completing-read to exit on
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
47 ;; an EOL with no substring pending, which is what we'd want to end the loop.
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
48 ;; 2. Search by string in synopsis line?
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
49 ;; 3. Function to check finder-package-info for unknown keywords.
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
50
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
51 ;;; Code:
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
52
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
53 (require 'lisp-mnt)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
54 (condition-case nil
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
55 (require 'finder-inf)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
56 (t nil))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
57 ;; XEmacs addition
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
58 (require 'picture)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
59 (require 'mode-motion)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
60
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
61 (defvar finder-emacs-root-directory
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
62 (file-name-directory (directory-file-name data-directory))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
63 "Root directory of current emacs tree.")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
64
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
65 (defvar finder-abbreviate-directory-list
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
66 (list finder-emacs-root-directory)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
67 "*List of directory roots to remove from finder-package-info directory entries.
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
68 The first element in the list is used when expanding relative package
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
69 directories to view or extract information from package source code.")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
70
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
71 (defvar finder-file-regexp "\\.el$"
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
72 "Regexp which matches file names but not Emacs Lisp finder keywords.")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
73
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
74 ;; Local variable in finder buffer.
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
75 (defvar finder-headmark)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
76
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
77 (defvar finder-known-keywords
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
78 `(
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
79 (abbrev . "abbreviation handling, typing shortcuts, macros")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
80 (bib . "code related to the `bib' bibliography processor")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
81 (build . "code used to build XEmacs")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
82 (c . "C, C++, and Objective-C language support")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
83 (calendar . "calendar and time management support")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
84 (comm . "communications, networking, remote access to files")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
85 (content . "contains content (menu/dialog box descs, text, images, &c)")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
86 (data . "support for editing files of data")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
87 (docs . "support for XEmacs documentation")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
88 (dumped . "files preloaded into XEmacs")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
89 (emulations . "emulations of other editors")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
90 (extensions . "Emacs Lisp language extensions")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
91 (faces . "support for multiple fonts")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
92 (frames . "support for XEmacs frames and window systems")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
93 (games . "games, jokes and amusements")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
94 (gui . "support for menubars, dialog boxes, and other GUI features")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
95 (hardware . "support for interfacing with exotic hardware")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
96 (help . "support for on-line help systems")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
97 (hypermedia . "support for links between text or other media types")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
98 (i18n . "internationalization and alternate character-set support")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
99 (internal . "code implementing core functionality in XEmacs")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
100 (languages . "specialized modes for editing programming languages")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
101 (lisp . "Lisp support, including Emacs Lisp")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
102 (local . "code local to your site")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
103 (mail . "modes for electronic-mail handling")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
104 (maint . "maintenance aids for the Emacs development group")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
105 (matching . "various sorts of searching and matching")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
106 (mouse . "mouse support")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
107 (mswin . "support for anything running on MS Windows")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
108 ,(when (featurep 'mule)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
109 (cons 'mule "multi-language extensions"))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
110 (news . "support for netnews reading and posting")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
111 (oop . "support for object-oriented programming")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
112 (outlines . "support for hierarchical outlining")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
113 (processes . "process, subshell, compilation, and job control support")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
114 (services . "provides services for use by other programs (cf `user')")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
115 (terminals . "support for terminal types")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
116 (tex . "code related to the TeX formatter")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
117 (tools . "programming tools")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
118 (unix . "front-ends/assistants for, or emulators of, UNIX features")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
119 (user . "program interacts directly with the user (cf `services'")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
120 (vms . "support code for vms")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
121 (wp . "word processing")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
122 (www . "support for the Web (WWW, the World Wide Web)")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
123 ))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
124
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
125 (defvar finder-mode-map nil)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
126 (or finder-mode-map
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
127 (let ((map (make-sparse-keymap)))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
128 (define-key map " " 'finder-select)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
129 (define-key map "f" 'finder-select)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
130 (define-key map "\C-m" 'finder-select)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
131 ;; XEmacs changes
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
132 (define-key map "e" 'finder-edit)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
133 (define-key map "v" 'finder-view)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
134 (define-key map "?" 'finder-summary)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
135 (define-key map "q" 'finder-exit)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
136 (define-key map "d" 'finder-list-keywords)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
137 ;; XEmacs change
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
138 (define-key map [button2] 'finder-mouse-select)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
139 (setq finder-mode-map map)))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
140
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
141
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
142 ;;; Code for regenerating the keyword list.
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
143
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
144 (defvar finder-package-info nil
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
145 "Assoc list mapping file names to description & keyword lists.")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
146
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
147 (defvar finder-compile-keywords-quiet nil
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
148 "If non-nil finder-compile-keywords will not print any messages.")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
149
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
150 (defun finder-compile-keywords (&rest dirs)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
151 "Regenerate the keywords association list into the file `finder-inf.el'.
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
152 Optional arguments are a list of Emacs Lisp directories to compile from; no
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
153 arguments compiles from `load-path'."
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
154 (save-excursion
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
155 ;; XEmacs change
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
156 (find-file (expand-file-name "finder-inf.el" lisp-directory))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
157 (let ((processed nil)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
158 (directory-abbrev-alist
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
159 (append
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
160 (mapcar (function (lambda (dir)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
161 (cons (concat "^" (regexp-quote dir))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
162 "")))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
163 finder-abbreviate-directory-list)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
164 directory-abbrev-alist))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
165 (using-load-path))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
166 (or dirs (setq dirs load-path))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
167 (setq using-load-path (equal dirs load-path))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
168 (erase-buffer)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
169 (insert ";;; finder-inf.el --- keyword-to-package mapping\n")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
170 (insert ";; Keywords: help\n")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
171 (insert ";;; Commentary:\n")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
172 (insert ";; Don't edit this file. It's generated by finder.el\n\n")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
173 (insert ";;; Code:\n")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
174 (insert "\n(defconst finder-package-info '(\n")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
175 (mapcar
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
176 (lambda (d)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
177 (mapcar
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
178 (lambda (f)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
179 (when (and (not (member f processed)) (file-readable-p f))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
180 (let (summary keystart keywords)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
181 (setq processed (cons f processed))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
182 (if (not finder-compile-keywords-quiet)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
183 (message "Processing %s ..." f))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
184 (save-excursion
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
185 (set-buffer (get-buffer-create "*finder-scratch*"))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
186 (buffer-disable-undo (current-buffer))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
187 (erase-buffer)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
188 (insert-file-contents (expand-file-name f d))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
189 (with-trapping-errors
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
190 :operation (format "processing %s in finder" f)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
191 :class 'finder
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
192 (setq summary (lm-synopsis)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
193 keywords (lm-keywords))))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
194 (when summary
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
195 (insert (format " (\"%s\"\n " f))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
196 (prin1 summary (current-buffer))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
197 (insert "\n ")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
198 (setq keystart (point))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
199 (insert (if keywords (format "(%s)" keywords) "nil"))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
200 (subst-char-in-region keystart (point) ?, ? )
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
201 (insert "\n ")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
202 (prin1 (abbreviate-file-name d) (current-buffer))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
203 (insert ")\n")))))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
204 ;;
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
205 ;; Skip null, non-existent or relative pathnames, e.g. "./", if
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
206 ;; using load-path, so that they do not interfere with a scan of
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
207 ;; library directories only.
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
208 (if (and using-load-path
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
209 (not (and d (file-name-absolute-p d) (file-exists-p d))))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
210 nil
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
211 (setq d (file-name-as-directory (or d ".")))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
212 (directory-files d nil "^[^=].*\\.el$"))))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
213 dirs)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
214 (insert "))\n\n(provide 'finder-inf)\n\n;;; finder-inf.el ends here\n")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
215 (kill-buffer "*finder-scratch*")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
216 (unless noninteractive
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
217 (eval-current-buffer)) ; So we get the new keyword list immediately
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
218 (basic-save-buffer))))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
219
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
220 (defun finder-compile-keywords-make-dist ()
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
221 "Regenerate `finder-inf.el' for the Emacs distribution."
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
222 (finder-compile-keywords default-directory))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
223
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
224 ;;; Now the retrieval code
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
225
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
226 (defun finder-insert-at-column (column &rest strings)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
227 "Insert list of STRINGS, at column COLUMN."
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
228 (if (>= (current-column) column) (insert "\n"))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
229 (move-to-column column)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
230 (let ((col (current-column)))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
231 (if (< col column)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
232 (indent-to column)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
233 (if (and (/= col column)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
234 (= (preceding-char) ?\t))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
235 (let (indent-tabs-mode)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
236 (delete-char -1)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
237 (indent-to col)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
238 (move-to-column column)))))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
239 (apply 'insert strings))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
240
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
241 (defun finder-list-keywords ()
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
242 "Display descriptions of the keywords in the Finder buffer."
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
243 (interactive)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
244 (setq buffer-read-only nil)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
245 (erase-buffer)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
246 (mapcar
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
247 (lambda (assoc)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
248 (let ((keyword (car assoc)))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
249 (insert (symbol-name keyword))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
250 (finder-insert-at-column 14 (concat (cdr assoc) "\n"))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
251 (cons (symbol-name keyword) keyword)))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
252 finder-known-keywords)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
253 (goto-char (point-min))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
254 (setq finder-headmark (point))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
255 (setq buffer-read-only t)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
256 (set-buffer-modified-p nil)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
257 ;; XEmacs change
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
258 (if (not (one-window-p))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
259 (balance-windows))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
260 (finder-summary))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
261
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
262 (defun finder-list-matches (key)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
263 (setq buffer-read-only nil)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
264 (erase-buffer)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
265 (let ((id (intern key)))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
266 (insert
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
267 "The following packages match the keyword `" key "':\n\n")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
268 (setq finder-headmark (point))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
269 (mapcar
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
270 (lambda (x)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
271 (if (memq id (car (cdr (cdr x))))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
272 (progn
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
273 (insert (car x))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
274 (finder-insert-at-column 16 (concat (car (cdr x)) "\n")))))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
275 finder-package-info)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
276 (goto-char (point-min))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
277 (forward-line)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
278 (setq buffer-read-only t)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
279 (set-buffer-modified-p nil)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
280 (shrink-window-if-larger-than-buffer)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
281 (finder-summary)))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
282
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
283 ;; Search for a file named FILE the same way `load' would search.
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
284 (defun finder-find-library (file)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
285 (if (file-name-absolute-p file)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
286 file
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
287 (let ((dirs load-path)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
288 found)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
289 (while (and dirs (not found))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
290 (if (file-exists-p (expand-file-name (concat file ".el") (car dirs)))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
291 (setq found (expand-file-name (concat file ".el") (car dirs)))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
292 (if (file-exists-p (expand-file-name file (car dirs)))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
293 (setq found (expand-file-name file (car dirs)))))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
294 (setq dirs (cdr dirs)))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
295 found)))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
296
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
297 ;;;###autoload
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
298 (defun finder-commentary (file)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
299 "Display FILE's commentary section.
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
300 FILE should be in a form suitable for passing to `locate-library'."
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
301 (interactive "sLibrary name: ")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
302 (let* ((str (lm-commentary (or (finder-find-library file)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
303 (finder-find-library (concat file ".el"))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
304 (error "Can't find library %s" file)))))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
305 (if (null str)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
306 (error "Can't find any Commentary section"))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
307 (pop-to-buffer "*Finder*")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
308 ;; XEmacs change
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
309 (setq buffer-read-only nil
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
310 mode-motion-hook 'mode-motion-highlight-line)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
311 (erase-buffer)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
312 (insert str)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
313 (goto-char (point-min))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
314 (delete-blank-lines)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
315 (goto-char (point-max))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
316 (delete-blank-lines)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
317 (goto-char (point-min))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
318 (while (re-search-forward "^;+ ?" nil t)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
319 (replace-match "" nil nil))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
320 (goto-char (point-min))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
321 (setq buffer-read-only t)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
322 (set-buffer-modified-p nil)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
323 (shrink-window-if-larger-than-buffer)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
324 (finder-summary)))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
325
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
326 (defun finder-current-item ()
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
327 (if (and finder-headmark (< (point) finder-headmark))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
328 (error "No keyword or filename on this line")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
329 (save-excursion
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
330 (beginning-of-line)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
331 (current-word))))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
332
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
333 ;; XEmacs change
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
334 (defun finder-edit ()
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
335 (interactive)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
336 (let ((entry (finder-current-item)))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
337 (if (string-match finder-file-regexp entry)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
338 (let ((path (finder-find-library entry)))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
339 (if path
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
340 (find-file-other-window path)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
341 (error "Can't find Emacs Lisp library: '%s'" entry)))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
342 ;; a finder keyword
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
343 (error "Finder-edit works on Emacs Lisp libraries only"))))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
344
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
345 ;; XEmacs change
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
346 (defun finder-view ()
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
347 (interactive)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
348 (let ((entry (finder-current-item)))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
349 (if (string-match finder-file-regexp entry)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
350 (let ((path (finder-find-library entry)))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
351 (if path
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
352 (view-file-other-window path)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
353 (error "Can't find Emacs Lisp library: '%s'" entry)))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
354 ;; a finder keyword
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
355 (error "Finder-view works on Emacs Lisp libraries only"))))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
356
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
357 (defun finder-select ()
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
358 (interactive)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
359 (let ((key (finder-current-item)))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
360 ;; XEmacs change
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
361 (if (string-match finder-file-regexp key)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
362 (finder-commentary key)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
363 (finder-list-matches key))))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
364
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
365 ;; XEmacs change
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
366 (defun finder-mouse-select (ev)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
367 (interactive "e")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
368 (goto-char (event-point ev))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
369 (finder-select))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
370
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
371 ;; XEmacs change
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
372 ;;;###autoload
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
373 (defun finder-by-keyword ()
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
374 "Find packages matching a given keyword."
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
375 (interactive)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
376 (finder-mode)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
377 (finder-list-keywords))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
378
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
379 (defun finder-mode ()
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
380 "Major mode for browsing package documentation.
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
381 \\<finder-mode-map>
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
382 \\[finder-select] more help for the item on the current line
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
383 \\[finder-edit] edit Lisp library in another window
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
384 \\[finder-view] view Lisp library in another window
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
385 \\[finder-exit] exit Finder mode and kill the Finder buffer.
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
386 "
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
387 (interactive)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
388 (pop-to-buffer "*Finder*")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
389 ;; XEmacs change
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
390 (setq buffer-read-only nil
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
391 mode-motion-hook 'mode-motion-highlight-line)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
392 (erase-buffer)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
393 (use-local-map finder-mode-map)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
394 (set-syntax-table emacs-lisp-mode-syntax-table)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
395 (setq mode-name "Finder")
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
396 (setq major-mode 'finder-mode)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
397 (make-local-variable 'finder-headmark)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
398 (setq finder-headmark nil))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
399
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
400 (defun finder-summary ()
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
401 "Summarize basic Finder commands."
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
402 (interactive)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
403 (message "%s"
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
404 (substitute-command-keys
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
405 ;; XEmacs change
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
406 "\\<finder-mode-map>\\[finder-select] = select, \\[finder-list-keywords] = keywords, \\[finder-edit] = edit, \\[finder-view] = view, \\[finder-exit] = quit, \\[finder-summary] = help")))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
407
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
408 (defun finder-exit ()
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
409 "Exit Finder mode and kill the buffer."
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
410 (interactive)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
411 ;; XEmacs change
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
412 (or (one-window-p t 0)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
413 (delete-window))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
414 (kill-buffer "*Finder*"))
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
415
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
416 (provide 'finder)
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
417
2997ff5f2aba [xemacs-hg @ 2005-10-09 10:41:37 by adrian]
adrian
parents: 1315
diff changeset
418 ;;; finder.el ends here