]> code.delx.au - gnu-emacs/blobdiff - src/abbrev.c
*** empty log message ***
[gnu-emacs] / src / abbrev.c
index 0412a062bcfafadd12835e38caa083b67635ca3e..9a7640b872ce4d7da755f70ecb079227516a0a55 100644 (file)
@@ -20,7 +20,6 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 #include "config.h"
 #include <stdio.h>
-#undef NULL
 #include "lisp.h"
 #include "commands.h"
 #include "buffer.h"
@@ -75,6 +74,9 @@ Lisp_Object Vlast_abbrev_text;
 
 int last_abbrev_point;
 
+/* Hook to run before expanding any abbrev.  */
+
+Lisp_Object Vpre_abbrev_expand_hook, Qpre_abbrev_expand_hook;
 \f
 DEFUN ("make-abbrev-table", Fmake_abbrev_table, Smake_abbrev_table, 0, 0, 0,
   "Create a new, empty abbrev table object.")
@@ -110,9 +112,9 @@ it is called after EXPANSION is inserted.")
   Lisp_Object sym, oexp, ohook, tem;
   CHECK_VECTOR (table, 0);
   CHECK_STRING (name, 1);
-  if (!NULL (expansion))
+  if (!NILP (expansion))
     CHECK_STRING (expansion, 2);
-  if (NULL (count))
+  if (NILP (count))
     count = make_number (0);
   else
     CHECK_NUMBER (count, 0);
@@ -123,10 +125,10 @@ it is called after EXPANSION is inserted.")
   ohook = XSYMBOL (sym)->function;
   if (!((EQ (oexp, expansion)
         || (XTYPE (oexp) == Lisp_String && XTYPE (expansion) == Lisp_String
-            && (tem = Fstring_equal (oexp, expansion), !NULL (tem))))
+            && (tem = Fstring_equal (oexp, expansion), !NILP (tem))))
        &&
        (EQ (ohook, hook)
-        || (tem = Fequal (ohook, hook), !NULL (tem)))))
+        || (tem = Fequal (ohook, hook), !NILP (tem)))))
     abbrevs_changed = 1;
 
   Fset (sym, expansion);
