aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGlenn Morris2007-07-17 07:04:48 +0000
committerGlenn Morris2007-07-17 07:04:48 +0000
commit857cc3fc2c4250480caae0b663210af0b6913987 (patch)
tree45afe15c43801ec69cba4cfa853fac35982d56ac /src
parente981804271cde591636aac7007f676c21463df85 (diff)
downloademacs-857cc3fc2c4250480caae0b663210af0b6913987.tar.gz
emacs-857cc3fc2c4250480caae0b663210af0b6913987.zip
(abbrev_check_chars): New function.
(Fdefine_global_abbrev, Fdefine_mode_abbrev): Call abbrev_check_chars to check abbrev characters are word constituents. Doc fix.
Diffstat (limited to 'src')
-rw-r--r--src/abbrev.c74
1 files changed, 72 insertions, 2 deletions
diff --git a/src/abbrev.c b/src/abbrev.c
index 40cad1832fc..6447c450056 100644
--- a/src/abbrev.c
+++ b/src/abbrev.c
@@ -172,12 +172,79 @@ overwrite a non-system abbreviation of the same name. */)
172 return name; 172 return name;
173} 173}
174 174
175/* Check if the characters in ABBREV have word syntax in either the
176 * current (if global == 0) or standard syntax table. */
177static void
178abbrev_check_chars (abbrev, global)
179 Lisp_Object abbrev;
180 int global;
181{
182 int i, i_byte, len, nbad = 0;
183 int j, found, nuniq = 0;
184 char *badchars, *baduniq;
185
186 CHECK_STRING (abbrev);
187 len = SCHARS (abbrev);
188
189 badchars = (char *) alloca (len + 1);
190
191 for (i = 0, i_byte = 0; i < len; )
192 {
193 int c;
194
195 FETCH_STRING_CHAR_ADVANCE (c, abbrev, i, i_byte);
196
197 if (global)
198 {
199 /* Copied from SYNTAX in syntax.h, except using FOLLOW_PARENT. */
200 Lisp_Object syntax_temp
201 = SYNTAX_ENTRY_FOLLOW_PARENT (Vstandard_syntax_table, c);
202 if ( (CONSP (syntax_temp)
203 ? (enum syntaxcode) (XINT (XCAR (syntax_temp)) & 0xff)
204 : Swhitespace) != Sword ) badchars[nbad++] = c;
205 }
206 else if (SYNTAX (c) != Sword)
207 badchars[nbad++] = c;
208 }
209
210 if (nbad == 0) return;
211
212 baduniq = (char *) alloca (nbad + 1);
213
214 for (i = 0; i < nbad; i++)
215 {
216 found = 0;
217
218 for (j = 0; j < nuniq; j++)
219 {
220 if (badchars[i] == baduniq[j])
221 {
222 found = 1;
223 break;
224 }
225 }
226
227 if (found) continue ;
228
229 baduniq[nuniq++] = badchars[i];
230 }
231
232 baduniq[nuniq] = '\0';
233
234 error ("Some abbrev characters (%s) are not word constituents %s",
235 baduniq, global ? "in the standard syntax" : "in this mode" );
236}
237
175DEFUN ("define-global-abbrev", Fdefine_global_abbrev, Sdefine_global_abbrev, 2, 2, 238DEFUN ("define-global-abbrev", Fdefine_global_abbrev, Sdefine_global_abbrev, 2, 2,
176 "sDefine global abbrev: \nsExpansion for %s: ", 239 "sDefine global abbrev: \nsExpansion for %s: ",
177 doc: /* Define ABBREV as a global abbreviation for EXPANSION. */) 240 doc: /* Define ABBREV as a global abbreviation for EXPANSION.
241The characters in ABBREV must all be word constituents in the standard
242syntax table. */)
178 (abbrev, expansion) 243 (abbrev, expansion)
179 Lisp_Object abbrev, expansion; 244 Lisp_Object abbrev, expansion;
180{ 245{
246 abbrev_check_chars (abbrev, 1);
247
181 Fdefine_abbrev (Vglobal_abbrev_table, Fdowncase (abbrev), 248 Fdefine_abbrev (Vglobal_abbrev_table, Fdowncase (abbrev),
182 expansion, Qnil, make_number (0), Qnil); 249 expansion, Qnil, make_number (0), Qnil);
183 return abbrev; 250 return abbrev;
@@ -185,13 +252,16 @@ DEFUN ("define-global-abbrev", Fdefine_global_abbrev, Sdefine_global_abbrev, 2,
185 252
186DEFUN ("define-mode-abbrev", Fdefine_mode_abbrev, Sdefine_mode_abbrev, 2, 2, 253DEFUN ("define-mode-abbrev", Fdefine_mode_abbrev, Sdefine_mode_abbrev, 2, 2,
187 "sDefine mode abbrev: \nsExpansion for %s: ", 254 "sDefine mode abbrev: \nsExpansion for %s: ",
188 doc: /* Define ABBREV as a mode-specific abbreviation for EXPANSION. */) 255 doc: /* Define ABBREV as a mode-specific abbreviation for EXPANSION.
256The characters in ABBREV must all be word-constituents in the current mode. */)
189 (abbrev, expansion) 257 (abbrev, expansion)
190 Lisp_Object abbrev, expansion; 258 Lisp_Object abbrev, expansion;
191{ 259{
192 if (NILP (current_buffer->abbrev_table)) 260 if (NILP (current_buffer->abbrev_table))
193 error ("Major mode has no abbrev table"); 261 error ("Major mode has no abbrev table");
194 262
263 abbrev_check_chars (abbrev, 0);
264
195 Fdefine_abbrev (current_buffer->abbrev_table, Fdowncase (abbrev), 265 Fdefine_abbrev (current_buffer->abbrev_table, Fdowncase (abbrev),
196 expansion, Qnil, make_number (0), Qnil); 266 expansion, Qnil, make_number (0), Qnil);
197 return abbrev; 267 return abbrev;