annotate lisp/packages/completion.el @ 98:0d2f883870bc r20-1b1

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