annotate lisp/packages/completion.el @ 187:b405438285a2 r20-3b20

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