annotate src/abbrev.c @ 371:cc15677e0335 r21-2b1

Import from CVS: tag r21-2b1
author cvs
date Mon, 13 Aug 2007 11:03:08 +0200
parents 8e84bee8ddd0
children 8626e4521993
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 /* Primitives for word-abbrev mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Copyright (C) 1985, 1986, 1992, 1993 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 /* Synched up with: FSF 19.30. Note that there are many more functions in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 FSF's abbrev.c. These have been moved into Lisp in XEmacs. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 /* Authorship:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 FSF: Original version; a long time ago.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 JWZ or Mly: Mostly moved into Lisp; maybe 1992.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 Ben Wing: Some changes for Mule for 19.12.
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
29 Hrvoje Niksic: Largely rewritten in June 1997.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 /* This file has been Mule-ized. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 #include "lisp.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 #include "buffer.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 #include "commands.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 #include "insdel.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 #include "syntax.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 #include "window.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 /* An abbrev table is an obarray.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 Each defined abbrev is represented by a symbol in that obarray
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 whose print name is the abbreviation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 The symbol's value is a string which is the expansion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 If its function definition is non-nil, it is called
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 after the expansion is done.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 The plist slot of the abbrev symbol is its usage count. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 /* The table of global abbrevs. These are in effect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 in any buffer in which abbrev mode is turned on. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 Lisp_Object Vglobal_abbrev_table;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 int abbrev_all_caps;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 /* Non-nil => use this location as the start of abbrev to expand
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (rather than taking the word before point as the abbrev) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 Lisp_Object Vabbrev_start_location;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 /* Buffer that Vabbrev_start_location applies to */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 Lisp_Object Vabbrev_start_location_buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 /* The symbol representing the abbrev most recently expanded */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 Lisp_Object Vlast_abbrev;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 /* A string for the actual text of the abbrev most recently expanded.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 This has more info than Vlast_abbrev since case is significant. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 Lisp_Object Vlast_abbrev_text;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 /* Character address of start of last abbrev expanded */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 227
diff changeset
72 int last_abbrev_location;
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
73
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 /* Hook to run before expanding any abbrev. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 Lisp_Object Vpre_abbrev_expand_hook, Qpre_abbrev_expand_hook;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
78 struct abbrev_match_mapper_closure {
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
79 struct buffer *buf;
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
80 struct Lisp_Char_Table *chartab;
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
81 Charcount point, maxlen;
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
82 struct Lisp_Symbol *found;
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
83 };
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
84
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
85 /* For use by abbrev_match(): Match SYMBOL's name against buffer text
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
86 before point, case-insensitively. When found, return non-zero, so
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
87 that map_obarray terminates mapping. */
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
88 static int
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
89 abbrev_match_mapper (Lisp_Object symbol, void *arg)
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
90 {
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
91 struct abbrev_match_mapper_closure *closure =
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
92 (struct abbrev_match_mapper_closure *)arg;
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
93 Charcount abbrev_length;
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
94 struct Lisp_Symbol *sym = XSYMBOL (symbol);
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
95 struct Lisp_String *abbrev;
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
96
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
97 /* symbol_value should be OK here, because abbrevs are not expected
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
98 to contain any SYMBOL_MAGIC stuff. */
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
99 if (UNBOUNDP (symbol_value (sym)) || NILP (symbol_value (sym)))
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
100 {
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
101 /* The symbol value of nil means that abbrev got undefined. */
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
102 return 0;
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
103 }
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
104 abbrev = symbol_name (sym);
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
105 abbrev_length = string_char_length (abbrev);
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
106 if (abbrev_length > closure->maxlen)
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
107 {
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
108 /* This abbrev is too large -- it wouldn't fit. */
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
109 return 0;
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
110 }
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
111 /* If `bar' is an abbrev, and a user presses `fubar<SPC>', we don't
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
112 normally want to expand it. OTOH, if the abbrev begins with
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
113 non-word syntax (e.g. `#if'), it is OK to abbreviate it anywhere. */
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
114 if (abbrev_length < closure->maxlen && abbrev_length > 0
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
115 && (WORD_SYNTAX_P (closure->chartab, string_char (abbrev, 0)))
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
116 && (WORD_SYNTAX_P (closure->chartab,
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
117 BUF_FETCH_CHAR (closure->buf,
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
118 closure->point - (abbrev_length + 1)))))
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
119 {
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
120 return 0;
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
121 }
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
122 /* Match abbreviation string against buffer text. */
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
123 {
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
124 Bufbyte *ptr = string_data (abbrev);
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
125 Charcount idx;
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
126
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
127 for (idx = 0; idx < abbrev_length; idx++)
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
128 {
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
129 if (DOWNCASE (closure->buf,
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
130 BUF_FETCH_CHAR (closure->buf,
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
131 closure->point - abbrev_length + idx))
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
132 != DOWNCASE (closure->buf, charptr_emchar (ptr)))
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
133 {
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
134 break;
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
135 }
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
136 INC_CHARPTR (ptr);
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
137 }
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
138 if (idx == abbrev_length)
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
139 {
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
140 /* This is the one. */
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
141 closure->found = sym;
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
142 return 1;
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
143 }
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
144 }
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
145 return 0;
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
146 }
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
147
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
148 /* Match the buffer text against names of symbols in obarray. Returns
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
149 the matching symbol, or 0 if not found. */
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
150 static struct Lisp_Symbol *
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
151 abbrev_match (struct buffer *buf, Lisp_Object obarray)
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
152 {
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
153 struct abbrev_match_mapper_closure closure;
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
154
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
155 /* Precalculate some stuff, so mapper function needn't to it in each
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
156 iteration. */
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
157 closure.buf = buf;
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
158 closure.point = BUF_PT (buf);
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
159 closure.maxlen = closure.point - BUF_BEGV (buf);
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
160 closure.chartab = XCHAR_TABLE (buf->mirror_syntax_table);
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
161 closure.found = 0;
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
162
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
163 map_obarray (obarray, abbrev_match_mapper, &closure);
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
164
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
165 return closure.found;
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
166 }
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
167
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
168 /* Take the word before point (or Vabbrev_start_location, if non-nil),
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
169 and look it up in OBARRAY, and return the symbol (or zero). This
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
170 used to be the default method of searching, with the obvious
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
171 limitation that the abbrevs may consist only of word characters.
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
172 It is an order of magnitude faster than the proper abbrev_match(),
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
173 but then again, vi is an order of magnitude faster than Emacs.
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
174
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
175 This speed difference should be unnoticable, though. I have tested
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
176 the degenerated cases of thousands of abbrevs being defined, and
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
177 abbrev_match() was still fast enough for normal operation. */
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
178 static struct Lisp_Symbol *
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
179 abbrev_oblookup (struct buffer *buf, Lisp_Object obarray)
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
180 {
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
181 Bufpos wordstart, wordend;
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
182 Bufbyte *word, *p;
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
183 Bytecount idx;
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
184 Lisp_Object lookup;
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
185
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
186 CHECK_VECTOR (obarray);
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
187
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
188 if (!NILP (Vabbrev_start_location))
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
189 {
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
190 wordstart = get_buffer_pos_char (buf, Vabbrev_start_location,
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
191 GB_COERCE_RANGE);
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
192 Vabbrev_start_location = Qnil;
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 272
diff changeset
193 #if 0
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
194 /* Previously, abbrev-prefix-mark crockishly inserted a dash to
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
195 indicate the abbrev start point. It now uses an extent with
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
196 a begin glyph so there's no dash to remove. */
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
197 if (wordstart != BUF_ZV (buf)
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
198 && BUF_FETCH_CHAR (buf, wordstart) == '-')
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
199 {
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
200 buffer_delete_range (buf, wordstart, wordstart + 1, 0);
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
201 }
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
202 #endif
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
203 wordend = BUF_PT (buf);
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
204 }
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
205 else
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
206 {
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
207 Bufpos point = BUF_PT (buf);
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
208
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
209 wordstart = scan_words (buf, point, -1);
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
210 if (!wordstart)
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
211 return 0;
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
212
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
213 wordend = scan_words (buf, wordstart, 1);
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
214 if (!wordend)
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
215 return 0;
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
216 if (wordend > BUF_ZV (buf))
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
217 wordend = BUF_ZV (buf);
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
218 if (wordend > point)
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
219 wordend = point;
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
220 /* Unlike the original function, we allow expansion only after
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
221 the abbrev, not preceded by a number of spaces. This is
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
222 because of consistency with abbrev_match. */
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
223 if (wordend < point)
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
224 return 0;
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 359
diff changeset
225 if (wordend <= wordstart)
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 359
diff changeset
226 return 0;
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
227 }
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
228
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
229 p = word = (Bufbyte *) alloca (MAX_EMCHAR_LEN * (wordend - wordstart));
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
230 for (idx = wordstart; idx < wordend; idx++)
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
231 {
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
232 Emchar c = BUF_FETCH_CHAR (buf, idx);
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
233 if (UPPERCASEP (buf, c))
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
234 c = DOWNCASE (buf, c);
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
235 p += set_charptr_emchar (p, c);
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
236 }
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
237 lookup = oblookup (obarray, word, p - word);
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
238 if (SYMBOLP (lookup) && !NILP (symbol_value (XSYMBOL (lookup))))
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
239 return XSYMBOL (lookup);
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
240 else
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
241 return NULL;
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
242 }
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
243
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
244 /* Return non-zero if OBARRAY contains an interned symbol ` '. */
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
245 static int
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
246 obarray_has_blank_p (Lisp_Object obarray)
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
247 {
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 272
diff changeset
248 return !ZEROP (oblookup (obarray, (Bufbyte *)" ", 1));
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
249 }
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
250
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
251 /* Analyze case in the buffer substring, and report it. */
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
252 static void
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
253 abbrev_count_case (struct buffer *buf, Bufpos pos, Charcount length,
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
254 int *lccount, int *uccount)
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
255 {
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
256 *lccount = *uccount = 0;
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
257 while (length--)
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
258 {
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 272
diff changeset
259 Emchar c = BUF_FETCH_CHAR (buf, pos);
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
260 if (UPPERCASEP (buf, c))
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
261 ++*uccount;
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
262 else if (LOWERCASEP (buf, c))
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
263 ++*lccount;
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
264 ++pos;
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
265 }
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
266 }
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
267
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
268 DEFUN ("expand-abbrev", Fexpand_abbrev, 0, 0, "", /*
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
269 Expand the abbrev before point, if any.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 Effective when explicitly called even when `abbrev-mode' is nil.
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
271 Returns the abbrev symbol, if expansion took place.
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
272 If no abbrev matched, but `pre-abbrev-expand-hook' changed the buffer,
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
273 returns t.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
274 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
275 ())
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 struct buffer *buf = current_buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 int oldmodiff = BUF_MODIFF (buf);
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
280 Lisp_Object pre_modiff_p;
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
281 Bufpos point; /* position of point */
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
282 Bufpos abbrev_start; /* position of abbreviation beginning */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
284 struct Lisp_Symbol *(*fun) (struct buffer *, Lisp_Object);
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
285
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
286 struct Lisp_Symbol *abbrev_symbol;
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
287 struct Lisp_String *abbrev_string;
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
288 Lisp_Object expansion, count, hook;
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
289 Charcount abbrev_length;
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
290 int lccount, uccount;
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
291
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 run_hook (Qpre_abbrev_expand_hook);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 /* If the hook changes the buffer, treat that as having "done an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 expansion". */
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
295 pre_modiff_p = (BUF_MODIFF (buf) != oldmodiff ? Qt : Qnil);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
297 abbrev_symbol = NULL;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 if (!BUFFERP (Vabbrev_start_location_buffer) ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 XBUFFER (Vabbrev_start_location_buffer) != buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 Vabbrev_start_location = Qnil;
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
301 /* We use the more general abbrev_match() if the obarray blank flag
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
302 is not set, and Vabbrev_start_location is nil. Otherwise, use
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
303 abbrev_oblookup(). */
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
304 #define MATCHFUN(tbl) ((obarray_has_blank_p (tbl) \
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
305 && NILP (Vabbrev_start_location)) \
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
306 ? abbrev_match : abbrev_oblookup)
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
307 if (!NILP (buf->abbrev_table))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 {
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
309 fun = MATCHFUN (buf->abbrev_table);
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
310 abbrev_symbol = fun (buf, buf->abbrev_table);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 }
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
312 if (!abbrev_symbol && !NILP (Vglobal_abbrev_table))
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
313 {
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
314 fun = MATCHFUN (Vglobal_abbrev_table);
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
315 abbrev_symbol = fun (buf, Vglobal_abbrev_table);
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
316 }
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
317 if (!abbrev_symbol)
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
318 return pre_modiff_p;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
320 /* NOTE: we hope that `pre-abbrev-expand-hook' didn't do something
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
321 nasty, such as changed the buffer. Here we protect against the
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
322 buffer getting killed. */
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
323 if (! BUFFER_LIVE_P (buf))
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
324 return Qnil;
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
325 point = BUF_PT (buf);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
327 /* OK, we're out of the must-be-fast part. An abbreviation matched.
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
328 Now find the parameters, insert the expansion, and make it all
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
329 look pretty. */
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
330 abbrev_string = symbol_name (abbrev_symbol);
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
331 abbrev_length = string_char_length (abbrev_string);
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
332 abbrev_start = point - abbrev_length;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
334 expansion = symbol_value (abbrev_symbol);
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
335 CHECK_STRING (expansion);
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
336
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
337 count = symbol_plist (abbrev_symbol); /* Gag */
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
338 if (NILP (count))
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
339 count = Qzero;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 else
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
341 CHECK_NATNUM (count);
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
342 symbol_plist (abbrev_symbol) = make_int (1 + XINT (count));
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
343
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
344 /* Count the case in the original text. */
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
345 abbrev_count_case (buf, abbrev_start, abbrev_length, &lccount, &uccount);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
347 /* Remember the last abbrev text, location, etc. */
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
348 XSETSYMBOL (Vlast_abbrev, abbrev_symbol);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 Vlast_abbrev_text =
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
350 make_string_from_buffer (buf, abbrev_start, abbrev_length);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 227
diff changeset
351 last_abbrev_location = abbrev_start;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
353 /* Add an undo boundary, in case we are doing this for a
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
354 self-inserting command which has avoided making one so far. */
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
355 if (INTERACTIVE)
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
356 Fundo_boundary ();
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
358 /* Remove the abbrev */
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
359 buffer_delete_range (buf, abbrev_start, point, 0);
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
360 /* And insert the expansion. */
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
361 buffer_insert_lisp_string (buf, expansion);
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
362 point = BUF_PT (buf);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
364 /* Now fiddle with the case. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 if (uccount && !lccount)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 /* Abbrev was all caps */
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
368 if (!abbrev_all_caps
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
369 && scan_words (buf, point, -1) > scan_words (buf, abbrev_start, 1))
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
370 {
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
371 Fupcase_initials_region (make_int (abbrev_start), make_int (point),
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
372 make_buffer (buf));
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
373 }
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
374 else
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
375 {
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
376 /* If expansion is one word, or if user says so, upcase it all. */
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
377 Fupcase_region (make_int (abbrev_start), make_int (point),
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
378 make_buffer (buf));
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
379 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 else if (uccount)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 /* Abbrev included some caps. Cap first initial of expansion */
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
384 Bufpos pos = abbrev_start;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 /* Find the initial. */
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
386 while (pos < point
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
387 && !WORD_SYNTAX_P (XCHAR_TABLE (buf->mirror_syntax_table),
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 20
diff changeset
388 BUF_FETCH_CHAR (buf, pos)))
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
389 pos++;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 /* Change just that. */
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
391 Fupcase_initials_region (make_int (pos), make_int (pos + 1),
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
392 make_buffer (buf));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
395 hook = symbol_function (abbrev_symbol);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 if (!NILP (hook) && !UNBOUNDP (hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 call0 (hook);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
399 return Vlast_abbrev;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 209
diff changeset
402
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 syms_of_abbrev (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 defsymbol (&Qpre_abbrev_expand_hook, "pre-abbrev-expand-hook");
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
407 DEFSUBR (Fexpand_abbrev);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 vars_of_abbrev (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 DEFVAR_LISP ("global-abbrev-table", &Vglobal_abbrev_table /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 The abbrev table whose abbrevs affect all buffers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 Each buffer may also have a local abbrev table.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 If it does, the local table overrides the global one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 for any particular abbrev defined in both.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 Vglobal_abbrev_table = Qnil; /* setup by Lisp code */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 DEFVAR_LISP ("last-abbrev", &Vlast_abbrev /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 The abbrev-symbol of the last abbrev expanded.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 See the function `abbrev-symbol'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 DEFVAR_LISP ("last-abbrev-text", &Vlast_abbrev_text /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 The exact text of the last abbrev expanded.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 nil if the abbrev has already been unexpanded.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 227
diff changeset
431 DEFVAR_INT ("last-abbrev-location", &last_abbrev_location /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 The location of the start of the last abbrev expanded.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 Vlast_abbrev = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 Vlast_abbrev_text = Qnil;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 227
diff changeset
437 last_abbrev_location = 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 DEFVAR_LISP ("abbrev-start-location", &Vabbrev_start_location /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 Buffer position for `expand-abbrev' to use as the start of the abbrev.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 nil means use the word before point as the abbrev.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 Calling `expand-abbrev' sets this to nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 Vabbrev_start_location = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 DEFVAR_LISP ("abbrev-start-location-buffer", &Vabbrev_start_location_buffer /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 Buffer that `abbrev-start-location' has been set for.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 Trying to expand an abbrev in any other buffer clears `abbrev-start-location'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 Vabbrev_start_location_buffer = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 DEFVAR_BOOL ("abbrev-all-caps", &abbrev_all_caps /*
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 70
diff changeset
453 *Non-nil means expand multi-word abbrevs all caps if abbrev was so.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 abbrev_all_caps = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 DEFVAR_LISP ("pre-abbrev-expand-hook", &Vpre_abbrev_expand_hook /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 Function or functions to be called before abbrev expansion is done.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 This is the first thing that `expand-abbrev' does, and so this may change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 the current abbrev table before abbrev lookup happens.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 Vpre_abbrev_expand_hook = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 }