]> code.delx.au - gnu-emacs/blobdiff - src/abbrev.c
Revision: miles@gnu.org--gnu-2005/emacs--unicode--0--patch-61
[gnu-emacs] / src / abbrev.c
index d134f95f25bd195c96800ad9eb6d57671c1a169d..086a58021fb381ef9ce415c13461c252f227d924 100644 (file)
@@ -1,5 +1,5 @@
 /* Primitives for word-abbrev mode.
-   Copyright (C) 1985, 1986, 1993, 1996, 1998, 2001
+   Copyright (C) 1985, 1986, 1993, 1996, 1998, 2001,02,03,04
    Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
@@ -27,7 +27,7 @@ Boston, MA 02111-1307, USA.  */
 #include "commands.h"
 #include "buffer.h"
 #include "window.h"
-#include "charset.h"
+#include "character.h"
 #include "syntax.h"
 
 /* An abbrev table is an obarray.
@@ -77,7 +77,7 @@ Lisp_Object Vlast_abbrev_text;
 
 /* Character address of start of last abbrev expanded */
 
-int last_abbrev_point;
+EMACS_INT last_abbrev_point;
 
 /* Hook to run before expanding any abbrev.  */
 
@@ -89,6 +89,7 @@ DEFUN ("make-abbrev-table", Fmake_abbrev_table, Smake_abbrev_table, 0, 0, 0,
        doc: /* Create a new, empty abbrev table object.  */)
      ()
 {
+  /* The value 59 is arbitrary chosen prime number.  */
   return Fmake_vector (make_number (59), make_number (0));
 }
 
@@ -237,12 +238,13 @@ Returns the abbrev symbol, if expansion took place.  */)
 {
   register char *buffer, *p;
   int wordstart, wordend;
-  register int wordstart_byte, wordend_byte, idx;
+  register int wordstart_byte, wordend_byte, idx, idx_byte;
   int whitecnt;
   int uccount = 0, lccount = 0;
   register Lisp_Object sym;
   Lisp_Object expansion, hook, tem;
   Lisp_Object value;
+  int multibyte = ! NILP (current_buffer->enable_multibyte_characters);
 
   value = Qnil;
 
@@ -288,26 +290,39 @@ Returns the abbrev symbol, if expansion took place.  */)
 
   p = buffer = (char *) alloca (wordend_byte - wordstart_byte);
 
-  for (idx = wordstart_byte; idx < wordend_byte; idx++)
+  for (idx = wordstart, idx_byte = wordstart_byte; idx < wordend; )
     {
-      /* ??? This loop needs to go by characters!  */
-      register int c = FETCH_BYTE (idx);
+      register int c;
+
+      if (multibyte)
+       {
+         FETCH_CHAR_ADVANCE (c, idx, idx_byte);
+       }
+      else
+       {
+         c = FETCH_BYTE (idx_byte);
+         idx++, idx_byte++;
+       }
+
       if (UPPERCASEP (c))
        c = DOWNCASE (c), uccount++;
       else if (! NOCASEP (c))
        lccount++;
-      *p++ = c;
+      if (multibyte)
+       p += CHAR_STRING (c, p);
+      else
+       *p++ = c;
     }
 
   if (VECTORP (current_buffer->abbrev_table))
     sym = oblookup (current_buffer->abbrev_table, buffer,
-                   wordend - wordstart, wordend_byte - wordstart_byte);
+                   wordend - wordstart, p - buffer);
   else
     XSETFASTINT (sym, 0);
 
   if (INTEGERP (sym) || NILP (SYMBOL_VALUE (sym)))
     sym = oblookup (Vglobal_abbrev_table, buffer,
-                   wordend - wordstart, wordend_byte - wordstart_byte);
+                   wordend - wordstart, p - buffer);
   if (INTEGERP (sym) || NILP (SYMBOL_VALUE (sym)))
     return value;
 
@@ -341,10 +356,13 @@ Returns the abbrev symbol, if expansion took place.  */)
     {
       SET_PT (wordstart);
 
-      del_range_both (wordstart, wordstart_byte, wordend, wordend_byte, 1);
+      insert_from_string (expansion, 0, 0, SCHARS (expansion),
+                         SBYTES (expansion), 1);
+      del_range_both (PT, PT_BYTE,
+                     wordend + (PT - wordstart),
+                     wordend_byte + (PT_BYTE - wordstart_byte),
+                     1);
 
-      insert_from_string (expansion, 0, 0, XSTRING (expansion)->size,
-                         STRING_BYTES (XSTRING (expansion)), 1);
       SET_PT (PT + whitecnt);
 
       if (uccount && !lccount)
@@ -370,9 +388,15 @@ Returns the abbrev symbol, if expansion took place.  */)
          int pos = wordstart_byte;
 
          /* Find the initial.  */
