annotate lisp/packages/completion.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children ac2d302a0011
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; completion.el --- dynamic word-completion code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;; Copyright (C) 1990, 1993, 1995 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; Maintainer: FSF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Keywords: abbrev
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Author: Jim Salem <salem@think.com> of Thinking Machines Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; (ideas suggested by Brewster Kahle)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;; Synched up with: FSF 19.30.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;;; What to put in .emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;;;-----------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;; (load "completion")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;;; (initialize-completions)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;;;---------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;;; Documentation [Slightly out of date]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;;;---------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;;; (also check the documentation string of the functions)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;;; Introduction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;;;---------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;;; After you type a few characters, pressing the "complete" key inserts
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;;; the rest of the word you are likely to type.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;;; This watches all the words that you type and remembers them. When
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;;; typing a new word, pressing "complete" (meta-return) "completes" the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;;; word by inserting the most recently used word that begins with the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;;; same characters. If you press meta-return repeatedly, it cycles
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;;; through all the words it knows about.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;;; If you like the completion then just continue typing, it is as if you
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;;; entered the text by hand. If you want the inserted extra characters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;;; to go away, type control-w or delete. More options are described below.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;;; The guesses are made in the order of the most recently "used". Typing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;;; in a word and then typing a separator character (such as a space) "uses"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;;; the word. So does moving a cursor over the word. If no words are found,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;;; it uses an extended version of the dabbrev style completion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 ;;; You automatically save the completions you use to a file between
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;;; sessions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;;; Completion enables programmers to enter longer, more descriptive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;;; variable names while typing fewer keystrokes than they normally would.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 ;;; Full documentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 ;;;---------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;;; A "word" is any string containing characters with either word or symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ;;; syntax. [E.G. Any alphanumeric string with hyphens, underscores, etc.]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ;;; Unless you change the constants, you must type at least three characters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;;; for the word to be recognized. Only words longer than 6 characters are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 ;;; saved.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 ;;; When you load this file, completion will be on. I suggest you use the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 ;;; compiled version (because it is noticeably faster).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ;;; M-X completion-mode toggles whether or not new words are added to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 ;;; database by changing the value of enable-completion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 ;;; SAVING/LOADING COMPLETIONS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 ;;; Completions are automatically saved from one session to another
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 ;;; (unless save-completions-flag or enable-completion is nil).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ;;; Loading this file (or calling initialize-completions) causes EMACS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 ;;; to load a completions database for a saved completions file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 ;;; (default: ~/.completions). When you exit, EMACS saves a copy of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 ;;; completions that you
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 ;;; often use. When you next start, EMACS loads in the saved completion file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 ;;; The number of completions saved depends loosely on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 ;;; *saved-completions-decay-factor*. Completions that have never been
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 ;;; inserted via "complete" are not saved. You are encouraged to experiment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 ;;; with different functions (see compute-completion-min-num-uses).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 ;;; Some completions are permanent and are always saved out. These
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 ;;; completions have their num-uses slot set to T. Use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 ;;; add-permanent-completion to do this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 ;;; Completions are saved only if enable-completion is T. The number of old
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 ;;; versions kept of the saved completions file is controlled by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 ;;; completions-file-versions-kept.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 ;;; COMPLETE KEY OPTIONS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 ;;; The complete function takes a numeric arguments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 ;;; control-u :: leave the point at the beginning of the completion rather
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 ;;; than the middle.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 ;;; a number :: rotate through the possible completions by that amount
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 ;;; `-' :: same as -1 (insert previous completion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 ;;; HOW THE DATABASE IS MAINTAINED
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 ;;; <write>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 ;;; UPDATING THE DATABASE MANUALLY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 ;;; m-x kill-completion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 ;;; kills the completion at point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 ;;; m-x add-completion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 ;;; m-x add-permanent-completion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 ;;; UPDATING THE DATABASE FROM A SOURCE CODE FILE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 ;;; m-x add-completions-from-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 ;;; Parses all the definition names from a C or LISP mode buffer and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 ;;; adds them to the completion database.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 ;;; m-x add-completions-from-lisp-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 ;;; Parses all the definition names from a C or Lisp mode file and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 ;;; adds them to the completion database.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 ;;; UPDATING THE DATABASE FROM A TAGS TABLE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 ;;; m-x add-completions-from-tags-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 ;;; Adds completions from the current tags-table-buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 ;;; HOW A COMPLETION IS FOUND
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 ;;; <write>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 ;;; STRING CASING
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 ;;; Completion is string case independent if case-fold-search has its
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 ;;; normal default of T. Also when the completion is inserted the case of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 ;;; entry is coerced appropriately.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 ;;; [E.G. APP --> APPROPRIATELY app --> appropriately
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 ;;; App --> Appropriately]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 ;;; INITIALIZATION
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 ;;; The form `(initialize-completions)' initializes the completion system by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 ;;; trying to load in the user's completions. After the first cal, further
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 ;;; calls have no effect so one should be careful not to put the form in a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 ;;; site's standard site-init file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 ;;;---------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 ;;;---------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 ;;; Functions you might like to call
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 ;;;---------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 ;;; add-completion string &optional num-uses
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 ;;; Adds a new string to the database
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 ;;; add-permanent-completion string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 ;;; Adds a new string to the database with num-uses = T
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 ;;; kill-completion string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 ;;; Kills the completion from the database.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 ;;; clear-all-completions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 ;;; Clears the database
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 ;;; list-all-completions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 ;;; Returns a list of all completions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 ;;; next-completion string &optional index
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 ;;; Returns a completion entry that starts with string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 ;;; find-exact-completion string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 ;;; Returns a completion entry that exactly matches string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 ;;; complete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 ;;; Inserts a completion at point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 ;;; initialize-completions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 ;;; Loads the completions file and sets up so that exiting emacs will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 ;;; save them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 ;;; save-completions-to-file &optional filename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 ;;; load-completions-from-file &optional filename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 ;;; Other functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 ;;; get-completion-list string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 ;;; These things are for manipulating the structure
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 ;;; make-completion string num-uses
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 ;;; completion-num-uses completion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 ;;; completion-string completion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 ;;; set-completion-num-uses completion num-uses
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 ;;; set-completion-string completion string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 ;;; To Do :: (anybody ?)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 ;;; Implement Lookup and keyboard interface in C
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 ;;; Add package prefix smarts (for Common Lisp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 ;;; Add autoprompting of possible completions after every keystroke (fast
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 ;;; terminals only !)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 ;;; Add doc. to texinfo
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 ;;; Change Log:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 ;;; Sometime in '84 Brewster implemented a somewhat buggy version for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 ;;; Symbolics LISPMs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 ;;; Jan. '85 Jim became enamored of the idea and implemented a faster,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 ;;; more robust version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 ;;; With input from many users at TMC, (rose, craig, and gls come to mind),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 ;;; the current style of interface was developed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 ;;; 9/87, Jim and Brewster took terminals home. Yuck. After
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 ;;; complaining for a while Brewester implemented a subset of the current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 ;;; LISPM version for GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 ;;; 8/88 After complaining for a while (and with sufficient
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 ;;; promised rewards), Jim reimplemented a version of GNU completion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 ;;; superior to that of the LISPM version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 ;;; Acknowledgements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 ;;; Cliff Lasser (cal@think.com), Kevin Herbert (kph@cisco.com),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 ;;; eero@media-lab, kgk@cs.brown.edu, jla@ai.mit.edu,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 ;;; Change Log
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 ;;; From version 9 to 10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 ;;; - Allowance for non-integral *completion-version* nos.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 ;;; - Fix cmpl-apply-as-top-level for keyboard macros
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 ;;; - Fix broken completion merging (in save-completions-to-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 ;;; - More misc. fixes for version 19.0 of emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 ;;; From Version 8 to 9
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 ;;; - Ported to version 19.0 of emacs (backcompatible with version 18)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 ;;; - Added add-completions-from-tags-table (with thanks to eero@media-lab)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 ;;; From Version 7 to 8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 ;;; - Misc. changes to comments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 ;;; - new completion key bindings: c-x o, M->, M-<, c-a, c-e
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 ;;; - cdabbrev now checks all the visible window buffers and the "other buffer"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 ;;; - `%' is now a symbol character rather than a separator (except in C mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 ;;; From Version 6 to 7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 ;;; - Fixed bug with saving out .completion file the first time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 ;;; From Version 5 to 6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 ;;; - removed statistics recording
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 ;;; - reworked advise to handle autoloads
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 ;;; - Fixed fortran mode support
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 ;;; - Added new cursor motion triggers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 ;;; From Version 4 to 5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 ;;; - doesn't bother saving if nothing has changed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 ;;; - auto-save if haven't used for a 1/2 hour
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 ;;; - save period extended to two weeks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 ;;; - minor fix to capitalization code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 ;;; - added *completion-auto-save-period* to variables recorded.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 ;;; - added reenter protection to cmpl-record-statistics-filter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 ;;; - added backup protection to save-completions-to-file (prevents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 ;;; problems with disk full errors)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 ;;;---------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 ;;; User changeable parameters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 ;;;---------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (defvar enable-completion t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 "*Non-nil means enable recording and saving of completions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 If nil, no new words added to the database or saved to the init file.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (defvar save-completions-flag t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 "*Non-nil means save most-used completions when exiting Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 See also `saved-completions-retention-time'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (defvar save-completions-file-name "~/.completions"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 "*The filename to save completions to.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (defvar save-completions-retention-time 336
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 "*Discard a completion if unused for this many hours.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 \(1 day = 24, 1 week = 168). If this is 0, non-permanent completions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 will not be saved unless these are used. Default is two weeks.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (defvar completion-on-separator-character nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 "*Non-nil means separator characters mark previous word as used.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 This means the word will be saved as a completion.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (defvar completions-file-versions-kept kept-new-versions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 "*Number of versions to keep for the saved completions file.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (defvar completion-prompt-speed-threshold 4800
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 "*Minimum output speed at which to display next potential completion.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (defvar completion-cdabbrev-prompt-flag nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 "*If non-nil, the next completion prompt does a cdabbrev search.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 This can be time consuming.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (defvar completion-search-distance 15000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 "*How far to search in the buffer when looking for completions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 In number of characters. If nil, search the whole buffer.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (defvar completions-merging-modes '(lisp c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 "*List of modes {`c' or `lisp'} for automatic completions merging.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 Definitions from visited files which have these modes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 are automatically added to the completion database.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 ;;;(defvar *record-cmpl-statistics-p* nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 ;;; "*If non-nil, record completion statistics.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 ;;;(defvar *completion-auto-save-period* 1800
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 ;;; "*The period in seconds to wait for emacs to be idle before autosaving
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 ;;;the completions. Default is a 1/2 hour.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (defconst completion-min-length nil ;; defined below in eval-when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 "*The minimum length of a stored completion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 DON'T CHANGE WITHOUT RECOMPILING ! This is used by macros.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (defconst completion-max-length nil ;; defined below in eval-when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 "*The maximum length of a stored completion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 DON'T CHANGE WITHOUT RECOMPILING ! This is used by macros.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (defconst completion-prefix-min-length nil ;; defined below in eval-when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 "The minimum length of a completion search string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 DON'T CHANGE WITHOUT RECOMPILING ! This is used by macros.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (defmacro eval-when-compile-load-eval (&rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 ;; eval everything before expanding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (mapcar 'eval body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (cons 'progn body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (eval-when-compile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (defvar completion-gensym-counter 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (defun completion-gensym (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 "Generate a new uninterned symbol.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 The name is made by appending a number to PREFIX, default \"G\"."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (let ((prefix (if (stringp arg) arg "G"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (num (if (integerp arg) arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 (prog1 completion-gensym-counter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (setq completion-gensym-counter (1+ completion-gensym-counter))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (make-symbol (format "%s%d" prefix num)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (defmacro completion-dolist (spec &rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 "(completion-dolist (VAR LIST [RESULT]) BODY...): loop over a list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 Evaluate BODY with VAR bound to each `car' from LIST, in turn.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 Then evaluate RESULT to get return value, default nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (let ((temp (completion-gensym "--dolist-temp--")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (append (list 'let (list (list temp (nth 1 spec)) (car spec))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (append (list 'while temp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 (list 'setq (car spec) (list 'car temp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 body (list (list 'setq temp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 (list 'cdr temp)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (if (cdr (cdr spec))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 (cons (list 'setq (car spec) nil) (cdr (cdr spec)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 '(nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 (defun completion-eval-when ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 (eval-when-compile-load-eval
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 ;; These vars. are defined at both compile and load time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 (setq completion-min-length 6)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (setq completion-max-length 200)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (setq completion-prefix-min-length 3)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 (completion-eval-when)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 ;;;---------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 ;;; Internal Variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 ;;;---------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 (defvar cmpl-initialized-p nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 "Set to t when the completion system is initialized.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 Indicates that the old completion file has been read in.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 (defvar cmpl-completions-accepted-p nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 "Set to t as soon as the first completion has been accepted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 Used to decide whether to save completions.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 (defvar cmpl-preceding-syntax)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (defvar completion-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 ;;;---------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 ;;; Low level tools
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 ;;;---------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 ;;; Misc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (defun minibuffer-window-selected-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 "True iff the current window is the minibuffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (window-minibuffer-p (selected-window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 ;; This used to be `(eval form)'. Eval FORM at run time now.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 (defmacro cmpl-read-time-eval (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 ;;; String case coercion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (defun cmpl-string-case-type (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 "Returns :capitalized, :up, :down, :mixed, or :neither."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (let ((case-fold-search nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 (cond ((string-match "[a-z]" string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 (cond ((string-match "[A-Z]" string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (cond ((and (> (length string) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 (null (string-match "[A-Z]" string 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 ':capitalized)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 ':mixed)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 (t ':down)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (cond ((string-match "[A-Z]" string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 ':up)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (t ':neither))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 ;;; Tests -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 ;;; (cmpl-string-case-type "123ABCDEF456") --> :up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 ;;; (cmpl-string-case-type "123abcdef456") --> :down
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 ;;; (cmpl-string-case-type "123aBcDeF456") --> :mixed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 ;;; (cmpl-string-case-type "123456") --> :neither
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 ;;; (cmpl-string-case-type "Abcde123") --> :capitalized
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (defun cmpl-coerce-string-case (string case-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 (cond ((eq case-type ':down) (downcase string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 ((eq case-type ':up) (upcase string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 ((eq case-type ':capitalized)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 (setq string (downcase string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 (aset string 0 (logand ?\337 (aref string 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (t string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (defun cmpl-merge-string-cases (string-to-coerce given-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (let ((string-case-type (cmpl-string-case-type string-to-coerce))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 (cond ((memq string-case-type '(:down :up :capitalized))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 ;; Found string is in a standard case. Coerce to a type based on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 ;; the given string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (cmpl-coerce-string-case string-to-coerce
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 (cmpl-string-case-type given-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 ;; If the found string is in some unusual case, just insert it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 ;; as is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 string-to-coerce)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 ;;; Tests -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 ;;; (cmpl-merge-string-cases "AbCdEf456" "abc") --> AbCdEf456
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 ;;; (cmpl-merge-string-cases "abcdef456" "ABC") --> ABCDEF456
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 ;;; (cmpl-merge-string-cases "ABCDEF456" "Abc") --> Abcdef456
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 ;;; (cmpl-merge-string-cases "ABCDEF456" "abc") --> abcdef456
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (defun cmpl-hours-since-origin ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 (let ((time (current-time)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (truncate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 (+ (* (/ (car time) 3600.0) (lsh 1 16))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (/ (nth 2 time) 3600.0)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 ;;;---------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 ;;; "Symbol" parsing functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 ;;;---------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 ;;; The functions symbol-before-point, symbol-under-point, etc. quickly return
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 ;;; an appropriate symbol string. The strategy is to temporarily change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 ;;; the syntax table to enable fast symbol searching. There are three classes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 ;;; of syntax in these "symbol" syntax tables ::
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 ;;; syntax (?_) - "symbol" chars (e.g. alphanumerics)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 ;;; syntax (?w) - symbol chars to ignore at end of words (e.g. period).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 ;;; syntax (? ) - everything else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 ;;; Thus by judicious use of scan-sexps and forward-word, we can get
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 ;;; the word we want relatively fast and without consing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 ;;; Why do we need a separate category for "symbol chars to ignore at ends" ?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 ;;; For example, in LISP we want starting :'s trimmed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 ;;; so keyword argument specifiers also define the keyword completion. And,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 ;;; for example, in C we want `.' appearing in a structure ref. to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 ;;; be kept intact in order to store the whole structure ref.; however, if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 ;;; it appears at the end of a symbol it should be discarded because it is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 ;;; probably used as a period.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 ;;; Here is the default completion syntax ::
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 ;;; Symbol chars :: A-Z a-z 0-9 @ / \ * + ~ $ < > %
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 ;;; Symbol chars to ignore at ends :: _ : . -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 ;;; Separator chars. :: <tab> <space> ! ^ & ( ) = ` | { } [ ] ; " ' #
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 ;;; , ? <Everything else>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 ;;; Mode specific differences and notes ::
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 ;;; LISP diffs ->
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 ;;; Symbol chars :: ! & ? = ^
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 ;;; C diffs ->
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 ;;; Separator chars :: + * / : %
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 ;;; A note on the hyphen (`-'). Perhaps the hyphen should also be a separator
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 ;;; char., however, we wanted to have completion symbols include pointer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 ;;; references. For example, "foo->bar" is a symbol as far as completion is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 ;;; concerned.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 ;;; FORTRAN diffs ->
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 ;;; Separator chars :: + - * / :
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 ;;; Pathname diffs ->
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 ;;; Symbol chars :: .
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 ;;; Of course there is no pathname "mode" and in fact we have not implemented
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 ;;; this table. However, if there was such a mode, this is what it would look
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 ;;; like.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 ;;; Table definitions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 (defun cmpl-make-standard-completion-syntax-table ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 (let ((table (make-vector 256 0)) ;; default syntax is whitespace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 i)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 ;; alpha chars
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 (setq i 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 (while (< i 26)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 (modify-syntax-entry (+ ?a i) "_" table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 (modify-syntax-entry (+ ?A i) "_" table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 (setq i (1+ i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 ;; digit chars.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 (setq i 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 (while (< i 10)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 (modify-syntax-entry (+ ?0 i) "_" table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 (setq i (1+ i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 ;; Other ones
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 (let ((symbol-chars '(?@ ?/ ?\\ ?* ?+ ?~ ?$ ?< ?> ?%))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 (symbol-chars-ignore '(?_ ?- ?: ?.))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 (completion-dolist (char symbol-chars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 (modify-syntax-entry char "_" table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 (completion-dolist (char symbol-chars-ignore)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 (modify-syntax-entry char "w" table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 (defconst cmpl-standard-syntax-table (cmpl-make-standard-completion-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 (defun cmpl-make-lisp-completion-syntax-table ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 (let ((table (copy-syntax-table cmpl-standard-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 (symbol-chars '(?! ?& ?? ?= ?^))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 (completion-dolist (char symbol-chars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 (modify-syntax-entry char "_" table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 (defun cmpl-make-c-completion-syntax-table ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 (let ((table (copy-syntax-table cmpl-standard-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 (separator-chars '(?+ ?* ?/ ?: ?%))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 (completion-dolist (char separator-chars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 (modify-syntax-entry char " " table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 (defun cmpl-make-fortran-completion-syntax-table ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 (let ((table (copy-syntax-table cmpl-standard-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 (separator-chars '(?+ ?- ?* ?/ ?:))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 (completion-dolist (char separator-chars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 (modify-syntax-entry char " " table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 (defconst cmpl-lisp-syntax-table (cmpl-make-lisp-completion-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 (defconst cmpl-c-syntax-table (cmpl-make-c-completion-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 (defconst cmpl-fortran-syntax-table (cmpl-make-fortran-completion-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 (defvar cmpl-syntax-table cmpl-standard-syntax-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 "This variable holds the current completion syntax table.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 (make-variable-buffer-local 'cmpl-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 ;;; Installing the appropriate mode tables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 (add-hook 'lisp-mode-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 '(lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 (setq cmpl-syntax-table cmpl-lisp-syntax-table)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 (add-hook 'c-mode-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 '(lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 (setq cmpl-syntax-table cmpl-c-syntax-table)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 (add-hook 'fortran-mode-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 '(lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 (setq cmpl-syntax-table cmpl-fortran-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 (completion-setup-fortran-mode)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 ;;; Symbol functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 (defvar cmpl-symbol-start nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 "Holds first character of symbol, after any completion symbol function.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 (defvar cmpl-symbol-end nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 "Holds last character of symbol, after any completion symbol function.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 ;;; These are temp. vars. we use to avoid using let.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 ;;; Why ? Small speed improvement.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 (defvar cmpl-saved-syntax nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 (defvar cmpl-saved-point nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 (defun symbol-under-point ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 "Returns the symbol that the point is currently on.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 But only if it is longer than `completion-min-length'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 (setq cmpl-saved-syntax (syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 (set-syntax-table cmpl-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 ;; Cursor is on following-char and after preceding-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 ((memq (char-syntax (following-char)) '(?w ?_))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 (setq cmpl-saved-point (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 cmpl-symbol-start (scan-sexps (1+ cmpl-saved-point) -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 cmpl-symbol-end (scan-sexps cmpl-saved-point 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 ;; remove chars to ignore at the start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 (cond ((= (char-syntax (char-after cmpl-symbol-start)) ?w)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 (goto-char cmpl-symbol-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 (forward-word 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 (setq cmpl-symbol-start (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 (goto-char cmpl-saved-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 ;; remove chars to ignore at the end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 (cond ((= (char-syntax (char-after (1- cmpl-symbol-end))) ?w)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 (goto-char cmpl-symbol-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 (forward-word -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 (setq cmpl-symbol-end (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 (goto-char cmpl-saved-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 ;; restore state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 (set-syntax-table cmpl-saved-syntax)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 ;; Return completion if the length is reasonable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 (if (and (<= (cmpl-read-time-eval completion-min-length)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 (- cmpl-symbol-end cmpl-symbol-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 (<= (- cmpl-symbol-end cmpl-symbol-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 (cmpl-read-time-eval completion-max-length)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 (buffer-substring cmpl-symbol-start cmpl-symbol-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 ;; restore table if no symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 (set-syntax-table cmpl-saved-syntax)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 ;;; tests for symbol-under-point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 ;;; `^' indicates cursor pos. where value is returned
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 ;;; simple-word-test
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 ;;; ^^^^^^^^^^^^^^^^ --> simple-word-test
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 ;;; _harder_word_test_
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 ;;; ^^^^^^^^^^^^^^^^^^ --> harder_word_test
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 ;;; .___.______.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 ;;; --> nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 ;;; /foo/bar/quux.hello
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 ;;; ^^^^^^^^^^^^^^^^^^^ --> /foo/bar/quux.hello
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 (defun symbol-before-point ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 "Returns a string of the symbol immediately before point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 Returns nil if there isn't one longer than `completion-min-length'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 ;; This is called when a word separator is typed so it must be FAST !
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 (setq cmpl-saved-syntax (syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 (set-syntax-table cmpl-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 ;; Cursor is on following-char and after preceding-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 (cond ((= (setq cmpl-preceding-syntax (char-syntax (preceding-char))) ?_)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 ;; No chars. to ignore at end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 (setq cmpl-symbol-end (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 cmpl-symbol-start (scan-sexps (1+ cmpl-symbol-end) -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 ;; remove chars to ignore at the start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 (cond ((= (char-syntax (char-after cmpl-symbol-start)) ?w)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 (goto-char cmpl-symbol-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 (forward-word 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 (setq cmpl-symbol-start (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 (goto-char cmpl-symbol-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 ;; restore state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 (set-syntax-table cmpl-saved-syntax)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 ;; return value if long enough
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 (if (>= cmpl-symbol-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 (+ cmpl-symbol-start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 (cmpl-read-time-eval completion-min-length)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 (buffer-substring cmpl-symbol-start cmpl-symbol-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 ((= cmpl-preceding-syntax ?w)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 ;; chars to ignore at end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 (setq cmpl-saved-point (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 cmpl-symbol-start (scan-sexps (1+ cmpl-saved-point) -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 ;; take off chars. from end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 (forward-word -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 (setq cmpl-symbol-end (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 ;; remove chars to ignore at the start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 (cond ((= (char-syntax (char-after cmpl-symbol-start)) ?w)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 (goto-char cmpl-symbol-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 (forward-word 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 (setq cmpl-symbol-start (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 ;; restore state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 (goto-char cmpl-saved-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 (set-syntax-table cmpl-saved-syntax)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 ;; Return completion if the length is reasonable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 (if (and (<= (cmpl-read-time-eval completion-min-length)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 (- cmpl-symbol-end cmpl-symbol-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 (<= (- cmpl-symbol-end cmpl-symbol-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 (cmpl-read-time-eval completion-max-length)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 (buffer-substring cmpl-symbol-start cmpl-symbol-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 ;; restore table if no symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 (set-syntax-table cmpl-saved-syntax)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 ;;; tests for symbol-before-point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 ;;; `^' indicates cursor pos. where value is returned
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 ;;; simple-word-test
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 ;;; ^ --> nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 ;;; ^ --> nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 ;;; ^ --> simple-w
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 ;;; ^ --> simple-word-test
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 ;;; _harder_word_test_
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 ;;; ^ --> harder_word_test
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 ;;; ^ --> harder_word_test
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 ;;; ^ --> harder
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 ;;; .___....
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 ;;; --> nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 (defun symbol-under-or-before-point ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 ;;; This could be made slightly faster but it is better to avoid
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 ;;; copying all the code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 ;;; However, it is only used by the completion string prompter.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 ;;; If it comes into common use, it could be rewritten.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 (setq cmpl-saved-syntax (syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 (set-syntax-table cmpl-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 (cond ((memq (char-syntax (following-char)) '(?w ?_))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 (set-syntax-table cmpl-saved-syntax)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 (symbol-under-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 (set-syntax-table cmpl-saved-syntax)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 (symbol-before-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 (defun symbol-before-point-for-complete ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 ;; "Returns a string of the symbol immediately before point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 ;; or nil if there isn't one. Like symbol-before-point but doesn't trim the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 ;; end chars."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 ;; Cursor is on following-char and after preceding-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 (setq cmpl-saved-syntax (syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 (set-syntax-table cmpl-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 (cond ((memq (setq cmpl-preceding-syntax (char-syntax (preceding-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 '(?_ ?w))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 (setq cmpl-symbol-end (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 cmpl-symbol-start (scan-sexps (1+ cmpl-symbol-end) -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 ;; remove chars to ignore at the start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 (cond ((= (char-syntax (char-after cmpl-symbol-start)) ?w)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 (goto-char cmpl-symbol-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 (forward-word 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 (setq cmpl-symbol-start (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 (goto-char cmpl-symbol-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 ;; restore state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 (set-syntax-table cmpl-saved-syntax)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 ;; Return completion if the length is reasonable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 (if (and (<= (cmpl-read-time-eval
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 completion-prefix-min-length)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 (- cmpl-symbol-end cmpl-symbol-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 (<= (- cmpl-symbol-end cmpl-symbol-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 (cmpl-read-time-eval completion-max-length)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 (buffer-substring cmpl-symbol-start cmpl-symbol-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 ;; restore table if no symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 (set-syntax-table cmpl-saved-syntax)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 ;;; tests for symbol-before-point-for-complete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 ;;; `^' indicates cursor pos. where value is returned
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 ;;; simple-word-test
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 ;;; ^ --> nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 ;;; ^ --> nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 ;;; ^ --> simple-w
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 ;;; ^ --> simple-word-test
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 ;;; _harder_word_test_
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 ;;; ^ --> harder_word_test
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 ;;; ^ --> harder_word_test_
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 ;;; ^ --> harder_
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 ;;; .___....
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 ;;; --> nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 ;;;---------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 ;;; Statistics Recording
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 ;;;---------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 ;;; Note that the guts of this has been turned off. The guts
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 ;;; are in completion-stats.el.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 ;;; Conditionalizing code on *record-cmpl-statistics-p*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 ;;; All statistics code outside this block should use this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 (defmacro cmpl-statistics-block (&rest body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 ;;; "Only executes body if we are recording statistics."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 ;;; (list 'cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 ;;; (list* '*record-cmpl-statistics-p* body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 ;;; ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 ;;; Completion Sources
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 ;; ID numbers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 (defconst cmpl-source-unknown 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 (defconst cmpl-source-init-file 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 (defconst cmpl-source-file-parsing 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 (defconst cmpl-source-separator 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 (defconst cmpl-source-cursor-moves 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 (defconst cmpl-source-interactive 5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 (defconst cmpl-source-cdabbrev 6)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 (defconst num-cmpl-sources 7)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 (defvar current-completion-source cmpl-source-unknown)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 ;;;---------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 ;;; Completion Method #2: dabbrev-expand style
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 ;;;---------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 ;;; This method is used if there are no useful stored completions. It is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 ;;; based on dabbrev-expand with these differences :
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 ;;; 1) Faster (we don't use regexps)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 ;;; 2) case coercion handled correctly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 ;;; This is called cdabbrev to differentiate it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 ;;; We simply search backwards through the file looking for words which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 ;;; start with the same letters we are trying to complete.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 (defvar cdabbrev-completions-tried nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 ;;; "A list of all the cdabbrev completions since the last reset.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 (defvar cdabbrev-current-point 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 ;;; "The current point position the cdabbrev search is at.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 (defvar cdabbrev-current-window nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 ;;; "The current window we are looking for cdabbrevs in. T if looking in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 ;;; (other-buffer), NIL if no more cdabbrevs.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 (defvar cdabbrev-wrapped-p nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 ;;; "T if the cdabbrev search has wrapped around the file.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 (defvar cdabbrev-abbrev-string "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 (defvar cdabbrev-start-point 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 (defvar cdabbrev-stop-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 ;;; Test strings for cdabbrev
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 ;;; cdat-upcase ;;same namestring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 ;;; CDAT-UPCASE ;;ok
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 ;;; cdat2 ;;too short
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 ;;; cdat-1-2-3-4 ;;ok
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 ;;; a-cdat-1 ;;doesn't start correctly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 ;;; cdat-simple ;;ok
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 (defun reset-cdabbrev (abbrev-string &optional initial-completions-tried)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 "Resets the cdabbrev search to search for abbrev-string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 INITIAL-COMPLETIONS-TRIED is a list of downcased strings to ignore
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 during the search."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 (setq cdabbrev-abbrev-string abbrev-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 cdabbrev-completions-tried
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 (cons (downcase abbrev-string) initial-completions-tried)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 (reset-cdabbrev-window t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 (defun set-cdabbrev-buffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 ;; cdabbrev-current-window must not be NIL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 (set-buffer (if (eq cdabbrev-current-window t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 (other-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 (window-buffer cdabbrev-current-window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 (defun reset-cdabbrev-window (&optional initializep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 "Resets the cdabbrev search to search for abbrev-string."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 ;; Set the window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 (cond (initializep
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 (setq cdabbrev-current-window (selected-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 ((eq cdabbrev-current-window t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 ;; Everything has failed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 (setq cdabbrev-current-window nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 (cdabbrev-current-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 (setq cdabbrev-current-window (next-window cdabbrev-current-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 (if (eq cdabbrev-current-window (selected-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 ;; No more windows, try other buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 (setq cdabbrev-current-window t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 (if cdabbrev-current-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 (set-cdabbrev-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 (setq cdabbrev-current-point (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 cdabbrev-start-point cdabbrev-current-point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 cdabbrev-stop-point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 (if completion-search-distance
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 (max (point-min)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923 (- cdabbrev-start-point completion-search-distance))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 cdabbrev-wrapped-p nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 (defun next-cdabbrev ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 "Return the next possible cdabbrev expansion or nil if there isn't one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 `reset-cdabbrev' must've been called already.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 This is sensitive to `case-fold-search'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 ;; note that case-fold-search affects the behavior of this function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 ;; Bug: won't pick up an expansion that starts at the top of buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 (if cdabbrev-current-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 (let (saved-point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 saved-syntax
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 (expansion nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 downcase-expansion tried-list syntax saved-point-2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 ;; Switch to current completion buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943 (set-cdabbrev-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 ;; Save current buffer state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 (setq saved-point (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946 saved-syntax (syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947 ;; Restore completion state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948 (set-syntax-table cmpl-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949 (goto-char cdabbrev-current-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 ;; Loop looking for completions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 (while
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 ;; This code returns t if it should loop again
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954 (;; search for the string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955 (search-backward cdabbrev-abbrev-string cdabbrev-stop-point t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 ;; return nil if the completion is valid
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 (not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958 (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959 ;; does it start with a separator char ?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 (or (= (setq syntax (char-syntax (preceding-char))) ? )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961 (and (= syntax ?w)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962 ;; symbol char to ignore at end. Are we at end ?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964 (setq saved-point-2 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 (forward-word -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967 (= (char-syntax (preceding-char)) ? )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968 (goto-char saved-point-2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 ;; is the symbol long enough ?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971 (setq expansion (symbol-under-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 ;; have we not tried this one before
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974 ;; See if we've already used it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 (setq tried-list cdabbrev-completions-tried
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 downcase-expansion (downcase expansion))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977 (while (and tried-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 (not (string-equal downcase-expansion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979 (car tried-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980 ;; Already tried, don't choose this one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 (setq tried-list (cdr tried-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983 ;; at this point tried-list will be nil if this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984 ;; expansion has not yet been tried
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 (if tried-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986 (setq expansion nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989 ;; search failed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990 (cdabbrev-wrapped-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991 ;; If already wrapped, then we've failed completely
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994 ;; need to wrap
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995 (goto-char (setq cdabbrev-current-point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 (if completion-search-distance
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997 (min (point-max) (+ cdabbrev-start-point completion-search-distance))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998 (point-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000 (setq cdabbrev-wrapped-p t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002 ;; end of while loop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003 (cond (expansion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 ;; successful
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 (setq cdabbrev-completions-tried
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006 (cons downcase-expansion cdabbrev-completions-tried)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007 cdabbrev-current-point (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009 (set-syntax-table saved-syntax)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 (goto-char saved-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 ;; If no expansion, go to next window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013 (cond (expansion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014 (t (reset-cdabbrev-window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015 (next-cdabbrev))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017 ;;; The following must be eval'd in the minibuffer ::
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 ;;; (reset-cdabbrev "cdat")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019 ;;; (next-cdabbrev) --> "cdat-simple"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020 ;;; (next-cdabbrev) --> "cdat-1-2-3-4"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021 ;;; (next-cdabbrev) --> "CDAT-UPCASE"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022 ;;; (next-cdabbrev) --> "cdat-wrapping"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023 ;;; (next-cdabbrev) --> "cdat_start_sym"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024 ;;; (next-cdabbrev) --> nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025 ;;; (next-cdabbrev) --> nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026 ;;; (next-cdabbrev) --> nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1027
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028 ;;; _cdat_start_sym
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029 ;;; cdat-wrapping
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032 ;;;---------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033 ;;; Completion Database
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034 ;;;---------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036 ;;; We use two storage modes for the two search types ::
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037 ;;; 1) Prefix {cmpl-prefix-obarray} for looking up possible completions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1038 ;;; Used by search-completion-next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1039 ;;; the value of the symbol is nil or a cons of head and tail pointers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040 ;;; 2) Interning {cmpl-obarray} to see if it's in the database
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1041 ;;; Used by find-exact-completion, completion-in-database-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042 ;;; The value of the symbol is the completion entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044 ;;; bad things may happen if this length is changed due to the way
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045 ;;; GNU implements obarrays
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1046 (defconst cmpl-obarray-length 511)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1047
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1048 (defvar cmpl-prefix-obarray (make-vector cmpl-obarray-length 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1049 "An obarray used to store the downcased completion prefixes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1050 Each symbol is bound to a list of completion entries.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1051
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1052 (defvar cmpl-obarray (make-vector cmpl-obarray-length 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1053 "An obarray used to store the downcased completions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1054 Each symbol is bound to a single completion entry.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1055
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1056 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1057 ;;; Completion Entry Structure Definition
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1058 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1059
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1060 ;;; A completion entry is a LIST of string, prefix-symbol num-uses, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1061 ;;; last-use-time (the time the completion was last used)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1062 ;;; last-use-time is T if the string should be kept permanently
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1063 ;;; num-uses is incremented everytime the completion is used.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1064
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1065 ;;; We chose lists because (car foo) is faster than (aref foo 0) and the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1066 ;;; creation time is about the same.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1067
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1068 ;;; READER MACROS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1069
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1070 (defmacro completion-string (completion-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1071 (list 'car completion-entry))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1072
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1073 (defmacro completion-num-uses (completion-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1074 ;; "The number of times it has used. Used to decide whether to save
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1075 ;; it."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1076 (list 'car (list 'cdr completion-entry)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1077
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1078 (defmacro completion-last-use-time (completion-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1079 ;; "The time it was last used. In hours since origin. Used to decide
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1080 ;; whether to save it. T if one should always save it."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1081 (list 'nth 2 completion-entry))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1082
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1083 (defmacro completion-source (completion-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1084 (list 'nth 3 completion-entry))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1086 ;;; WRITER MACROS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087 (defmacro set-completion-string (completion-entry string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1088 (list 'setcar completion-entry string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1089
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1090 (defmacro set-completion-num-uses (completion-entry num-uses)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1091 (list 'setcar (list 'cdr completion-entry) num-uses))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1092
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1093 (defmacro set-completion-last-use-time (completion-entry last-use-time)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1094 (list 'setcar (list 'cdr (list 'cdr completion-entry)) last-use-time))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1095
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1096 ;;; CONSTRUCTOR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1097 (defun make-completion (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1098 "Returns a list of a completion entry."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1099 (list (list string 0 nil current-completion-source)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1101 ;; Obsolete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1102 ;;(defmacro cmpl-prefix-entry-symbol (completion-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1103 ;; (list 'car (list 'cdr completion-entry)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1104
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1105
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1106
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1107 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1108 ;;; Prefix symbol entry definition
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1109 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1110 ;;; A cons of (head . tail)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1112 ;;; READER Macros
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1113
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1114 (defmacro cmpl-prefix-entry-head (prefix-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1115 (list 'car prefix-entry))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1116
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1117 (defmacro cmpl-prefix-entry-tail (prefix-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1118 (list 'cdr prefix-entry))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1119
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1120 ;;; WRITER Macros
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1121
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1122 (defmacro set-cmpl-prefix-entry-head (prefix-entry new-head)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1123 (list 'setcar prefix-entry new-head))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1124
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1125 (defmacro set-cmpl-prefix-entry-tail (prefix-entry new-tail)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1126 (list 'setcdr prefix-entry new-tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1127
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1128 ;;; Constructor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1129
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1130 (defun make-cmpl-prefix-entry (completion-entry-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1131 "Makes a new prefix entry containing only completion-entry."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1132 (cons completion-entry-list completion-entry-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1133
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1134 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1135 ;;; Completion Database - Utilities
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1136 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1137
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1138 (defun clear-all-completions ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1139 "Initializes the completion storage. All existing completions are lost."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1140 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1141 (setq cmpl-prefix-obarray (make-vector cmpl-obarray-length 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1142 (setq cmpl-obarray (make-vector cmpl-obarray-length 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1143 (cmpl-statistics-block
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1144 (record-clear-all-completions))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1145 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1146
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1147 (defvar completions-list-return-value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1148
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1149 (defun list-all-completions ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1150 "Returns a list of all the known completion entries."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1151 (let ((completions-list-return-value nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1152 (mapatoms 'list-all-completions-1 cmpl-prefix-obarray)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1153 completions-list-return-value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1154
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1155 (defun list-all-completions-1 (prefix-symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1156 (if (boundp prefix-symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1157 (setq completions-list-return-value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1158 (append (cmpl-prefix-entry-head (symbol-value prefix-symbol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1159 completions-list-return-value))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1160
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1161 (defun list-all-completions-by-hash-bucket ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1162 "Return list of lists of known completion entries, organized by hash bucket."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1163 (let ((completions-list-return-value nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1164 (mapatoms 'list-all-completions-by-hash-bucket-1 cmpl-prefix-obarray)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1165 completions-list-return-value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1166
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167 (defun list-all-completions-by-hash-bucket-1 (prefix-symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1168 (if (boundp prefix-symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1169 (setq completions-list-return-value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1170 (cons (cmpl-prefix-entry-head (symbol-value prefix-symbol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1171 completions-list-return-value))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1172
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1173
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1174 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1175 ;;; Updating the database
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1176 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1177 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1178 ;;; These are the internal functions used to update the datebase
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1179 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1180 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1181 (defvar completion-to-accept nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1182 ;;"Set to a string that is pending its acceptance."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1183 ;; this checked by the top level reading functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1184
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1185 (defvar cmpl-db-downcase-string nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1186 ;; "Setup by find-exact-completion, etc. The given string, downcased."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1187 (defvar cmpl-db-symbol nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1188 ;; "The interned symbol corresponding to cmpl-db-downcase-string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1189 ;; Set up by cmpl-db-symbol."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1190 (defvar cmpl-db-prefix-symbol nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1191 ;; "The interned prefix symbol corresponding to cmpl-db-downcase-string."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1192 (defvar cmpl-db-entry nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1193 (defvar cmpl-db-debug-p nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1194 "Set to T if you want to debug the database.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1195
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1196 ;;; READS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1197 (defun find-exact-completion (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1198 "Returns the completion entry for string or nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1199 Sets up `cmpl-db-downcase-string' and `cmpl-db-symbol'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1200 (and (boundp (setq cmpl-db-symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1201 (intern (setq cmpl-db-downcase-string (downcase string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1202 cmpl-obarray)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1203 (symbol-value cmpl-db-symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1204 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1205
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1206 (defun find-cmpl-prefix-entry (prefix-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1207 "Returns the prefix entry for string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1208 Sets `cmpl-db-prefix-symbol'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1209 Prefix-string must be exactly `completion-prefix-min-length' long
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1210 and downcased. Sets up `cmpl-db-prefix-symbol'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1211 (and (boundp (setq cmpl-db-prefix-symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1212 (intern prefix-string cmpl-prefix-obarray)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1213 (symbol-value cmpl-db-prefix-symbol)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1214
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1215 (defvar inside-locate-completion-entry nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1216 ;; used to trap lossage in silent error correction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1217
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1218 (defun locate-completion-entry (completion-entry prefix-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1219 "Locates the completion entry.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1220 Returns a pointer to the element before the completion entry or nil if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1221 the completion entry is at the head.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1222 Must be called after `find-exact-completion'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1223 (let ((prefix-list (cmpl-prefix-entry-head prefix-entry))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1224 next-prefix-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1225 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1226 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1227 ((not (eq (car prefix-list) completion-entry))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1228 ;; not already at head
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1229 (while (and prefix-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1230 (not (eq completion-entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1231 (car (setq next-prefix-list (cdr prefix-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1232 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1233 (setq prefix-list next-prefix-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1234 (cond (;; found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1235 prefix-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1236 ;; Didn't find it. Database is messed up.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1237 (cmpl-db-debug-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1238 ;; not found, error if debug mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1239 (error "Completion entry exists but not on prefix list - %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1240 completion-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1241 (inside-locate-completion-entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1242 ;; recursive error: really scrod
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1243 (locate-completion-db-error))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1244 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1245 ;; Patch out
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1246 (set cmpl-db-symbol nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1247 ;; Retry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1248 (locate-completion-entry-retry completion-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1249 ))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1250
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1251 (defun locate-completion-entry-retry (old-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1252 (let ((inside-locate-completion-entry t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1253 (add-completion (completion-string old-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1254 (completion-num-uses old-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1255 (completion-last-use-time old-entry))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1256 (let* ((cmpl-entry (find-exact-completion (completion-string old-entry)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1257 (pref-entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1258 (if cmpl-entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1259 (find-cmpl-prefix-entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1260 (substring cmpl-db-downcase-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1261 0 completion-prefix-min-length))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1262 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1263 (if (and cmpl-entry pref-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1264 ;; try again
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1265 (locate-completion-entry cmpl-entry pref-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1266 ;; still losing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1267 (locate-completion-db-error))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1268 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1269
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1270 (defun locate-completion-db-error ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1271 ;; recursive error: really scrod
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1272 (error "Completion database corrupted. Try M-x clear-all-completions. Send bug report.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1273 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1274
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1275 ;;; WRITES
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1276 (defun add-completion-to-tail-if-new (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1277 "If STRING is not in the database add it to appropriate prefix list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1278 STRING is added to the end of the appropriate prefix list with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1279 num-uses = 0. The database is unchanged if it is there. STRING must be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1280 longer than `completion-prefix-min-length'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1281 This must be very fast.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1282 Returns the completion entry."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1283 (or (find-exact-completion string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1284 ;; not there
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1285 (let (;; create an entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1286 (entry (make-completion string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1287 ;; setup the prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1288 (prefix-entry (find-cmpl-prefix-entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1289 (substring cmpl-db-downcase-string 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1290 (cmpl-read-time-eval
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1291 completion-prefix-min-length))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1292 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1293 ;; The next two forms should happen as a unit (atomically) but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1294 ;; no fatal errors should result if that is not the case.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1295 (cond (prefix-entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1296 ;; These two should be atomic, but nothing fatal will happen
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1297 ;; if they're not.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1298 (setcdr (cmpl-prefix-entry-tail prefix-entry) entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1299 (set-cmpl-prefix-entry-tail prefix-entry entry))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1300 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1301 (set cmpl-db-prefix-symbol (make-cmpl-prefix-entry entry))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1302 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1303 ;; statistics
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1304 (cmpl-statistics-block
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1305 (note-added-completion))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1306 ;; set symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1307 (set cmpl-db-symbol (car entry))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1308 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1309
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1310 (defun add-completion-to-head (completion-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1311 "If COMPLETION-STRING is not in the database, add it to prefix list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1312 We add COMPLETION-STRING to the head of the appropriate prefix list,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1313 or it to the head of the list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1314 COMPLETION-STRING must be longer than `completion-prefix-min-length'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1315 Updates the saved string with the supplied string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1316 This must be very fast.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1317 Returns the completion entry."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1318 ;; Handle pending acceptance
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1319 (if completion-to-accept (accept-completion))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1320 ;; test if already in database
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1321 (if (setq cmpl-db-entry (find-exact-completion completion-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1322 ;; found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1323 (let* ((prefix-entry (find-cmpl-prefix-entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1324 (substring cmpl-db-downcase-string 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1325 (cmpl-read-time-eval
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1326 completion-prefix-min-length))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1327 (splice-ptr (locate-completion-entry cmpl-db-entry prefix-entry))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1328 (cmpl-ptr (cdr splice-ptr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1329 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1330 ;; update entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1331 (set-completion-string cmpl-db-entry completion-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1332 ;; move to head (if necessary)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1333 (cond (splice-ptr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1334 ;; These should all execute atomically but it is not fatal if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1335 ;; they don't.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1336 ;; splice it out
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1337 (or (setcdr splice-ptr (cdr cmpl-ptr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1338 ;; fix up tail if necessary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1339 (set-cmpl-prefix-entry-tail prefix-entry splice-ptr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1340 ;; splice in at head
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1341 (setcdr cmpl-ptr (cmpl-prefix-entry-head prefix-entry))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1342 (set-cmpl-prefix-entry-head prefix-entry cmpl-ptr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1343 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1344 cmpl-db-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1345 ;; not there
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1346 (let (;; create an entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1347 (entry (make-completion completion-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1348 ;; setup the prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1349 (prefix-entry (find-cmpl-prefix-entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1350 (substring cmpl-db-downcase-string 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1351 (cmpl-read-time-eval
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1352 completion-prefix-min-length))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1353 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1354 (cond (prefix-entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1355 ;; Splice in at head
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1356 (setcdr entry (cmpl-prefix-entry-head prefix-entry))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1357 (set-cmpl-prefix-entry-head prefix-entry entry))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1358 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1359 ;; Start new prefix entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1360 (set cmpl-db-prefix-symbol (make-cmpl-prefix-entry entry))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1361 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1362 ;; statistics
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1363 (cmpl-statistics-block
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1364 (note-added-completion))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1365 ;; Add it to the symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1366 (set cmpl-db-symbol (car entry))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1367 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1368
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1369 (defun delete-completion (completion-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1370 "Deletes the completion from the database.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1371 String must be longer than `completion-prefix-min-length'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1372 ;; Handle pending acceptance
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1373 (if completion-to-accept (accept-completion))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1374 (if (setq cmpl-db-entry (find-exact-completion completion-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1375 ;; found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1376 (let* ((prefix-entry (find-cmpl-prefix-entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1377 (substring cmpl-db-downcase-string 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1378 (cmpl-read-time-eval
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1379 completion-prefix-min-length))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1380 (splice-ptr (locate-completion-entry cmpl-db-entry prefix-entry))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1381 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1382 ;; delete symbol reference
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1383 (set cmpl-db-symbol nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1384 ;; remove from prefix list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1385 (cond (splice-ptr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1386 ;; not at head
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1387 (or (setcdr splice-ptr (cdr (cdr splice-ptr)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1388 ;; fix up tail if necessary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1389 (set-cmpl-prefix-entry-tail prefix-entry splice-ptr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1390 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1391 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1392 ;; at head
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1393 (or (set-cmpl-prefix-entry-head
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1394 prefix-entry (cdr (cmpl-prefix-entry-head prefix-entry)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1395 ;; List is now empty
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1396 (set cmpl-db-prefix-symbol nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1397 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1398 (cmpl-statistics-block
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1399 (note-completion-deleted))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1400 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1401 (error "Unknown completion `%s'" completion-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1402 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1403
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1404 ;;; Tests --
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1405 ;;; - Add and Find -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1406 ;;; (add-completion-to-head "banana") --> ("banana" 0 nil 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1407 ;;; (find-exact-completion "banana") --> ("banana" 0 nil 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1408 ;;; (find-exact-completion "bana") --> nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1409 ;;; (car (find-cmpl-prefix-entry "ban")) --> (("banana" ...))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1410 ;;; (cdr (find-cmpl-prefix-entry "ban")) --> (("banana" ...))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1411 ;;; (add-completion-to-head "banish") --> ("banish" 0 nil 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1412 ;;; (find-exact-completion "banish") --> ("banish" 0 nil 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1413 ;;; (car (find-cmpl-prefix-entry "ban")) --> (("banish" ...) ("banana" ...))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1414 ;;; (cdr (find-cmpl-prefix-entry "ban")) --> (("banana" ...))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1415 ;;; (add-completion-to-head "banana") --> ("banana" 0 nil 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1416 ;;; (car (find-cmpl-prefix-entry "ban")) --> (("banana" ...) ("banish" ...))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1417 ;;; (cdr (find-cmpl-prefix-entry "ban")) --> (("banish" ...))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1418 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1419 ;;; - Deleting -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1420 ;;; (add-completion-to-head "banner") --> ("banner" 0 nil 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1421 ;;; (delete-completion "banner")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1422 ;;; (find-exact-completion "banner") --> nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1423 ;;; (car (find-cmpl-prefix-entry "ban")) --> (("banana" ...) ("banish" ...))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1424 ;;; (cdr (find-cmpl-prefix-entry "ban")) --> (("banish" ...))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1425 ;;; (add-completion-to-head "banner") --> ("banner" 0 nil 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1426 ;;; (delete-completion "banana")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1427 ;;; (car (find-cmpl-prefix-entry "ban")) --> (("banner" ...) ("banish" ...))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1428 ;;; (cdr (find-cmpl-prefix-entry "ban")) --> (("banish" ...))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1429 ;;; (delete-completion "banner")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1430 ;;; (delete-completion "banish")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1431 ;;; (find-cmpl-prefix-entry "ban") --> nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1432 ;;; (delete-completion "banner") --> error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1433 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1434 ;;; - Tail -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1435 ;;; (add-completion-to-tail-if-new "banana") --> ("banana" 0 nil 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1436 ;;; (car (find-cmpl-prefix-entry "ban")) --> (("banana" ...))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1437 ;;; (cdr (find-cmpl-prefix-entry "ban")) --> (("banana" ...))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1438 ;;; (add-completion-to-tail-if-new "banish") --> ("banish" 0 nil 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1439 ;;; (car (find-cmpl-prefix-entry "ban")) -->(("banana" ...) ("banish" ...))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1440 ;;; (cdr (find-cmpl-prefix-entry "ban")) -->(("banish" ...))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1441 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1442
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1443
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1444 ;;;---------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1445 ;;; Database Update :: Interface level routines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1446 ;;;---------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1447 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1448 ;;; These lie on top of the database ref. functions but below the standard
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1449 ;;; user interface level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1450
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1451
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1452 (defun interactive-completion-string-reader (prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1453 (let* ((default (symbol-under-or-before-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1454 (new-prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1455 (if default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1456 (format "%s: (default: %s) " prompt default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1457 (format "%s: " prompt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1458 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1459 (read (completing-read new-prompt cmpl-obarray))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1460 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1461 (if (zerop (length read)) (setq read (or default "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1462 (list read)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1463 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1464
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1465 (defun check-completion-length (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1466 (if (< (length string) completion-min-length)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1467 (error "The string `%s' is too short to be saved as a completion"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1468 string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1469 (list string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1470
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1471 (defun add-completion (string &optional num-uses last-use-time)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1472 "Add STRING to completion list, or move it to head of list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1473 The completion is altered appropriately if num-uses and/or last-use-time is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1474 specified."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1475 (interactive (interactive-completion-string-reader "Completion to add"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1476 (check-completion-length string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1477 (let* ((current-completion-source (if (interactive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1478 cmpl-source-interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1479 current-completion-source))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1480 (entry (add-completion-to-head string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1481
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1482 (if num-uses (set-completion-num-uses entry num-uses))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1483 (if last-use-time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1484 (set-completion-last-use-time entry last-use-time))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1485 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1486
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1487 (defun add-permanent-completion (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1488 "Add STRING if it isn't already listed, and mark it permanent."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1489 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1490 (interactive-completion-string-reader "Completion to add permanently"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1491 (let ((current-completion-source (if (interactive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1492 cmpl-source-interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1493 current-completion-source))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1494 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1495 (add-completion string nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1496 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1497
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1498 (defun kill-completion (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1499 (interactive (interactive-completion-string-reader "Completion to kill"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1500 (check-completion-length string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1501 (delete-completion string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1502 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1503
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1504 (defun accept-completion ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1505 "Accepts the pending completion in `completion-to-accept'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1506 This bumps num-uses. Called by `add-completion-to-head' and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1507 `completion-search-reset'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1508 (let ((string completion-to-accept)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1509 ;; if this is added afresh here, then it must be a cdabbrev
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1510 (current-completion-source cmpl-source-cdabbrev)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1511 entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1512 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1513 (setq completion-to-accept nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1514 (setq entry (add-completion-to-head string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1515 (set-completion-num-uses entry (1+ (completion-num-uses entry)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1516 (setq cmpl-completions-accepted-p t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1517 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1518
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1519 (defun use-completion-under-point ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1520 "Add the completion symbol underneath the point into the completion buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1521 (let ((string (and enable-completion (symbol-under-point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1522 (current-completion-source cmpl-source-cursor-moves))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1523 (if string (add-completion-to-head string))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1524
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1525 (defun use-completion-before-point ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1526 "Add the completion symbol before point into the completion buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1527 (let ((string (and enable-completion (symbol-before-point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1528 (current-completion-source cmpl-source-cursor-moves))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1529 (if string (add-completion-to-head string))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1530
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1531 (defun use-completion-under-or-before-point ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1532 "Add the completion symbol before point into the completion buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1533 (let ((string (and enable-completion (symbol-under-or-before-point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1534 (current-completion-source cmpl-source-cursor-moves))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1535 (if string (add-completion-to-head string))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1536
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1537 (defun use-completion-before-separator ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1538 "Add the completion symbol before point into the completion buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1539 Completions added this way will automatically be saved if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1540 `completion-on-separator-character' is non-nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1541 (let ((string (and enable-completion (symbol-before-point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1542 (current-completion-source cmpl-source-separator)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1543 entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1544 (cmpl-statistics-block
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1545 (note-separator-character string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1546 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1547 (cond (string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1548 (setq entry (add-completion-to-head string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1549 (if (and completion-on-separator-character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1550 (zerop (completion-num-uses entry)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1551 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1552 (set-completion-num-uses entry 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1553 (setq cmpl-completions-accepted-p t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1554 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1555
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1556 ;;; Tests --
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1557 ;;; - Add and Find -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1558 ;;; (add-completion "banana" 5 10)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1559 ;;; (find-exact-completion "banana") --> ("banana" 5 10 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1560 ;;; (add-completion "banana" 6)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1561 ;;; (find-exact-completion "banana") --> ("banana" 6 10 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1562 ;;; (add-completion "banish")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1563 ;;; (car (find-cmpl-prefix-entry "ban")) --> (("banish" ...) ("banana" ...))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1564 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1565 ;;; - Accepting -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1566 ;;; (setq completion-to-accept "banana")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1567 ;;; (accept-completion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1568 ;;; (find-exact-completion "banana") --> ("banana" 7 10)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1569 ;;; (car (find-cmpl-prefix-entry "ban")) --> (("banana" ...) ("banish" ...))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1570 ;;; (setq completion-to-accept "banish")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1571 ;;; (add-completion "banner")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1572 ;;; (car (find-cmpl-prefix-entry "ban"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1573 ;;; --> (("banner" ...) ("banish" 1 ...) ("banana" 7 ...))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1574 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1575 ;;; - Deleting -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1576 ;;; (kill-completion "banish")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1577 ;;; (car (find-cmpl-prefix-entry "ban")) --> (("banner" ...) ("banana" ...))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1578
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1579
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1580 ;;;---------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1581 ;;; Searching the database
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1582 ;;;---------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1583 ;;; Functions outside this block must call completion-search-reset followed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1584 ;;; by calls to completion-search-next or completion-search-peek
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1585 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1586
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1587 ;;; Status variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1588 ;; Commented out to improve loading speed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1589 (defvar cmpl-test-string "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1590 ;; "The current string used by completion-search-next."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1591 (defvar cmpl-test-regexp "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1592 ;; "The current regexp used by completion-search-next.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1593 ;; (derived from cmpl-test-string)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1594 (defvar cmpl-last-index 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1595 ;; "The last index that completion-search-next was called with."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1596 (defvar cmpl-cdabbrev-reset-p nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1597 ;; "Set to t when cdabbrevs have been reset."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1598 (defvar cmpl-next-possibilities nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1599 ;; "A pointer to the element BEFORE the next set of possible completions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1600 ;; cadr of this is the cmpl-next-possibility"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1601 (defvar cmpl-starting-possibilities nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1602 ;; "The initial list of starting possibilities."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1603 (defvar cmpl-next-possibility nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1604 ;; "The cached next possibility."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1605 (defvar cmpl-tried-list nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1606 ;; "A downcased list of all the completions we have tried."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1607
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1608
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1609 (defun completion-search-reset (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1610 "Set up the for completion searching for STRING.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1611 STRING must be longer than `completion-prefix-min-length'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1612 (if completion-to-accept (accept-completion))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1613 (setq cmpl-starting-possibilities
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1614 (cmpl-prefix-entry-head
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1615 (find-cmpl-prefix-entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1616 (downcase (substring string 0 completion-prefix-min-length))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1617 cmpl-test-string string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1618 cmpl-test-regexp (concat (regexp-quote string) "."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1619 (completion-search-reset-1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1620 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1621
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1622 (defun completion-search-reset-1 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1623 (setq cmpl-next-possibilities cmpl-starting-possibilities
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1624 cmpl-next-possibility nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1625 cmpl-cdabbrev-reset-p nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1626 cmpl-last-index -1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1627 cmpl-tried-list nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1628 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1629
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1630 (defun completion-search-next (index)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1631 "Return the next completion entry.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1632 If INDEX is out of sequence, reset and start from the top.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1633 If there are no more entries, try cdabbrev and returns only a string."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1634 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1635 ((= index (setq cmpl-last-index (1+ cmpl-last-index)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1636 (completion-search-peek t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1637 ((< index 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1638 (completion-search-reset-1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1639 (setq cmpl-last-index index)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1640 ;; reverse the possibilities list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1641 (setq cmpl-next-possibilities (reverse cmpl-starting-possibilities))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1642 ;; do a "normal" search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1643 (while (and (completion-search-peek nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1644 (< (setq index (1+ index)) 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1645 (setq cmpl-next-possibility nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1646 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1647 (cond ((not cmpl-next-possibilities))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1648 ;; If no more possibilities, leave it that way
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1649 ((= -1 cmpl-last-index)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1650 ;; next completion is at index 0. reset next-possibility list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1651 ;; to start at beginning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1652 (setq cmpl-next-possibilities cmpl-starting-possibilities))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1653 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1654 ;; otherwise point to one before current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1655 (setq cmpl-next-possibilities
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1656 (nthcdr (- (length cmpl-starting-possibilities)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1657 (length cmpl-next-possibilities))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1658 cmpl-starting-possibilities))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1659 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1660 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1661 ;; non-negative index, reset and search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1662 ;;(prin1 'reset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1663 (completion-search-reset-1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1664 (setq cmpl-last-index index)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1665 (while (and (completion-search-peek t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1666 (not (< (setq index (1- index)) 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1667 (setq cmpl-next-possibility nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1668 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1669 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1670 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1671 cmpl-next-possibility
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1672 (setq cmpl-next-possibility nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1673 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1674
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1675
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1676 (defun completion-search-peek (use-cdabbrev)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1677 "Returns the next completion entry without actually moving the pointers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1678 Calling this again or calling `completion-search-next' results in the same
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1679 string being returned. Depends on `case-fold-search'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1680 If there are no more entries, try cdabbrev and then return only a string."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1681 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1682 ;; return the cached value if we have it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1683 (cmpl-next-possibility)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1684 ((and cmpl-next-possibilities
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1685 ;; still a few possibilities left
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1686 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1687 (while
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1688 (and (not (eq 0 (string-match cmpl-test-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1689 (completion-string (car cmpl-next-possibilities)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1690 (setq cmpl-next-possibilities (cdr cmpl-next-possibilities))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1691 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1692 cmpl-next-possibilities
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1693 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1694 ;; successful match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1695 (setq cmpl-next-possibility (car cmpl-next-possibilities)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1696 cmpl-tried-list (cons (downcase (completion-string cmpl-next-possibility))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1697 cmpl-tried-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1698 cmpl-next-possibilities (cdr cmpl-next-possibilities)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1699 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1700 cmpl-next-possibility)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1701 (use-cdabbrev
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1702 ;; unsuccessful, use cdabbrev
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1703 (cond ((not cmpl-cdabbrev-reset-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1704 (reset-cdabbrev cmpl-test-string cmpl-tried-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1705 (setq cmpl-cdabbrev-reset-p t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1706 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1707 (setq cmpl-next-possibility (next-cdabbrev))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1708 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1709 ;; Completely unsuccessful, return nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1710 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1711
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1712 ;;; Tests --
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1713 ;;; - Add and Find -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1714 ;;; (add-completion "banana")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1715 ;;; (completion-search-reset "ban")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1716 ;;; (completion-search-next 0) --> "banana"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1717 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1718 ;;; - Discrimination -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1719 ;;; (add-completion "cumberland")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1720 ;;; (add-completion "cumberbund")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1721 ;;; cumbering
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1722 ;;; (completion-search-reset "cumb")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1723 ;;; (completion-search-peek t) --> "cumberbund"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1724 ;;; (completion-search-next 0) --> "cumberbund"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1725 ;;; (completion-search-peek t) --> "cumberland"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1726 ;;; (completion-search-next 1) --> "cumberland"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1727 ;;; (completion-search-peek nil) --> nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1728 ;;; (completion-search-next 2) --> "cumbering" {cdabbrev}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1729 ;;; (completion-search-next 3) --> nil or "cumming"{depends on context}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1730 ;;; (completion-search-next 1) --> "cumberland"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1731 ;;; (completion-search-peek t) --> "cumbering" {cdabbrev}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1732 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1733 ;;; - Accepting -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1734 ;;; (completion-search-next 1) --> "cumberland"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1735 ;;; (setq completion-to-accept "cumberland")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1736 ;;; (completion-search-reset "foo")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1737 ;;; (completion-search-reset "cum")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1738 ;;; (completion-search-next 0) --> "cumberland"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1739 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1740 ;;; - Deleting -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1741 ;;; (kill-completion "cumberland")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1742 ;;; cummings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1743 ;;; (completion-search-reset "cum")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1744 ;;; (completion-search-next 0) --> "cumberbund"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1745 ;;; (completion-search-next 1) --> "cummings"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1746 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1747 ;;; - Ignoring Capitalization -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1748 ;;; (completion-search-reset "CuMb")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1749 ;;; (completion-search-next 0) --> "cumberbund"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1750
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1751
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1752
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1753 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1754 ;;; COMPLETE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1755 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1756
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1757 (defun completion-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1758 "Toggles whether or not to add new words to the completion database."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1759 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1760 (setq enable-completion (not enable-completion))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1761 (message "Completion mode is now %s." (if enable-completion "ON" "OFF"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1762 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1763
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1764 (defvar cmpl-current-index 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1765 (defvar cmpl-original-string nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1766 (defvar cmpl-last-insert-location -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1767 (defvar cmpl-leave-point-at-start nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1768
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1769 (defun complete (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1770 "Fill out a completion of the word before point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1771 Point is left at end. Consecutive calls rotate through all possibilities.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1772 Prefix args ::
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1773 control-u :: leave the point at the beginning of the completion rather
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1774 than at the end.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1775 a number :: rotate through the possible completions by that amount
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1776 `-' :: same as -1 (insert previous completion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1777 {See the comments at the top of `completion.el' for more info.}"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1778 (interactive "*p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1779 ;;; Set up variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1780 (cond ((eq last-command this-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1781 ;; Undo last one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1782 (delete-region cmpl-last-insert-location (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1783 ;; get next completion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1784 (setq cmpl-current-index (+ cmpl-current-index (or arg 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1785 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1786 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1787 (if (not cmpl-initialized-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1788 (initialize-completions)) ;; make sure everything's loaded
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1789 (cond ((consp current-prefix-arg) ;; control-u
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1790 (setq arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1791 (setq cmpl-leave-point-at-start t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1792 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1793 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1794 (setq cmpl-leave-point-at-start nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1795 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1796 ;; get string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1797 (setq cmpl-original-string (symbol-before-point-for-complete))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1798 (cond ((not cmpl-original-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1799 (setq this-command 'failed-complete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1800 (error "To complete, point must be after a symbol at least %d character long"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1801 completion-prefix-min-length)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1802 ;; get index
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1803 (setq cmpl-current-index (if current-prefix-arg arg 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1804 ;; statistics
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1805 (cmpl-statistics-block
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1806 (note-complete-entered-afresh cmpl-original-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1807 ;; reset database
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1808 (completion-search-reset cmpl-original-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1809 ;; erase what we've got
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1810 (delete-region cmpl-symbol-start cmpl-symbol-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1811 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1812
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1813 ;; point is at the point to insert the new symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1814 ;; Get the next completion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1815 (let* ((print-status-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1816 ;; XEmacs change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1817 (and (>= (device-baud-rate) completion-prompt-speed-threshold)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1818 (not (minibuffer-window-selected-p))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1819 (insert-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1820 (entry (completion-search-next cmpl-current-index))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1821 string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1822 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1823 ;; entry is either a completion entry or a string (if cdabbrev)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1824
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1825 ;; If found, insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1826 (cond (entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1827 ;; Setup for proper case
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1828 (setq string (if (stringp entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1829 entry (completion-string entry)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1830 (setq string (cmpl-merge-string-cases
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1831 string cmpl-original-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1832 ;; insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1833 (insert string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1834 ;; accept it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1835 (setq completion-to-accept string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1836 ;; fixup and cache point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1837 (cond (cmpl-leave-point-at-start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1838 (setq cmpl-last-insert-location (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1839 (goto-char insert-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1840 (t;; point at end,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1841 (setq cmpl-last-insert-location insert-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1842 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1843 ;; statistics
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1844 (cmpl-statistics-block
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1845 (note-complete-inserted entry cmpl-current-index))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1846 ;; Done ! cmpl-stat-complete-successful
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1847 ;;display the next completion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1848 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1849 ((and print-status-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1850 ;; This updates the display and only prints if there
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1851 ;; is no typeahead
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1852 (sit-for 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1853 (setq entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1854 (completion-search-peek
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1855 completion-cdabbrev-prompt-flag)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1856 (setq string (if (stringp entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1857 entry (completion-string entry)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1858 (setq string (cmpl-merge-string-cases
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1859 string cmpl-original-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1860 (message "Next completion: %s" string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1861 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1862 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1863 (t;; none found, insert old
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1864 (insert cmpl-original-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1865 ;; Don't accept completions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1866 (setq completion-to-accept nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1867 ;; print message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1868 ;; This used to call cmpl19-sit-for, an undefined function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1869 ;; I hope that sit-for does the right thing; I don't know -- rms.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1870 (if (and print-status-p (sit-for 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1871 (message "No %scompletions."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1872 (if (eq this-command last-command) "more " "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1873 ;; statistics
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1874 (cmpl-statistics-block
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1875 (record-complete-failed cmpl-current-index))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1876 ;; Pretend that we were never here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1877 (setq this-command 'failed-complete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1878 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1879
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1880 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1881 ;;; "Complete" Key Keybindings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1882 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1883
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1884 ;; XEmacs change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1885 ;;(global-set-key "\M-\r" 'complete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1886 ;;(global-set-key [?\C-\r] 'complete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1887 ;;(define-key function-key-map [C-return] [?\C-\r])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1888 (global-set-key '(meta return) 'complete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1889 (global-set-key '(control return) 'complete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1890 ;; XEmacs: #### still need to take care of function-key-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1891
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1892 ;;; Tests -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1893 ;;; (add-completion "cumberland")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1894 ;;; (add-completion "cumberbund")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1895 ;;; cum
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1896 ;;; Cumber
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1897 ;;; cumbering
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1898 ;;; cumb
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1899
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1900
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1901 ;;;---------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1902 ;;; Parsing definitions from files into the database
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1903 ;;;---------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1904
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1905 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1906 ;;; Top Level functions ::
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1907 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1908
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1909 ;;; User interface
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1910 (defun add-completions-from-file (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1911 "Parse possible completions from a file and add them to data base."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1912 (interactive "fFile: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1913 (setq file (expand-file-name file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1914 (let* ((buffer (get-file-buffer file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1915 (buffer-already-there-p buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1916 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1917 (if (not buffer-already-there-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1918 (let ((completions-merging-modes nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1919 (setq buffer (find-file-noselect file))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1920 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1921 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1922 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1923 (add-completions-from-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1924 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1925 (if (not buffer-already-there-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1926 (kill-buffer buffer)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1927
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1928 (defun add-completions-from-buffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1929 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1930 (let ((current-completion-source cmpl-source-file-parsing)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1931 (start-num
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1932 (cmpl-statistics-block
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1933 (aref completion-add-count-vector cmpl-source-file-parsing)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1934 mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1935 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1936 (cond ((memq major-mode '(emacs-lisp-mode lisp-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1937 (add-completions-from-lisp-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1938 (setq mode 'lisp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1939 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1940 ((memq major-mode '(c-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1941 (add-completions-from-c-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1942 (setq mode 'c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1943 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1944 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1945 (error "Cannot parse completions in %s buffers"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1946 major-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1947 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1948 (cmpl-statistics-block
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1949 (record-cmpl-parse-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1950 mode (point-max)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1951 (- (aref completion-add-count-vector cmpl-source-file-parsing)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1952 start-num)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1953 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1954
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1955 ;;; Find file hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1956 (defun cmpl-find-file-hook ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1957 (cond (enable-completion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1958 (cond ((and (memq major-mode '(emacs-lisp-mode lisp-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1959 (memq 'lisp completions-merging-modes)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1960 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1961 (add-completions-from-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1962 ((and (memq major-mode '(c-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1963 (memq 'c completions-merging-modes)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1964 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1965 (add-completions-from-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1966 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1967 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1968
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1969 (add-hook 'find-file-hooks 'cmpl-find-file-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1970
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1971 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1972 ;;; Tags Table Completions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1973 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1974
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1975 (defun add-completions-from-tags-table ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1976 ;; Inspired by eero@media-lab.media.mit.edu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1977 "Add completions from the current tags table."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1978 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1979 (visit-tags-table-buffer) ;this will prompt if no tags-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1980 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1981 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1982 (let (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1983 (condition-case e
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1984 (while t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1985 (search-forward "\177")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1986 (backward-char 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1987 (and (setq string (symbol-under-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1988 (add-completion-to-tail-if-new string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1989 (forward-char 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1990 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1991 (search-failed)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1992 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1993
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1994
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1995 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1996 ;;; Lisp File completion parsing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1997 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1998 ;;; This merely looks for phrases beginning with (def.... or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1999 ;;; (package:def ... and takes the next word.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2000 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2001 ;;; We tried using forward-lines and explicit searches but the regexp technique
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2002 ;;; was faster. (About 100K characters per second)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2003 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2004 (defconst *lisp-def-regexp*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2005 "\n(\\(\\w*:\\)?def\\(\\w\\|\\s_\\)*\\s +(*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2006 "A regexp that searches for lisp definition form."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2007 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2008
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2009 ;;; Tests -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2010 ;;; (and (string-match *lisp-def-regexp* "\n(defun foo") (match-end 0)) -> 8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2011 ;;; (and (string-match *lisp-def-regexp* "\n(si:def foo") (match-end 0)) -> 9
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2012 ;;; (and (string-match *lisp-def-regexp* "\n(def-bar foo")(match-end 0)) -> 10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2013 ;;; (and (string-match *lisp-def-regexp* "\n(defun (foo") (match-end 0)) -> 9
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2014
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2015 ;;; Parses all the definition names from a Lisp mode buffer and adds them to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2016 ;;; the completion database.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2017 (defun add-completions-from-lisp-buffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2018 ;;; Benchmarks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2019 ;;; Sun-3/280 - 1500 to 3000 lines of lisp code per second
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2020 (let (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2021 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2022 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2023 (condition-case e
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2024 (while t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2025 (re-search-forward *lisp-def-regexp*)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2026 (and (setq string (symbol-under-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2027 (add-completion-to-tail-if-new string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2028 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2029 (search-failed)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2030 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2031
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2032
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2033 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2034 ;;; C file completion parsing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2035 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2036 ;;; C :
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2037 ;;; Looks for #define or [<storage class>] [<type>] <name>{,<name>}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2038 ;;; or structure, array or pointer defs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2039 ;;; It gets most of the definition names.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2040 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2041 ;;; As you might suspect by now, we use some symbol table hackery
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2042 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2043 ;;; Symbol separator chars (have whitespace syntax) --> , ; * = (
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2044 ;;; Opening char --> [ {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2045 ;;; Closing char --> ] }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2046 ;;; opening and closing must be skipped over
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2047 ;;; Whitespace chars (have symbol syntax)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2048 ;;; Everything else has word syntax
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2049
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2050 (defun cmpl-make-c-def-completion-syntax-table ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2051 (let ((table (make-vector 256 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2052 (whitespace-chars '(? ?\n ?\t ?\f ?\v ?\r))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2053 ;; unfortunately the ?( causes the parens to appear unbalanced
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2054 (separator-chars '(?, ?* ?= ?\( ?\;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2055 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2056 i)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2057 ;; default syntax is whitespace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2058 (setq i 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2059 (while (< i 256)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2060 (modify-syntax-entry i "w" table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2061 (setq i (1+ i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2062 (completion-dolist (char whitespace-chars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2063 (modify-syntax-entry char "_" table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2064 (completion-dolist (char separator-chars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2065 (modify-syntax-entry char " " table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2066 (modify-syntax-entry ?\[ "(]" table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2067 (modify-syntax-entry ?\{ "(}" table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2068 (modify-syntax-entry ?\] ")[" table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2069 (modify-syntax-entry ?\} "){" table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2070 table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2071
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2072 (defconst cmpl-c-def-syntax-table (cmpl-make-c-def-completion-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2073
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2074 ;;; Regexps
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2075 (defconst *c-def-regexp*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2076 ;; This stops on lines with possible definitions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2077 "\n[_a-zA-Z#]"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2078 ;; This stops after the symbol to add.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2079 ;;"\n\\(#define\\s +.\\|\\(\\(\\w\\|\\s_\\)+\\b\\s *\\)+[(;,[*{=]\\)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2080 ;; This stops before the symbol to add. {Test cases in parens. below}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2081 ;;"\n\\(\\(\\w\\|\\s_\\)+\\s *(\\|\\(\\(#define\\|auto\\|extern\\|register\\|static\\|int\\|long\\|short\\|unsigned\\|char\\|void\\|float\\|double\\|enum\\|struct\\|union\\|typedef\\)\\s +\\)+\\)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2082 ;; this simple version picks up too much extraneous stuff
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2083 ;; "\n\\(\\w\\|\\s_\\|#\\)\\B"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2084 "A regexp that searches for a definition form."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2085 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2086 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2087 ;(defconst *c-cont-regexp*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2088 ; "\\(\\w\\|\\s_\\)+\\b\\s *\\({\\|\\(\\[[0-9\t ]*\\]\\s *\\)*,\\(*\\|\\s \\)*\\b\\)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2089 ; "This regexp should be used in a looking-at to parse for lists of variables.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2090 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2091 ;(defconst *c-struct-regexp*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2092 ; "\\(*\\|\\s \\)*\\b"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2093 ; "This regexp should be used to test whether a symbol follows a structure definition.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2094
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2095 ;(defun test-c-def-regexp (regexp string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2096 ; (and (eq 0 (string-match regexp string)) (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2097 ; )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2098
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2099 ;;; Tests -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2100 ;;; (test-c-def-regexp *c-def-regexp* "\n#define foo") -> 10 (9)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2101 ;;; (test-c-def-regexp *c-def-regexp* "\nfoo (x, y) {") -> 6 (6)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2102 ;;; (test-c-def-regexp *c-def-regexp* "\nint foo (x, y)") -> 10 (5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2103 ;;; (test-c-def-regexp *c-def-regexp* "\n int foo (x, y)") -> nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2104 ;;; (test-c-def-regexp *c-cont-regexp* "oo, bar") -> 4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2105 ;;; (test-c-def-regexp *c-cont-regexp* "oo, *bar") -> 5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2106 ;;; (test-c-def-regexp *c-cont-regexp* "a [5][6], bar") -> 10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2107 ;;; (test-c-def-regexp *c-cont-regexp* "oo(x,y)") -> nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2108 ;;; (test-c-def-regexp *c-cont-regexp* "a [6] ,\t bar") -> 9
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2109 ;;; (test-c-def-regexp *c-cont-regexp* "oo {trout =1} my_carp;") -> 14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2110 ;;; (test-c-def-regexp *c-cont-regexp* "truct_p complex foon") -> nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2112 ;;; Parses all the definition names from a C mode buffer and adds them to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2113 ;;; completion database.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2114 (defun add-completions-from-c-buffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2115 ;; Benchmark --
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2116 ;; Sun 3/280-- 1250 lines/sec.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2118 (let (string next-point char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2119 (saved-syntax (syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2120 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2121 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2122 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2123 (catch 'finish-add-completions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2124 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2125 (while t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2126 ;; we loop here only when scan-sexps fails
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2127 ;; (i.e. unbalance exps.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2128 (set-syntax-table cmpl-c-def-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2129 (condition-case e
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2130 (while t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2131 (re-search-forward *c-def-regexp*)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2132 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2133 ((= (preceding-char) ?#)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2134 ;; preprocessor macro, see if it's one we handle
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2135 (setq string (buffer-substring (point) (+ (point) 6)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2136 (cond ((or (string-equal string "define")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2137 (string-equal string "ifdef ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2138 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2139 ;; skip forward over definition symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2140 ;; and add it to database
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2141 (and (forward-word 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2142 (setq string (symbol-before-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2143 ;;(push string foo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2144 (add-completion-to-tail-if-new string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2145 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2146 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2147 ;; C definition
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2148 (setq next-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2149 (while (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2150 next-point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2151 ;; scan to next separator char.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2152 (setq next-point (scan-sexps next-point 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2153 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2154 ;; position the point on the word we want to add
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2155 (goto-char next-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2156 (while (= (setq char (following-char)) ?*)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2157 ;; handle pointer ref
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2158 ;; move to next separator char.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2159 (goto-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2160 (setq next-point (scan-sexps (point) 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2161 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2162 (forward-word -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2163 ;; add to database
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2164 (if (setq string (symbol-under-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2165 ;; (push string foo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2166 (add-completion-to-tail-if-new string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2167 ;; Local TMC hack (useful for parsing paris.h)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2168 (if (and (looking-at "_AP") ;; "ansi prototype"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2169 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2170 (forward-word -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2171 (setq string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2172 (symbol-under-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2173 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2174 (add-completion-to-tail-if-new string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2175 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2176 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2177 ;; go to next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2178 (goto-char next-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2179 ;; (push (format "%c" (following-char)) foo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2180 (if (= (char-syntax char) ?\()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2181 ;; if on an opening delimiter, go to end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2182 (while (= (char-syntax char) ?\()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2183 (setq next-point (scan-sexps next-point 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2184 char (char-after next-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2185 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2186 (or (= char ?,)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2187 ;; Current char is an end char.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2188 (setq next-point nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2189 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2190 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2191 (search-failed ;;done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2192 (throw 'finish-add-completions t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2193 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2194 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2195 ;; Check for failure in scan-sexps
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2196 (if (or (string-equal (nth 1 e)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2197 "Containing expression ends prematurely")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2198 (string-equal (nth 1 e) "Unbalanced parentheses"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2199 ;; unbalanced paren., keep going
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2200 ;;(ding)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2201 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2202 (message "Error parsing C buffer for completions--please send bug report")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2203 (throw 'finish-add-completions t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2204 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2205 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2206 (set-syntax-table saved-syntax)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2207 )))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2208
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2209
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2210 ;;;---------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2211 ;;; Init files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2212 ;;;---------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2213
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2214 ;;; The version of save-completions-to-file called at kill-emacs time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2215 (defun kill-emacs-save-completions ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2216 (if (and save-completions-flag enable-completion cmpl-initialized-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2217 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2218 ((not cmpl-completions-accepted-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2219 (message "Completions database has not changed - not writing."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2220 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2221 (save-completions-to-file)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2222
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2223 ;; There is no point bothering to change this again
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2224 ;; unless the package changes so much that it matters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2225 ;; for people that have saved completions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2226 (defconst completion-version "11")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2227
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2228 (defconst saved-cmpl-file-header
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2229 ";;; Completion Initialization file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2230 ;;; Version = %s
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2231 ;;; Format is (<string> . <last-use-time>)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2232 ;;; <string> is the completion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2233 ;;; <last-use-time> is the time the completion was last used
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2234 ;;; If it is t, the completion will never be pruned from the file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2235 ;;; Otherwise it is in hours since origin.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2236 \n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2237
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2238 (defun completion-backup-filename (filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2239 (concat filename ".BAK"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2240
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2241 (defun save-completions-to-file (&optional filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2242 "Save completions in init file FILENAME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2243 If file name is not specified, use `save-completions-file-name'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2244 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2245 (setq filename (expand-file-name (or filename save-completions-file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2246 (if (file-writable-p filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2247 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2248 (if (not cmpl-initialized-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2249 (initialize-completions));; make sure everything's loaded
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2250 (message "Saving completions to file %s" filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2251
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2252 (let* ((delete-old-versions t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2253 (kept-old-versions 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2254 (kept-new-versions completions-file-versions-kept)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2255 last-use-time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2256 (current-time (cmpl-hours-since-origin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2257 (total-in-db 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2258 (total-perm 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2259 (total-saved 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2260 (backup-filename (completion-backup-filename filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2261 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2262
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2263 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2264 (get-buffer-create " *completion-save-buffer*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2265 (set-buffer " *completion-save-buffer*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2266 (setq buffer-file-name filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2267
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2268 (if (not (verify-visited-file-modtime (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2269 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2270 ;; file has changed on disk. Bring us up-to-date
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2271 (message "Completion file has changed. Merging. . .")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2272 (load-completions-from-file filename t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2273 (message "Merging finished. Saving completions to file %s" filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2274
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2275 ;; prepare the buffer to be modified
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2276 (clear-visited-file-modtime)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2277 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2278 ;; (/ 1 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2279 (insert (format saved-cmpl-file-header completion-version))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2280 (completion-dolist (completion (list-all-completions))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2281 (setq total-in-db (1+ total-in-db))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2282 (setq last-use-time (completion-last-use-time completion))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2283 ;; Update num uses and maybe write completion to a file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2284 (cond ((or;; Write to file if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2285 ;; permanent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2286 (and (eq last-use-time t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2287 (setq total-perm (1+ total-perm)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2288 ;; or if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2289 (if (> (completion-num-uses completion) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2290 ;; it's been used
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2291 (setq last-use-time current-time)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2292 ;; or it was saved before and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2293 (and last-use-time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2294 ;; save-completions-retention-time is nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2295 (or (not save-completions-retention-time)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2296 ;; or time since last use is < ...retention-time*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2297 (< (- current-time last-use-time)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2298 save-completions-retention-time))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2299 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2300 ;; write to file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2301 (setq total-saved (1+ total-saved))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2302 (insert (prin1-to-string (cons (completion-string completion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2303 last-use-time)) "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2304 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2305
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2306 ;; write the buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2307 (condition-case e
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2308 (let ((file-exists-p (file-exists-p filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2309 (if file-exists-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2310 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2311 ;; If file exists . . .
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2312 ;; Save a backup(so GNU doesn't screw us when we're out of disk)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2313 ;; (GNU leaves a 0 length file if it gets a disk full error!)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2314
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2315 ;; If backup doesn't exit, Rename current to backup
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2316 ;; {If backup exists the primary file is probably messed up}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2317 (or (file-exists-p backup-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2318 (rename-file filename backup-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2319 ;; Copy the backup back to the current name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2320 ;; (so versioning works)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2321 (copy-file backup-filename filename t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2322 ;; Save it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2323 (save-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2324 (if file-exists-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2325 ;; If successful, remove backup
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2326 (delete-file backup-filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2327 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2328 (set-buffer-modified-p nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2329 (message "Couldn't save completion file `%s'" filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2330 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2331 ;; Reset accepted-p flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2332 (setq cmpl-completions-accepted-p nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2333 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2334 (cmpl-statistics-block
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2335 (record-save-completions total-in-db total-perm total-saved))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2336 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2337
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2338 ;;;(defun autosave-completions ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2339 ;;; (if (and save-completions-flag enable-completion cmpl-initialized-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2340 ;;; *completion-auto-save-period*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2341 ;;; (> cmpl-emacs-idle-time *completion-auto-save-period*)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2342 ;;; cmpl-completions-accepted-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2343 ;;; (save-completions-to-file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2344
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2345 ;;;(add-hook 'cmpl-emacs-idle-time-hooks 'autosave-completions)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2346
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2347 (defun load-completions-from-file (&optional filename no-message-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2348 "Loads a completion init file FILENAME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2349 If file is not specified, then use `save-completions-file-name'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2350 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2351 (setq filename (expand-file-name (or filename save-completions-file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2352 (let* ((backup-filename (completion-backup-filename filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2353 (backup-readable-p (file-readable-p backup-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2354 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2355 (if backup-readable-p (setq filename backup-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2356 (if (file-readable-p filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2357 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2358 (if (not no-message-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2359 (message "Loading completions from %sfile %s . . ."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2360 (if backup-readable-p "backup " "") filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2361 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2362 (get-buffer-create " *completion-save-buffer*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2363 (set-buffer " *completion-save-buffer*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2364 (setq buffer-file-name filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2365 ;; prepare the buffer to be modified
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2366 (clear-visited-file-modtime)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2367 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2368
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2369 (let ((insert-okay-p nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2370 (buffer (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2371 (current-time (cmpl-hours-since-origin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2372 string num-uses entry last-use-time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2373 cmpl-entry cmpl-last-use-time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2374 (current-completion-source cmpl-source-init-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2375 (start-num
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2376 (cmpl-statistics-block
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2377 (aref completion-add-count-vector cmpl-source-file-parsing)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2378 (total-in-file 0) (total-perm 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2379 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2380 ;; insert the file into a buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2381 (condition-case e
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2382 (progn (insert-file-contents filename t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2383 (setq insert-okay-p t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2384
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2385 (file-error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2386 (message "File error trying to load completion file %s."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2387 filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2388 ;; parse it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2389 (if insert-okay-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2390 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2391 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2392
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2393 (condition-case e
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2394 (while t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2395 (setq entry (read buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2396 (setq total-in-file (1+ total-in-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2397 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2398 ((and (consp entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2399 (stringp (setq string (car entry)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2400 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2401 ((eq (setq last-use-time (cdr entry)) 'T)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2402 ;; handle case sensitivity
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2403 (setq total-perm (1+ total-perm))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2404 (setq last-use-time t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2405 ((eq last-use-time t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2406 (setq total-perm (1+ total-perm)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2407 ((integerp last-use-time))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2408 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2409 ;; Valid entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2410 ;; add it in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2411 (setq cmpl-last-use-time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2412 (completion-last-use-time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2413 (setq cmpl-entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2414 (add-completion-to-tail-if-new string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2415 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2416 (if (or (eq last-use-time t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2417 (and (> last-use-time 1000);;backcompatibility
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2418 (not (eq cmpl-last-use-time t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2419 (or (not cmpl-last-use-time)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2420 ;; more recent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2421 (> last-use-time cmpl-last-use-time))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2422 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2423 ;; update last-use-time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2424 (set-completion-last-use-time cmpl-entry last-use-time)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2425 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2426 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2427 ;; Bad format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2428 (message "Error: invalid saved completion - %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2429 (prin1-to-string entry))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2430 ;; try to get back in sync
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2431 (search-forward "\n(")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2432 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2433 (search-failed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2434 (message "End of file while reading completions.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2435 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2436 (end-of-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2437 (if (= (point) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2438 (if (not no-message-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2439 (message "Loading completions from file %s . . . Done."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2440 filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2441 (message "End of file while reading completions.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2442 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2443 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2444
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2445 (cmpl-statistics-block
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2446 (record-load-completions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2447 total-in-file total-perm
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2448 (- (aref completion-add-count-vector cmpl-source-init-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2449 start-num)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2450
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2451 ))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2452
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2453 (defun initialize-completions ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2454 "Load the default completions file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2455 Also sets up so that exiting emacs will automatically save the file."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2456 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2457 (cond ((not cmpl-initialized-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2458 (load-completions-from-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2459 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2460 (setq cmpl-initialized-p t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2461 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2462
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2463
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2464 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2465 ;;; Kill EMACS patch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2466 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2467
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2468 (add-hook 'kill-emacs-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2469 '(lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2470 (kill-emacs-save-completions)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2471 (cmpl-statistics-block
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2472 (record-cmpl-kill-emacs))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2473
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2474 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2475 ;;; Kill region patch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2476 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2477
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2478 (defun completion-kill-region (&optional beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2479 "Kill between point and mark.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2480 The text is deleted but saved in the kill ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2481 The command \\[yank] can retrieve it from there.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2482 /(If you want to kill and then yank immediately, use \\[copy-region-as-kill].)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2483
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2484 This is the primitive for programs to kill text (as opposed to deleting it).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2485 Supply two arguments, character numbers indicating the stretch of text
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2486 to be killed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2487 Any command that calls this function is a \"kill command\".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2488 If the previous command was also a kill command,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2489 the text killed this time appends to the text killed last time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2490 to make one entry in the kill ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2491 Patched to remove the most recent completion."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2492 (interactive "r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2493 (cond ((eq last-command 'complete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2494 (delete-region (point) cmpl-last-insert-location)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2495 (insert cmpl-original-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2496 (setq completion-to-accept nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2497 (cmpl-statistics-block
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2498 (record-complete-failed)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2499 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2500 (kill-region beg end))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2501
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2502 (global-set-key "\C-w" 'completion-kill-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2503
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2504 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2505 ;;; Patches to self-insert-command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2506 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2507
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2508 ;;; Need 2 versions: generic separator chars. and space (to get auto fill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2509 ;;; to work)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2510
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2511 ;;; All common separators (eg. space "(" ")" """) characters go through a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2512 ;;; function to add new words to the list of words to complete from:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2513 ;;; COMPLETION-SEPARATOR-SELF-INSERT-COMMAND (arg).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2514 ;;; If the character before this was an alpha-numeric then this adds the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2515 ;;; symbol before point to the completion list (using ADD-COMPLETION).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2516
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2517 (defun completion-separator-self-insert-command (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2518 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2519 (use-completion-before-separator)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2520 (self-insert-command arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2521 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2522
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2523 (defun completion-separator-self-insert-autofilling (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2524 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2525 (use-completion-before-separator)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2526 (self-insert-command arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2527 (and auto-fill-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2528 (funcall auto-fill-function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2529 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2530
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2531 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2532 ;;; Wrapping Macro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2533 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2534
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2535 ;;; Note that because of the way byte compiling works, none of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2536 ;;; the functions defined with this macro get byte compiled.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2537
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2538 (defmacro def-completion-wrapper (function-name type &optional new-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2539 "Add a call to update the completion database before function execution.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2540 TYPE is the type of the wrapper to be added. Can be :before or :under."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2541 (cond ((eq type ':separator)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2542 (list 'put (list 'quote function-name) ''completion-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2543 ''use-completion-before-separator))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2544 ((eq type ':before)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2545 (list 'put (list 'quote function-name) ''completion-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2546 ''use-completion-before-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2547 ((eq type ':backward-under)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2548 (list 'put (list 'quote function-name) ''completion-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2549 ''use-completion-backward-under))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2550 ((eq type ':backward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2551 (list 'put (list 'quote function-name) ''completion-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2552 ''use-completion-backward))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2553 ((eq type ':under)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2554 (list 'put (list 'quote function-name) ''completion-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2555 ''use-completion-under-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2556 ((eq type ':under-or-before)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2557 (list 'put (list 'quote function-name) ''completion-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2558 ''use-completion-under-or-before-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2559 ((eq type ':minibuffer-separator)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2560 (list 'put (list 'quote function-name) ''completion-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2561 ''use-completion-minibuffer-separator))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2562
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2563 (defun use-completion-minibuffer-separator ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2564 (let ((cmpl-syntax-table cmpl-standard-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2565 (use-completion-before-separator)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2566
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2567 (defun use-completion-backward-under ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2568 (use-completion-under-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2569 (if (eq last-command 'complete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2570 ;; probably a failed completion if you have to back up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2571 (cmpl-statistics-block (record-complete-failed))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2572
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2573 (defun use-completion-backward ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2574 (if (eq last-command 'complete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2575 ;; probably a failed completion if you have to back up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2576 (cmpl-statistics-block (record-complete-failed))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2577
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2578 (defun completion-before-command ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2579 (funcall (or (and (symbolp this-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2580 (get this-command 'completion-function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2581 'use-completion-under-or-before-point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2582 (add-hook 'pre-command-hook 'completion-before-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2583
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2584
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2585 ;;;---------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2586 ;;; Patches to standard keymaps insert completions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2587 ;;;---------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2588
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2589 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2590 ;;; Separators
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2591 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2592 ;;; We've used the completion syntax table given as a guide.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2593 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2594 ;;; Global separator chars.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2595 ;;; We left out <tab> because there are too many special cases for it. Also,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2596 ;;; in normal coding it's rarely typed after a word.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2597 (global-set-key " " 'completion-separator-self-insert-autofilling)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2598 (global-set-key "!" 'completion-separator-self-insert-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2599 (global-set-key "%" 'completion-separator-self-insert-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2600 (global-set-key "^" 'completion-separator-self-insert-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2601 (global-set-key "&" 'completion-separator-self-insert-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2602 (global-set-key "(" 'completion-separator-self-insert-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2603 (global-set-key ")" 'completion-separator-self-insert-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2604 (global-set-key "=" 'completion-separator-self-insert-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2605 (global-set-key "`" 'completion-separator-self-insert-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2606 (global-set-key "|" 'completion-separator-self-insert-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2607 (global-set-key "{" 'completion-separator-self-insert-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2608 (global-set-key "}" 'completion-separator-self-insert-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2609 (global-set-key "[" 'completion-separator-self-insert-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2610 (global-set-key "]" 'completion-separator-self-insert-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2611 (global-set-key ";" 'completion-separator-self-insert-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2612 (global-set-key "\"" 'completion-separator-self-insert-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2613 (global-set-key "'" 'completion-separator-self-insert-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2614 (global-set-key "#" 'completion-separator-self-insert-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2615 (global-set-key "," 'completion-separator-self-insert-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2616 (global-set-key "?" 'completion-separator-self-insert-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2617
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2618 ;;; We include period and colon even though they are symbol chars because :
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2619 ;;; - in text we want to pick up the last word in a sentence.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2620 ;;; - in C pointer refs. we want to pick up the first symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2621 ;;; - it won't make a difference for lisp mode (package names are short)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2622 (global-set-key "." 'completion-separator-self-insert-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2623 (global-set-key ":" 'completion-separator-self-insert-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2624
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2625 ;;; Lisp Mode diffs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2626 (define-key lisp-mode-map "!" 'self-insert-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2627 (define-key lisp-mode-map "&" 'self-insert-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2628 (define-key lisp-mode-map "%" 'self-insert-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2629 (define-key lisp-mode-map "?" 'self-insert-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2630 (define-key lisp-mode-map "=" 'self-insert-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2631 (define-key lisp-mode-map "^" 'self-insert-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2632
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2633 ;;; C mode diffs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2634 (defun completion-c-mode-hook ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2635 (def-completion-wrapper electric-c-semi :separator)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2636 (define-key c-mode-map "+" 'completion-separator-self-insert-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2637 (define-key c-mode-map "*" 'completion-separator-self-insert-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2638 (define-key c-mode-map "/" 'completion-separator-self-insert-command))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2639 ;; Do this either now or whenever C mode is loaded.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2640 (if (featurep 'cc-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2641 (completion-c-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2642 (add-hook 'c-mode-hook 'completion-c-mode-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2643
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2644 ;;; FORTRAN mode diffs. (these are defined when fortran is called)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2645 (defun completion-setup-fortran-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2646 (define-key fortran-mode-map "+" 'completion-separator-self-insert-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2647 (define-key fortran-mode-map "-" 'completion-separator-self-insert-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2648 (define-key fortran-mode-map "*" 'completion-separator-self-insert-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2649 (define-key fortran-mode-map "/" 'completion-separator-self-insert-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2650 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2651
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2652 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2653 ;;; End of line chars.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2654 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2655 (def-completion-wrapper newline :separator)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2656 (def-completion-wrapper newline-and-indent :separator)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2657 (def-completion-wrapper comint-send-input :separator)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2658 (def-completion-wrapper exit-minibuffer :minibuffer-separator)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2659 (def-completion-wrapper eval-print-last-sexp :separator)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2660 (def-completion-wrapper eval-last-sexp :separator)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2661 ;;(def-completion-wrapper minibuffer-complete-and-exit :minibuffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2662
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2663 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2664 ;;; Cursor movement
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2665 ;;;-----------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2666
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2667 (def-completion-wrapper next-line :under-or-before)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2668 (def-completion-wrapper previous-line :under-or-before)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2669 (def-completion-wrapper beginning-of-buffer :under-or-before)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2670 (def-completion-wrapper end-of-buffer :under-or-before)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2671 (def-completion-wrapper beginning-of-line :under-or-before)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2672 (def-completion-wrapper end-of-line :under-or-before)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2673 (def-completion-wrapper forward-char :under-or-before)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2674 (def-completion-wrapper forward-word :under-or-before)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2675 (def-completion-wrapper forward-sexp :under-or-before)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2676 (def-completion-wrapper backward-char :backward-under)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2677 (def-completion-wrapper backward-word :backward-under)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2678 (def-completion-wrapper backward-sexp :backward-under)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2679
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2680 (def-completion-wrapper delete-backward-char :backward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2681 (def-completion-wrapper delete-backward-char-untabify :backward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2682
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2683 ;;; Tests --
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2684 ;;; foobarbiz
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2685 ;;; foobar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2686 ;;; fooquux
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2687 ;;; fooper
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2688
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2689 (cmpl-statistics-block
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2690 (record-completion-file-loaded))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2691
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2692 ;;; completion.el ends here