/* Primitives for word-abbrev mode.
- Copyright (C) 1985, 1986 Free Software Foundation, Inc.
+ Copyright (C) 1985, 1986, 1993 Free Software Foundation, Inc.
This file is part of GNU Emacs.
GNU Emacs is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 1, or (at your option)
+the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Emacs is distributed in the hope that it will be useful,
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
-#include "config.h"
+#include <config.h>
#include <stdio.h>
#include "lisp.h"
#include "commands.h"
#include "buffer.h"
#include "window.h"
+#include "syntax.h"
/* An abbrev table is an obarray.
Each defined abbrev is represented by a symbol in that obarray
oexp = XSYMBOL (sym)->value;
ohook = XSYMBOL (sym)->function;
if (!((EQ (oexp, expansion)
- || (XTYPE (oexp) == Lisp_String && XTYPE (expansion) == Lisp_String
+ || (STRINGP (oexp) && STRINGP (expansion)
&& (tem = Fstring_equal (oexp, expansion), !NILP (tem))))
&&
(EQ (ohook, hook)
if (!NILP (Vrun_hooks))
call1 (Vrun_hooks, Qpre_abbrev_expand_hook);
- /* If the hook changes the buffer, treat that as
- having "done an expansion". */
+ /* If the hook changes the buffer, treat that as having "done an
+ expansion". */
value = (MODIFF != oldmodiff ? Qt : Qnil);
- if (XBUFFER (Vabbrev_start_location_buffer) != current_buffer)
+ wordstart = 0;
+ if (!(BUFFERP (Vabbrev_start_location_buffer) &&
+ XBUFFER (Vabbrev_start_location_buffer) == current_buffer))
Vabbrev_start_location = Qnil;
if (!NILP (Vabbrev_start_location))
{
CHECK_NUMBER_COERCE_MARKER (tem, 0);
wordstart = XINT (tem);
Vabbrev_start_location = Qnil;
- if (FETCH_CHAR (wordstart) == '-')
+ if (wordstart < BEGV || wordstart > ZV)
+ wordstart = 0;
+ if (wordstart && wordstart != ZV && FETCH_CHAR (wordstart) == '-')
del_range (wordstart, wordstart + 1);
}
- else
+ if (!wordstart)
wordstart = scan_words (point, -1);
if (!wordstart)
p = buffer = (char *) alloca (wordend - wordstart);
- for (idx = wordstart; idx < point; idx++)
+ for (idx = wordstart; idx < wordend; idx++)
{
register int c = FETCH_CHAR (idx);
if (UPPERCASEP (c))
*p++ = c;
}
- if (XTYPE (current_buffer->abbrev_table) == Lisp_Vector)
+ if (VECTORP (current_buffer->abbrev_table))
sym = oblookup (current_buffer->abbrev_table, buffer, p - buffer);
else
- XFASTINT (sym) = 0;
- if (XTYPE (sym) == Lisp_Int || NILP (XSYMBOL (sym)->value))
+ XSETFASTINT (sym, 0);
+ if (INTEGERP (sym) || NILP (XSYMBOL (sym)->value))
sym = oblookup (Vglobal_abbrev_table, buffer, p - buffer);
- if (XTYPE (sym) == Lisp_Int || NILP (XSYMBOL (sym)->value))
+ if (INTEGERP (sym) || NILP (XSYMBOL (sym)->value))
return value;
if (INTERACTIVE && !EQ (minibuf_window, selected_window))
{
+ /* Add an undo boundary, in case we are doing this for
+ a self-inserting command which has avoided making one so far. */
SET_PT (wordend);
Fundo_boundary ();
}
Vlast_abbrev = sym;
last_abbrev_point = wordstart;
- if (XTYPE (XSYMBOL (sym)->plist) == Lisp_Int)
+ if (INTEGERP (XSYMBOL (sym)->plist))
XSETINT (XSYMBOL (sym)->plist,
XINT (XSYMBOL (sym)->plist) + 1); /* Increment use count */
expansion = XSYMBOL (sym)->value;
- insert_from_string (expansion, 0, XSTRING (expansion)->size);
+ insert_from_string (expansion, 0, XSTRING (expansion)->size, 1);
SET_PT (point + whitecnt);
if (uccount && !lccount)
if (!abbrev_all_caps)
if (scan_words (point, -1) > scan_words (wordstart, 1))
{
- upcase_initials_region (make_number (wordstart),
- make_number (point));
+ Fupcase_initials_region (make_number (wordstart),
+ make_number (point));
goto caped;
}
/* If expansion is one word, or if user says so, upcase it all. */
else if (uccount)
{
/* Abbrev included some caps. Cap first initial of expansion */
- int old_zv = ZV;
- int old_pt = point;
+ int pos = wordstart;
- /* Don't let Fcapitalize_word operate on text after point. */
- ZV = point;
- SET_PT (wordstart);
- Fcapitalize_word (make_number (1));
+ /* Find the initial. */
+ while (pos < point
+ && SYNTAX (*BUF_CHAR_ADDRESS (current_buffer, pos)) != Sword)
+ pos++;
- SET_PT (old_pt);
- ZV = old_zv;
+ /* Change just that. */
+ Fupcase_initials_region (make_number (pos), make_number (pos + 1));
}
hook = XSYMBOL (sym)->function;
|| last_abbrev_point > ZV)
return Qnil;
SET_PT (last_abbrev_point);
- if (XTYPE (Vlast_abbrev_text) == Lisp_String)
+ if (STRINGP (Vlast_abbrev_text))
{
/* This isn't correct if Vlast_abbrev->function was used
to do the expansion */
Lisp_Object val;
- XSET (val, Lisp_String, XSYMBOL (Vlast_abbrev)->value);
+ val = XSYMBOL (Vlast_abbrev)->value;
+ if (!STRINGP (val))
+ error ("value of abbrev-symbol must be a string");
adjust = XSTRING (val)->size;
del_range (point, point + adjust);
+ /* Don't inherit properties here; just copy from old contents. */
insert_from_string (Vlast_abbrev_text, 0,
- XSTRING (Vlast_abbrev_text)->size);
+ XSTRING (Vlast_abbrev_text)->size, 0);
adjust -= XSTRING (Vlast_abbrev_text)->size;
Vlast_abbrev_text = Qnil;
}
if (NILP (XSYMBOL (sym)->value))
return;
insert (" (", 5);
- XSET (name, Lisp_String, XSYMBOL (sym)->name);
+ XSETSTRING (name, XSYMBOL (sym)->name);
Fprin1 (name, stream);
insert (" ", 1);
Fprin1 (XSYMBOL (sym)->value, stream);
table = Fsymbol_value (name);
CHECK_VECTOR (table, 0);
- XSET (stream, Lisp_Buffer, current_buffer);
+ XSETBUFFER (stream, current_buffer);
if (!NILP (readable))
{
Trying to expand an abbrev in any other buffer clears `abbrev-start-location'.");
Vabbrev_start_location_buffer = Qnil;
- DEFVAR_PER_BUFFER ("local-abbrev-table", ¤t_buffer->abbrev_table,
+ DEFVAR_PER_BUFFER ("local-abbrev-table", ¤t_buffer->abbrev_table, Qnil,
"Local (mode-specific) abbrev table of current buffer.");
DEFVAR_BOOL ("abbrevs-changed", &abbrevs_changed,