@@ -153,7 +155,7 @@ DEFUN ("define-mode-abbrev", Fdefine_mode_abbrev, Sdefine_mode_abbrev, 2, 2,
   (name, expansion)
      Lisp_Object name, expansion;
 {
-  if (NULL (current_buffer->abbrev_table))
+  if (NILP (current_buffer->abbrev_table))
     error ("Major mode has no abbrev table");
 
   Fdefine_abbrev (current_buffer->abbrev_table, Fdowncase (name),
@@ -173,19 +175,19 @@ The default is to try buffer's mode-specific abbrev table, then global table.")
 {
   Lisp_Object sym;
   CHECK_STRING (abbrev, 0);
-  if (!NULL (table))
+  if (!NILP (table))
     sym = Fintern_soft (abbrev, table);
   else
     {
       sym = Qnil;
-      if (!NULL (current_buffer->abbrev_table))
+      if (!NILP (current_buffer->abbrev_table))
        sym = Fintern_soft (abbrev, current_buffer->abbrev_table);
-      if (NULL (XSYMBOL (sym)->value))
+      if (NILP (XSYMBOL (sym)->value))
        sym = Qnil;
-      if (NULL (sym))
+      if (NILP (sym))
        sym = Fintern_soft (abbrev, Vglobal_abbrev_table);
     }
-  if (NULL (XSYMBOL (sym)->value)) return Qnil;
+  if (NILP (XSYMBOL (sym)->value)) return Qnil;
   return sym;
 }
 
@@ -198,7 +200,7 @@ then ABBREV is looked up in that table only.")
 {
   Lisp_Object sym;
   sym = Fabbrev_symbol (abbrev, table);
-  if (NULL (sym)) return sym;
+  if (NILP (sym)) return sym;
   return Fsymbol_value (sym);
 }
 \f
@@ -218,9 +220,12 @@ Returns t if expansion took place.")
   register Lisp_Object sym;
   Lisp_Object expansion, hook, tem;
 
+  if (!NILP (Vrun_hooks))
+    call1 (Vrun_hooks, Qpre_abbrev_expand_hook);
+
   if (XBUFFER (Vabbrev_start_location_buffer) != current_buffer)
     Vabbrev_start_location = Qnil;
-  if (!NULL (Vabbrev_start_location))
+  if (!NILP (Vabbrev_start_location))
     {
       tem = Vabbrev_start_location;
       CHECK_NUMBER_COERCE_MARKER (tem, 0);
@@ -261,9 +266,9 @@ Returns t if expansion took place.")
     sym = oblookup (current_buffer->abbrev_table, buffer, p - buffer);
   else
     XFASTINT (sym) = 0;
-  if (XTYPE (sym) == Lisp_Int || NULL (XSYMBOL (sym)->value))
+  if (XTYPE (sym) == Lisp_Int || NILP (XSYMBOL (sym)->value))
     sym = oblookup (Vglobal_abbrev_table, buffer, p - buffer);
-  if (XTYPE (sym) == Lisp_Int || NULL (XSYMBOL (sym)->value))
+  if (XTYPE (sym) == Lisp_Int || NILP (XSYMBOL (sym)->value))
     return Qnil;
 
   if (INTERACTIVE && !EQ (minibuf_window, selected_window))
@@ -308,14 +313,20 @@ Returns t if expansion took place.")
   else if (uccount)
     {
       /* Abbrev included some caps.  Cap first initial of expansion */
-      idx = point;
+      int old_zv = ZV;
+      int old_pt = point;
+
+      /* Don't let Fcapitalize_word operate on text after point.  */
+      ZV = point;
       SET_PT (wordstart);
       Fcapitalize_word (make_number (1));
-      SET_PT (idx);
+
+      SET_PT (old_pt);
+      ZV = old_zv;
     }
 
   hook = XSYMBOL (sym)->function;
-  if (!NULL (hook))
+  if (!NILP (hook))
     call0 (hook);
 
   return Qt;
@@ -355,7 +366,7 @@ write_abbrev (sym, stream)
      Lisp_Object sym, stream;
 {
   Lisp_Object name;
-  if (NULL (XSYMBOL (sym)->value))
+  if (NILP (XSYMBOL (sym)->value))
     return;
   insert ("    (", 5);
   XSET (name, Lisp_String, XSYMBOL (sym)->name);
@@ -375,7 +386,7 @@ describe_abbrev (sym, stream)
 {
   Lisp_Object one;
 
-  if (NULL (XSYMBOL (sym)->value))
+  if (NILP (XSYMBOL (sym)->value))
     return;
   one = make_number (1);
   Fprin1 (Fsymbol_name (sym), stream);
@@ -383,7 +394,7 @@ describe_abbrev (sym, stream)
   Fprin1 (XSYMBOL (sym)->plist, stream);
   Findent_to (make_number (20), one);
   Fprin1 (XSYMBOL (sym)->value, stream);
-  if (!NULL (XSYMBOL (sym)->function))
+  if (!NILP (XSYMBOL (sym)->function))
     {
       Findent_to (make_number (45), one);
       Fprin1 (XSYMBOL (sym)->function, stream);
@@ -412,7 +423,7 @@ define the abbrev table NAME exactly as it is currently defined.")
 
   XSET (stream, Lisp_Buffer, current_buffer);
 
-  if (!NULL (readable))
+  if (!NILP (readable))
     {
       insert_string ("(");
       Fprin1 (name, stream);
@@ -445,7 +456,7 @@ of the form (ABBREVNAME EXPANSION HOOK USECOUNT).")
 
   CHECK_SYMBOL (tabname, 0);
   table = Fboundp (tabname);
-  if (NULL (table) || (table = Fsymbol_value (tabname), NULL (table)))
+  if (NILP (table) || (table = Fsymbol_value (tabname), NILP (table)))
     {
       table = Fmake_abbrev_table ();
       Fset (tabname, table);
@@ -454,7 +465,7 @@ of the form (ABBREVNAME EXPANSION HOOK USECOUNT).")
     }
   CHECK_VECTOR (table, 0);
 
-  for (;!NULL (defns); defns = Fcdr (defns))
+  for (;!NILP (defns); defns = Fcdr (defns))
     {
       elt = Fcar (defns);
       name = Fcar (elt);
@@ -526,6 +537,14 @@ This causes `save-some-buffers' to offer to save the abbrevs.");
     "*Set non-nil means expand multi-word abbrevs all caps if abbrev was so.");
   abbrev_all_caps = 0;
 
+  DEFVAR_LISP ("pre-abbrev-expand-hook", &Vpre_abbrev_expand_hook,
+    "Function or functions to be called before abbrev expansion is done.\n\
+This is the first thing that `expand-abbrev' does, and so this may change\n\
+the current abbrev table before abbrev lookup happens.");
+  Vpre_abbrev_expand_hook = Qnil;
+  Qpre_abbrev_expand_hook = intern ("pre-abbrev-expand-hook");
+  staticpro (&Qpre_abbrev_expand_hook);
+
   defsubr (&Smake_abbrev_table);
   defsubr (&Sclear_abbrev_table);
   defsubr (&Sdefine_abbrev);