annotate lisp/packages/completion.el @ 86:364816949b59 r20-0b93

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