/[emacs]/emacs/src/abbrev.c
ViewVC logotype

Diff of /emacs/src/abbrev.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.47 by rms, Mon Nov 26 00:05:33 2001 UTC revision 1.48 by rms, Fri Dec 28 22:14:23 2001 UTC
# Line 82  int last_abbrev_point; Line 82  int last_abbrev_point;
82  /* Hook to run before expanding any abbrev.  */  /* Hook to run before expanding any abbrev.  */
83    
84  Lisp_Object Vpre_abbrev_expand_hook, Qpre_abbrev_expand_hook;  Lisp_Object Vpre_abbrev_expand_hook, Qpre_abbrev_expand_hook;
85    
86    Lisp_Object Qsystem_type, Qcount;
87    
88  DEFUN ("make-abbrev-table", Fmake_abbrev_table, Smake_abbrev_table, 0, 0, 0,  DEFUN ("make-abbrev-table", Fmake_abbrev_table, Smake_abbrev_table, 0, 0, 0,
89         doc: /* Create a new, empty abbrev table object.  */)         doc: /* Create a new, empty abbrev table object.  */)
# Line 105  DEFUN ("clear-abbrev-table", Fclear_abbr Line 107  DEFUN ("clear-abbrev-table", Fclear_abbr
107    return Qnil;    return Qnil;
108  }  }
109    
110  DEFUN ("define-abbrev", Fdefine_abbrev, Sdefine_abbrev, 3, 5, 0,  DEFUN ("define-abbrev", Fdefine_abbrev, Sdefine_abbrev, 3, 6, 0,
111         doc: /* Define an abbrev in TABLE named NAME, to expand to EXPANSION and call HOOK.         doc: /* Define an abbrev in TABLE named NAME, to expand to EXPANSION and call HOOK.
112  NAME must be a string.  NAME must be a string.
113  EXPANSION should usually be a string.  EXPANSION should usually be a string.
# Line 114  If HOOK is non-nil, it should be a funct Line 116  If HOOK is non-nil, it should be a funct
116  it is called after EXPANSION is inserted.  it is called after EXPANSION is inserted.
117  If EXPANSION is not a string, the abbrev is a special one,  If EXPANSION is not a string, the abbrev is a special one,
118   which does not expand in the usual way but only runs HOOK.   which does not expand in the usual way but only runs HOOK.
119  COUNT, if specified, initializes the abbrev's usage-count  
120  which is incremented each time the abbrev is used.  */)  COUNT, if specified, gives the initial value for the abbrev's
121       (table, name, expansion, hook, count)  usage-count, which is incremented each time the abbrev is used.
122       Lisp_Object table, name, expansion, hook, count;  \(The default is zero.)
123    
124    SYSTEM-FLAG, if non-nil, says that this is a "system" abbreviation
125    which should not be saved in the user's abbreviation file.  */)
126         (table, name, expansion, hook, count, system_flag)
127         Lisp_Object table, name, expansion, hook, count, system_flag;
128  {  {
129    Lisp_Object sym, oexp, ohook, tem;    Lisp_Object sym, oexp, ohook, tem;
130    CHECK_VECTOR (table);    CHECK_VECTOR (table);
# Line 137  which is incremented each time the abbre Line 144  which is incremented each time the abbre
144               && (tem = Fstring_equal (oexp, expansion), !NILP (tem))))               && (tem = Fstring_equal (oexp, expansion), !NILP (tem))))
145          &&          &&
146          (EQ (ohook, hook)          (EQ (ohook, hook)
147           || (tem = Fequal (ohook, hook), !NILP (tem)))))           || (tem = Fequal (ohook, hook), !NILP (tem))))
148          && NILP (system_flag))
149      abbrevs_changed = 1;      abbrevs_changed = 1;
150    
151    Fset (sym, expansion);    Fset (sym, expansion);
152    Ffset (sym, hook);    Ffset (sym, hook);
153    Fsetplist (sym, count);  
154      if (! NILP (system_flag))
155        Fsetplist (sym, list4 (Qcount, count, Qsystem_type, system_flag));
156      else
157        Fsetplist (sym, count);
158    
159    return name;    return name;
160  }  }
# Line 154  DEFUN ("define-global-abbrev", Fdefine_g Line 166  DEFUN ("define-global-abbrev", Fdefine_g
166       Lisp_Object abbrev, expansion;       Lisp_Object abbrev, expansion;
167  {  {
168    Fdefine_abbrev (Vglobal_abbrev_table, Fdowncase (abbrev),    Fdefine_abbrev (Vglobal_abbrev_table, Fdowncase (abbrev),
169                    expansion, Qnil, make_number (0));                    expansion, Qnil, make_number (0), Qnil);
170    return abbrev;    return abbrev;
171  }  }
172    
# Line 168  DEFUN ("define-mode-abbrev", Fdefine_mod Line 180  DEFUN ("define-mode-abbrev", Fdefine_mod
180      error ("Major mode has no abbrev table");      error ("Major mode has no abbrev table");
181    
182    Fdefine_abbrev (current_buffer->abbrev_table, Fdowncase (abbrev),    Fdefine_abbrev (current_buffer->abbrev_table, Fdowncase (abbrev),
183                    expansion, Qnil, make_number (0));                    expansion, Qnil, make_number (0), Qnil);
184    return abbrev;    return abbrev;
185  }  }
186    
# Line 292  Returns the abbrev symbol, if expansion Line 304  Returns the abbrev symbol, if expansion
304                      wordend - wordstart, wordend_byte - wordstart_byte);                      wordend - wordstart, wordend_byte - wordstart_byte);
305    else    else
306      XSETFASTINT (sym, 0);      XSETFASTINT (sym, 0);
307    
308    if (INTEGERP (sym) || NILP (SYMBOL_VALUE (sym)))    if (INTEGERP (sym) || NILP (SYMBOL_VALUE (sym)))
309      sym = oblookup (Vglobal_abbrev_table, buffer,      sym = oblookup (Vglobal_abbrev_table, buffer,
310                      wordend - wordstart, wordend_byte - wordstart_byte);                      wordend - wordstart, wordend_byte - wordstart_byte);
# Line 314  Returns the abbrev symbol, if expansion Line 327  Returns the abbrev symbol, if expansion
327    value = sym;    value = sym;
328    last_abbrev_point = wordstart;    last_abbrev_point = wordstart;
329    
330      /* Increment use count.  */
331    if (INTEGERP (XSYMBOL (sym)->plist))    if (INTEGERP (XSYMBOL (sym)->plist))
332      XSETINT (XSYMBOL (sym)->plist,      XSETINT (XSYMBOL (sym)->plist,
333               XINT (XSYMBOL (sym)->plist) + 1);  /* Increment use count */               XINT (XSYMBOL (sym)->plist) + 1);
334      else if (tem = Fget (sym, Qcount))
335        Fput (sym, Qcount, make_number (XINT (tem) + 1));
336    
337    /* If this abbrev has an expansion, delete the abbrev    /* If this abbrev has an expansion, delete the abbrev
338       and insert the expansion.  */       and insert the expansion.  */
# Line 427  static void Line 443  static void
443  write_abbrev (sym, stream)  write_abbrev (sym, stream)
444       Lisp_Object sym, stream;       Lisp_Object sym, stream;
445  {  {
446    Lisp_Object name;    Lisp_Object name, count, system_flag;
447    if (NILP (SYMBOL_VALUE (sym)))  
448      if (INTEGERP (XSYMBOL (sym)->plist))
449        {
450          count = XSYMBOL (sym)->plist;
451          system_flag = Qnil;
452        }
453      else
454        {
455          count = Fget (sym, Qcount);
456          system_flag = Fget (sym, Qsystem_type);
457        }
458    
459      if (NILP (SYMBOL_VALUE (sym)) || ! NILP (system_flag))
460      return;      return;
461    
462    insert ("    (", 5);    insert ("    (", 5);
463    XSETSTRING (name, XSYMBOL (sym)->name);    XSETSTRING (name, XSYMBOL (sym)->name);
464    Fprin1 (name, stream);    Fprin1 (name, stream);
# Line 438  write_abbrev (sym, stream) Line 467  write_abbrev (sym, stream)
467    insert (" ", 1);    insert (" ", 1);
468    Fprin1 (XSYMBOL (sym)->function, stream);    Fprin1 (XSYMBOL (sym)->function, stream);
469    insert (" ", 1);    insert (" ", 1);
470    Fprin1 (XSYMBOL (sym)->plist, stream);    Fprin1 (count, stream);
471    insert (")\n", 2);    insert (")\n", 2);
472  }  }
473    
# Line 446  static void Line 475  static void
475  describe_abbrev (sym, stream)  describe_abbrev (sym, stream)
476       Lisp_Object sym, stream;       Lisp_Object sym, stream;
477  {  {
478    Lisp_Object one;    Lisp_Object one, count, system_flag;
479    
480      if (INTEGERP (XSYMBOL (sym)->plist))
481        {
482          count = XSYMBOL (sym)->plist;
483          system_flag = Qnil;
484        }
485      else
486        {
487          count = Fget (sym, Qcount);
488          system_flag = Fget (sym, Qsystem_type);
489        }
490    
491    if (NILP (SYMBOL_VALUE (sym)))    if (NILP (SYMBOL_VALUE (sym)))
492      return;      return;
493    
494    one = make_number (1);    one = make_number (1);
495    Fprin1 (Fsymbol_name (sym), stream);    Fprin1 (Fsymbol_name (sym), stream);
496    Findent_to (make_number (15), one);  
497    Fprin1 (XSYMBOL (sym)->plist, stream);    if (!NILP (system_flag))
498        {
499          insert_string (" (sys)");
500          Findent_to (make_number (20), one);
501        }
502      else
503        Findent_to (make_number (15), one);
504    
505      Fprin1 (count, stream);
506    Findent_to (make_number (20), one);    Findent_to (make_number (20), one);
507    Fprin1 (SYMBOL_VALUE (sym), stream);    Fprin1 (SYMBOL_VALUE (sym), stream);
508    if (!NILP (XSYMBOL (sym)->function))    if (!NILP (XSYMBOL (sym)->function))
# Line 471  NAME is a symbol whose value is an abbre Line 520  NAME is a symbol whose value is an abbre
520  If optional 2nd arg READABLE is non-nil, a human-readable description  If optional 2nd arg READABLE is non-nil, a human-readable description
521  is inserted.  Otherwise the description is an expression,  is inserted.  Otherwise the description is an expression,
522  a call to `define-abbrev-table', which would  a call to `define-abbrev-table', which would
523  define the abbrev table NAME exactly as it is currently defined.  */)  define the abbrev table NAME exactly as it is currently defined.
524    
525    Abbrevs marked as "system abbrevs" are omitted.  */)
526       (name, readable)       (name, readable)
527       Lisp_Object name, readable;       Lisp_Object name, readable;
528  {  {
# Line 508  DEFUN ("define-abbrev-table", Fdefine_ab Line 559  DEFUN ("define-abbrev-table", Fdefine_ab
559         2, 2, 0,         2, 2, 0,
560         doc: /* Define TABLENAME (a symbol) as an abbrev table name.         doc: /* Define TABLENAME (a symbol) as an abbrev table name.
561  Define abbrevs in it according to DEFINITIONS, which is a list of elements  Define abbrevs in it according to DEFINITIONS, which is a list of elements
562  of the form (ABBREVNAME EXPANSION HOOK USECOUNT).  */)  of the form (ABBREVNAME EXPANSION HOOK USECOUNT SYSTEMFLAG).
563    \(If the list is shorter than that, omitted elements default to nil).  */)
564       (tablename, definitions)       (tablename, definitions)
565       Lisp_Object tablename, definitions;       Lisp_Object tablename, definitions;
566  {  {
567    Lisp_Object name, exp, hook, count;    Lisp_Object name, exp, hook, count;
568    Lisp_Object table, elt;    Lisp_Object table, elt, sys;
569    
570    CHECK_SYMBOL (tablename);    CHECK_SYMBOL (tablename);
571    table = Fboundp (tablename);    table = Fboundp (tablename);
# Line 531  of the form (ABBREVNAME EXPANSION HOOK U Line 583  of the form (ABBREVNAME EXPANSION HOOK U
583        name  = Fcar (elt);       elt = Fcdr (elt);        name  = Fcar (elt);       elt = Fcdr (elt);
584        exp   = Fcar (elt);       elt = Fcdr (elt);        exp   = Fcar (elt);       elt = Fcdr (elt);
585        hook  = Fcar (elt);       elt = Fcdr (elt);        hook  = Fcar (elt);       elt = Fcdr (elt);
586        count = Fcar (elt);        count = Fcar (elt);       elt = Fcdr (elt);
587        Fdefine_abbrev (table, name, exp, hook, count);        sys   = Fcar (elt);
588          Fdefine_abbrev (table, name, exp, hook, count, sys);
589      }      }
590    return Qnil;    return Qnil;
591  }  }
# Line 540  of the form (ABBREVNAME EXPANSION HOOK U Line 593  of the form (ABBREVNAME EXPANSION HOOK U
593  void  void
594  syms_of_abbrev ()  syms_of_abbrev ()
595  {  {
596      Qsystem_type = intern ("system-type");
597      staticpro (&Qsystem_type);
598    
599      Qcount = intern ("count");
600      staticpro (&Qcount);
601    
602    DEFVAR_LISP ("abbrev-table-name-list", &Vabbrev_table_name_list,    DEFVAR_LISP ("abbrev-table-name-list", &Vabbrev_table_name_list,
603                 doc: /* List of symbols whose values are abbrev tables.  */);                 doc: /* List of symbols whose values are abbrev tables.  */);
604    Vabbrev_table_name_list = Fcons (intern ("fundamental-mode-abbrev-table"),    Vabbrev_table_name_list = Fcons (intern ("fundamental-mode-abbrev-table"),

Legend:
Removed from v.1.47  
changed lines
  Added in v.1.48

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26