-         while (pos < PT_BYTE
-                && SYNTAX (*BUF_BYTE_ADDRESS (current_buffer, pos)) != Sword)
-           pos++;
+         if (multibyte)
+           while (pos < PT_BYTE
+                  && SYNTAX (FETCH_MULTIBYTE_CHAR (pos)) != Sword)
+             INC_POS (pos);
+         else
+           while (pos < PT_BYTE
+                  && (SYNTAX (*BUF_BYTE_ADDRESS (current_buffer, pos))
+                      != Sword))
+             pos++;
 
          /* Change just that.  */
          pos = BYTE_TO_CHAR (pos);
@@ -388,8 +412,8 @@ Returns the abbrev symbol, if expansion took place.  */)
       /* If the abbrev has a hook function, run it.  */
       expanded = call0 (hook);
 
-      /* In addition, if the hook function is a symbol with a a
-        non-nil `no-self-insert' property, let the value it returned
+      /* In addition, if the hook function is a symbol with
+        non-nil `no-self-insert' property, let the value it returned
         specify whether we consider that an expansion took place.  If
         it returns nil, no expansion has been done.  */
 
@@ -426,11 +450,11 @@ is not undone.  */)
       if (!STRINGP (val))
        error ("value of abbrev-symbol must be a string");
       zv_before = ZV;
-      del_range_byte (PT_BYTE, PT_BYTE + STRING_BYTES (XSTRING (val)), 1);
+      del_range_byte (PT_BYTE, PT_BYTE + SBYTES (val), 1);
       /* Don't inherit properties here; just copy from old contents.  */
       insert_from_string (Vlast_abbrev_text, 0, 0,
-                         XSTRING (Vlast_abbrev_text)->size,
-                         STRING_BYTES (XSTRING (Vlast_abbrev_text)), 0);
+                         SCHARS (Vlast_abbrev_text),
+                         SBYTES (Vlast_abbrev_text), 0);
       Vlast_abbrev_text = Qnil;
       /* Total number of characters deleted.  */
       adjust = ZV - zv_before;
@@ -460,7 +484,7 @@ write_abbrev (sym, stream)
     return;
 
   insert ("    (", 5);
-  XSETSTRING (name, XSYMBOL (sym)->name);
+  name = SYMBOL_NAME (sym);
   Fprin1 (name, stream);
   insert (" ", 1);
   Fprin1 (SYMBOL_VALUE (sym), stream);
@@ -522,7 +546,8 @@ is inserted.  Otherwise the description is an expression,
 a call to `define-abbrev-table', which would
 define the abbrev table NAME exactly as it is currently defined.
 
-Abbrevs marked as "system abbrevs" are omitted.  */)
+Abbrevs marked as "system abbrevs" are normally omitted.  However, if
+READABLE is non-nil, they are listed.  */)
      (name, readable)
      Lisp_Object name, readable;
 {
@@ -577,9 +602,9 @@ of the form (ABBREVNAME EXPANSION HOOK USECOUNT SYSTEMFLAG).
     }
   CHECK_VECTOR (table);
 
-  for (; !NILP (definitions); definitions = Fcdr (definitions))
+  for (; CONSP (definitions); definitions = XCDR (definitions))
     {
-      elt = Fcar (definitions);
+      elt = XCAR (definitions);
       name  = Fcar (elt);      elt = Fcdr (elt);
       exp   = Fcar (elt);      elt = Fcdr (elt);
       hook  = Fcar (elt);      elt = Fcdr (elt);
@@ -634,7 +659,7 @@ nil if the abbrev has already been unexpanded.  */);
 
   DEFVAR_LISP ("abbrev-start-location", &Vabbrev_start_location,
               doc: /* Buffer position for `expand-abbrev' to use as the start of the abbrev.
-nil means use the word before point as the abbrev.
+When nil, use the word before point as the abbrev.
 Calling `expand-abbrev' sets this to nil.  */);
   Vabbrev_start_location = Qnil;
 
@@ -675,3 +700,6 @@ the current abbrev table before abbrev lookup happens.  */);
   defsubr (&Sinsert_abbrev_table_description);
   defsubr (&Sdefine_abbrev_table);
 }
+
+/* arch-tag: b721db69-f633-44a8-a361-c275acbdad7d
+   (do not change this comment) */