]> code.delx.au - gnu-emacs/blobdiff - src/abbrev.c
(lgrep, rgrep): Use add-to-history.
[gnu-emacs] / src / abbrev.c
index 6e973e9c307c3ad5079a957dfff07e5e7eecb86e..e371797f139b17b35d5470af6152f3546838dfa2 100644 (file)
@@ -1,6 +1,6 @@
 /* Primitives for word-abbrev mode.
-   Copyright (C) 1985, 1986, 1993, 1996, 1998, 2001
-   Free Software Foundation, Inc.
+   Copyright (C) 1985, 1986, 1993, 1996, 1998, 2001, 2002, 2003, 2004,
+                 2005, 2006 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -16,8 +16,8 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with GNU Emacs; see the file COPYING.  If not, write to
-the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.  */
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.  */
 
 
 #include <config.h>
@@ -238,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;
 
@@ -289,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;
 
@@ -342,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);
+
       SET_PT (PT + whitecnt);
 
       if (uccount && !lccount)
@@ -425,7 +442,7 @@ is not undone.  */)
 
       val = SYMBOL_VALUE (Vlast_abbrev);
       if (!STRINGP (val))
-       error ("value of abbrev-symbol must be a string");
+       error ("Value of `abbrev-symbol' must be a string");
       zv_before = ZV;
       del_range_byte (PT_BYTE, PT_BYTE + SBYTES (val), 1);
       /* Don't inherit properties here; just copy from old contents.  */
@@ -514,6 +531,13 @@ describe_abbrev (sym, stream)
   Fterpri (stream);
 }
 
+static void
+record_symbol (sym, list)
+     Lisp_Object sym, list;
+{
+  XSETCDR (list, Fcons (sym, XCDR (list)));
+}
+
 DEFUN ("insert-abbrev-table-description", Finsert_abbrev_table_description,
        Sinsert_abbrev_table_description, 1, 2, 0,
        doc: /* Insert before point a full description of abbrev table named NAME.
@@ -523,11 +547,13 @@ 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;
 {
   Lisp_Object table;
+  Lisp_Object symbols;
   Lisp_Object stream;
 
   CHECK_SYMBOL (name);
@@ -536,12 +562,22 @@ Abbrevs marked as "system abbrevs" are omitted.  */)
 
   XSETBUFFER (stream, current_buffer);
 
+  symbols = Fcons (Qnil, Qnil);
+  map_obarray (table, record_symbol, symbols);
+  symbols = XCDR (symbols);
+  symbols = Fsort (symbols, Qstring_lessp);
+
   if (!NILP (readable))
     {
       insert_string ("(");
       Fprin1 (name, stream);
       insert_string (")\n\n");
-      map_obarray (table, describe_abbrev, stream);
+      while (! NILP (symbols))
+       {
+         describe_abbrev (XCAR (symbols), stream);
+         symbols = XCDR (symbols);
+       }
+
       insert_string ("\n\n");
     }
   else
@@ -549,7 +585,11 @@ Abbrevs marked as "system abbrevs" are omitted.  */)
       insert_string ("(define-abbrev-table '");
       Fprin1 (name, stream);
       insert_string (" '(\n");
-      map_obarray (table, write_abbrev, stream);
+      while (! NILP (symbols))
+       {
+         write_abbrev (XCAR (symbols), stream);
+         symbols = XCDR (symbols);
+       }
       insert_string ("    ))\n\n");
     }
 
@@ -578,9 +618,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);
@@ -676,3 +716,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) */