summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/lispref/abbrevs.texi62
-rw-r--r--etc/NEWS2
-rw-r--r--lisp/ChangeLog8
-rw-r--r--lisp/abbrev.el72
4 files changed, 73 insertions, 71 deletions
diff --git a/doc/lispref/abbrevs.texi b/doc/lispref/abbrevs.texi
index 9ccafe2de24..8415bdca2be 100644
--- a/doc/lispref/abbrevs.texi
+++ b/doc/lispref/abbrevs.texi
@@ -23,13 +23,10 @@ abbrev table. Normally both are used.
each abbreviation. The symbol's name is the abbreviation; its value
is the expansion; its function definition is the hook function to do
the expansion (@pxref{Defining Abbrevs}); its property list cell
-typically contains the use count, the number of times the abbreviation
-has been expanded. Alternatively, the use count is on the
-@code{count} property and the system-abbrev flag is on the
-@code{system-type} property. Abbrevs with a non-@code{nil}
-@code{system-type} property are called ``system'' abbrevs. They are
-usually defined by modes or packages, instead of by the user, and are
-treated specially in certain respects.
+typically contains various additional properties such as the use
+count, the number of times the abbreviation has been expanded, or
+whether the abbrev is a so-called ``system'' abbrev defined by a major
+mode rather than by the user (@pxref{Abbrev Properties}).
Because the symbols used for abbrevs are not interned in the usual
obarray, they will never appear as the result of reading a Lisp
@@ -82,7 +79,8 @@ This is the same as @code{(default-value 'abbrev-mode)}.
@defun make-abbrev-table &rest props
This function creates and returns a new, empty abbrev table---an obarray
containing no symbols. It is a vector filled with zeros. @var{props}
-is a property list that is applied to the new table.
+is a property list that is applied to the new table
+(@pxref{Abbrev Table Properties}).
@end defun
@defun abbrev-table-p table
@@ -145,7 +143,7 @@ to add these to @var{name} separately.)
@code{define-abbrev} is the low-level basic function for defining an
abbrev in a specified abbrev table. When major modes predefine standard
abbrevs, they should call @code{define-abbrev} and specify a @code{t} for
-the @code{system-flag} property.
+the @code{:system} property.
Be aware that any saved non-``system'' abbrevs are
restored at startup, i.e. before some major modes are loaded. Major modes
should therefore not assume that when they are first loaded their abbrev
@@ -155,6 +153,9 @@ tables are empty.
This function defines an abbrev named @var{name}, in @var{table}, to
expand to @var{expansion} and call @var{hook}, with properties
@var{props} (@pxref{Abbrev Properties}). The return value is @var{name}.
+The @code{:system} property in @var{props} is treated specially here:
+if it has the value @code{force}, then it will overwrite an existing
+definition even for a non-``system'' abbrev of the same name.
The argument @var{name} should be a string. The argument
@var{expansion} is normally the desired expansion (a string), or
@@ -413,8 +414,8 @@ This is the local abbrev table used in Lisp mode and Emacs Lisp mode.
@section Abbrev Properties
Abbrevs have properties, some of which influence the way they work.
-They are usually set by providing the relevant arguments to
-@code{define-abbrev} and can be manipulated with the functions:
+You can provide them as arguments to @code{define-abbrev} and you can
+manipulate them with the functions:
@defun abbrev-put abbrev prop val
Set the property @var{prop} of abbrev @var{abbrev} to value @var{val}.
@@ -428,38 +429,34 @@ if the abbrev has no such property.
The following properties have special meaning:
@table @code
-@item count
+@item :count
This property counts the number of times the abbrev has
been expanded. If not explicitly set, it is initialized to 0 by
@code{define-abbrev}.
-@item system-flag
+@item :system
If non-@code{nil}, this property marks the abbrev as a ``system''
abbrev. Such abbrevs will not be saved to @var{abbrev-file-name}.
-Also, unless @code{system-flag} has the value @code{force},
-a ``system'' abbrev will not overwrite an existing definition for
-a non-``system'' abbrev of the same name.
@item :enable-function
-If non-@code{nil}, this property should be set to a function of no
+If non-@code{nil}, this property should be a function of no
arguments which returns @code{nil} if the abbrev should not be used
and @code{t} otherwise.
@item :case-fixed
If non-@code{nil}, this property indicates that the case of the
abbrev's name is significant and should only match a text with the
-same capitalization. It also disables the code that modifies the
-capitalization of the expansion.
-
+same pattern of capitalization. It also disables the code that
+modifies the capitalization of the expansion.
@end table
@node Abbrev Table Properties, , Abbrev Properties, Abbrevs
@section Abbrev Table Properties
Like abbrevs, abble tables have properties, some of which influence
-the way they work. They are usually set by providing the relevant
-arguments to @code{define-abbrev-table} and can be manipulated with
-the functions:
+the way they work. You can provide them as arguments to
+@code{define-abbrev-table} and you can manipulate them with the
+functions:
@defun abbrev-table-put table prop val
Set the property @var{prop} of abbrev table @var{table} to value @var{val}.
@@ -474,26 +471,21 @@ The following properties have special meaning:
@table @code
@item :enable-function
-If non-@code{nil}, this property should be set to a function of no
-arguments which returns @code{nil} if the abbrev table should not be
-used and @code{t} otherwise. This is like the @code{:enable-function}
-abbrev property except that it applies to all abbrevs in the table and
-is used even before trying to find the abbrev before point.
+This is like the @code{:enable-function} abbrev property except that
+it applies to all abbrevs in the table and is used even before trying
+to find the abbrev before point so it can dynamically modify the
+abbrev table.
@item :case-fixed
-If non-@code{nil}, this property indicates that the case of the names
-is significant for all abbrevs in the table and should only match
-a text with the same capitalization. It also disables the code that
-modifies the capitalization of the expansion. This is like the
-@code{:case-fixed} abbrev property except that it applies to all
-abbrevs in the table.
+This is like the @code{:case-fixed} abbrev property except that it
+applies to all abbrevs in the table.
@item :regexp
If non-@code{nil}, this property is a regular expression that
indicates how to extract the name of the abbrev before point before
looking it up in the table. When the regular expression matches
before point, the abbrev name is expected to be in submatch 1.
-If this property is nil, @code{expand-function} defaults to
+If this property is @code{nil}, @code{expand-function} defaults to
@code{"\\<\\(\\w+\\)\\W"}. This property allows the use of abbrevs
whose name contains characters of non-word syntax.
diff --git a/etc/NEWS b/etc/NEWS
index dcc066e9e3b..87773104dbc 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -180,7 +180,7 @@ consult the Remember Manual for usage details.
*** New variable `abbrev-minor-mode-table-alist'.
*** `local-abbrev-table' can hold a list of abbrev-tables.
*** Abbrevs have now the following special properties:
- `count', `system-flag', `:enable-function', `:case-fixed'.
+ `:count', `:system', `:enable-function', `:case-fixed'.
*** Abbrev-tables have now the following special properties:
`:parents', `:case-fixed', `:enable-function', `:regexp',
`abbrev-table-modiff'.
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 07bc2244f7a..d1910299720 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,11 @@
+2007-10-30 Stefan Monnier <monnier@iro.umontreal.ca>
+
+ * abbrev.el: Rename `count' and `system-flag' to :count and :system.
+ Update all users.
+ (abbrev-get, abbrev-put): Simplify.
+ (define-abbrev): Don't store the `force' value in the :system property.
+ (abbrev--before-point): Obey the :enable-function of the abbrev as well.
+
2007-10-30 Michael Olson <mwolson@gnu.org>
* desktop.el (desktop-minor-mode-table): Add line for ERC.
diff --git a/lisp/abbrev.el b/lisp/abbrev.el
index b13f0a60725..04b8a8ce97c 100644
--- a/lisp/abbrev.el
+++ b/lisp/abbrev.el
@@ -388,21 +388,16 @@ A prefix argument means don't query; expand all abbrevs."
(set sym nil) ; Make sure it won't be confused for an abbrev.
(put sym prop val)))
-(defun abbrev-get (sym prop)
- "Get the property PROP of abbrev SYM."
- (let ((plist (symbol-plist sym)))
- (if (listp plist)
- (plist-get plist prop)
- (if (eq 'count prop) plist))))
-
-(defun abbrev-put (sym prop val)
- "Set the property PROP of abbrev SYM to value VAL.
-See `define-abbrev' for the effect of some special properties."
- (let ((plist (symbol-plist sym)))
- (if (consp plist)
- (put sym prop val)
- (setplist sym (if (eq 'count prop) val
- (list 'count plist prop val))))))
+(defalias 'abbrev-get 'get
+ "Get the property PROP of abbrev ABBREV
+
+\(fn ABBREV PROP)")
+
+(defalias 'abbrev-put 'put
+ "Set the property PROP of abbrev ABREV to value VAL.
+See `define-abbrev' for the effect of some special properties.
+
+\(fn ABBREV PROP VAL)")
(defmacro abbrev-with-wrapper-hook (var &rest body)
"Run BODY wrapped with the VAR hook.
@@ -543,11 +538,11 @@ If EXPANSION is not a string, the abbrev is a special one,
which does not expand in the usual way but only runs HOOK.
PROPS is a property list. The following properties are special:
-- `count': the value for the abbrev's usage-count, which is incremented each time
+- `:count': the value for the abbrev's usage-count, which is incremented each time
the abbrev is used (the default is zero).
-- `system-flag': if non-nil, says that this is a \"system\" abbreviation
+- `:system': if non-nil, says that this is a \"system\" abbreviation
which should not be saved in the user's abbreviation file.
- Unless `system-flag' is `force', a system abbreviation will not
+ Unless `:system' is `force', a system abbreviation will not
overwrite a non-system abbreviation of the same name.
- `:case-fixed': non-nil means that abbreviations are looked up without
case-folding, and the expansion is not capitalized/upcased.
@@ -556,20 +551,20 @@ PROPS is a property list. The following properties are special:
An obsolete but still supported calling form is:
-\(define-abbrev TABLE NAME EXPANSION &optional HOOK COUNT SYSTEM-FLAG)."
+\(define-abbrev TABLE NAME EXPANSION &optional HOOK COUNT SYSTEM)."
(when (and (consp props) (or (null (car props)) (numberp (car props))))
;; Old-style calling convention.
- (setq props (list* 'count (car props)
- (if (cadr props) (list 'system-flag (cadr props))))))
- (unless (plist-get props 'count)
- (setq props (plist-put props 'count 0)))
- (let ((system-flag (plist-get props 'system-flag))
+ (setq props (list* :count (car props)
+ (if (cadr props) (list :system (cadr props))))))
+ (unless (plist-get props :count)
+ (setq props (plist-put props :count 0)))
+ (let ((system-flag (plist-get props :system))
(sym (intern name table)))
;; Don't override a prior user-defined abbrev with a system abbrev,
;; unless system-flag is `force'.
(unless (and (not (memq system-flag '(nil force)))
(boundp sym) (symbol-value sym)
- (not (abbrev-get sym 'system-flag)))
+ (not (abbrev-get sym :system)))
(unless (or system-flag
(and (boundp sym) (fboundp sym)
;; load-file-name
@@ -578,7 +573,10 @@ An obsolete but still supported calling form is:
(setq abbrevs-changed t))
(set sym expansion)
(fset sym hook)
- (setplist sym props)
+ (setplist sym
+ ;; Don't store the `force' value of `system-flag' into
+ ;; the :system property.
+ (if (eq 'force system-flag) (plist-put props :system t) props))
(abbrev-table-put table :abbrev-table-modiff
(1+ (abbrev-table-get table :abbrev-table-modiff))))
name))
@@ -710,10 +708,14 @@ then ABBREV is looked up in that table only."
(line-beginning-position))
(setq start (match-beginning 1))
(setq end (match-end 1))
- (setq name (buffer-substring start end))
- ;; This will also look it up in parent tables.
- ;; This is not on purpose, but it seems harmless.
- (list (abbrev-symbol name table) name start end)))
+ (setq name (buffer-substring start end))
+ (let ((abbrev (abbrev-symbol name table)))
+ (when abbrev
+ (setq enable-fun (abbrev-get abbrev :enable-function))
+ (and (or (not enable-fun) (funcall enable-fun))
+ ;; This will also look it up in parent tables.
+ ;; This is not on purpose, but it seems harmless.
+ (list abbrev name start end))))))
;; Restore point.
(goto-char pos)))
res)))
@@ -746,7 +748,7 @@ Returns the abbrev symbol, if expansion took place."
(setq last-abbrev sym)
(setq last-abbrev-location wordstart)
;; Increment use count.
- (abbrev-put sym 'count (1+ (abbrev-get sym 'count)))
+ (abbrev-put sym :count (1+ (abbrev-get sym :count)))
;; If this abbrev has an expansion, delete the abbrev
;; and insert the expansion.
(when (stringp (symbol-value sym))
@@ -815,7 +817,7 @@ is not undone."
"Write the abbrev in a `read'able form.
Only writes the non-system abbrevs.
Presumes that `standard-output' points to `current-buffer'."
- (unless (or (null (symbol-value sym)) (abbrev-get sym 'system-flag))
+ (unless (or (null (symbol-value sym)) (abbrev-get sym :system))
(insert " (")
(prin1 name)
(insert " ")
@@ -823,17 +825,17 @@ Presumes that `standard-output' points to `current-buffer'."
(insert " ")
(prin1 (symbol-function sym))
(insert " ")
- (prin1 (abbrev-get sym 'count))
+ (prin1 (abbrev-get sym :count))
(insert ")\n")))
(defun abbrev--describe (sym)
(when (symbol-value sym)
(prin1 (symbol-name sym))
- (if (null (abbrev-get sym 'system-flag))
+ (if (null (abbrev-get sym :system))
(indent-to 15 1)
(insert " (sys)")
(indent-to 20 1))
- (prin1 (abbrev-get sym 'count))
+ (prin1 (abbrev-get sym :count))
(indent-to 20 1)
(prin1 (symbol-value sym))
(when (symbol-function sym)