diff options
| author | Przemysław Wojnowski | 2015-11-08 19:19:15 +0100 |
|---|---|---|
| committer | Nicolas Petton | 2015-11-20 00:19:56 +0100 |
| commit | 5c81fd58e32d965c2551663622e084f2800e1e90 (patch) | |
| tree | 2dfaabcf1cddc4b4c370ef61f7c8b5e4d48bddae /lisp | |
| parent | ebad964b3afbe5ef77085be94cf566836450c74c (diff) | |
| download | emacs-5c81fd58e32d965c2551663622e084f2800e1e90.tar.gz emacs-5c81fd58e32d965c2551663622e084f2800e1e90.zip | |
Use obarray functions from obarray.
* lisp/abbrev.el (copy-abbrev-table, abbrev-table-p, make-abbrev-table,
abbrev-table-get, abbrev-table-put, abbrev-table-empty-p,
clear-abbrev-table, define-abbrev, abbrev--symbol, abbrev-table-menu):
delegate to obarray.el functions.
* lisp/loadup.el: load obarray before abbrev
* test/automated/abbrev-tests.el: new tests
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/abbrev.el | 52 | ||||
| -rw-r--r-- | lisp/loadup.el | 1 |
2 files changed, 27 insertions, 26 deletions
diff --git a/lisp/abbrev.el b/lisp/abbrev.el index 43a905b906e..c95e1ea9dfd 100644 --- a/lisp/abbrev.el +++ b/lisp/abbrev.el | |||
| @@ -33,6 +33,7 @@ | |||
| 33 | ;;; Code: | 33 | ;;; Code: |
| 34 | 34 | ||
| 35 | (eval-when-compile (require 'cl-lib)) | 35 | (eval-when-compile (require 'cl-lib)) |
| 36 | (require 'obarray) | ||
| 36 | 37 | ||
| 37 | (defgroup abbrev-mode nil | 38 | (defgroup abbrev-mode nil |
| 38 | "Word abbreviations mode." | 39 | "Word abbreviations mode." |
| @@ -87,7 +88,7 @@ be replaced by its expansion." | |||
| 87 | "Make a new abbrev-table with the same abbrevs as TABLE. | 88 | "Make a new abbrev-table with the same abbrevs as TABLE. |
| 88 | Does not copy property lists." | 89 | Does not copy property lists." |
| 89 | (let ((new-table (make-abbrev-table))) | 90 | (let ((new-table (make-abbrev-table))) |
| 90 | (mapatoms | 91 | (obarray-map |
| 91 | (lambda (symbol) | 92 | (lambda (symbol) |
| 92 | (define-abbrev new-table | 93 | (define-abbrev new-table |
| 93 | (symbol-name symbol) | 94 | (symbol-name symbol) |
| @@ -406,12 +407,12 @@ A prefix argument means don't query; expand all abbrevs." | |||
| 406 | 407 | ||
| 407 | (defun abbrev-table-get (table prop) | 408 | (defun abbrev-table-get (table prop) |
| 408 | "Get the PROP property of abbrev table TABLE." | 409 | "Get the PROP property of abbrev table TABLE." |
| 409 | (let ((sym (intern-soft "" table))) | 410 | (let ((sym (obarray-get table ""))) |
| 410 | (if sym (get sym prop)))) | 411 | (if sym (get sym prop)))) |
| 411 | 412 | ||
| 412 | (defun abbrev-table-put (table prop val) | 413 | (defun abbrev-table-put (table prop val) |
| 413 | "Set the PROP property of abbrev table TABLE to VAL." | 414 | "Set the PROP property of abbrev table TABLE to VAL." |
| 414 | (let ((sym (intern "" table))) | 415 | (let ((sym (obarray-put table ""))) |
| 415 | (set sym nil) ; Make sure it won't be confused for an abbrev. | 416 | (set sym nil) ; Make sure it won't be confused for an abbrev. |
| 416 | (put sym prop val))) | 417 | (put sym prop val))) |
| 417 | 418 | ||
| @@ -435,8 +436,7 @@ See `define-abbrev' for the effect of some special properties. | |||
| 435 | (defun make-abbrev-table (&optional props) | 436 | (defun make-abbrev-table (&optional props) |
| 436 | "Create a new, empty abbrev table object. | 437 | "Create a new, empty abbrev table object. |
| 437 | PROPS is a list of properties." | 438 | PROPS is a list of properties." |
| 438 | ;; The value 59 is an arbitrary prime number. | 439 | (let ((table (obarray-make))) |
| 439 | (let ((table (make-vector 59 0))) | ||
| 440 | ;; Each abbrev-table has a `modiff' counter which can be used to detect | 440 | ;; Each abbrev-table has a `modiff' counter which can be used to detect |
| 441 | ;; when an abbreviation was added. An example of use would be to | 441 | ;; when an abbreviation was added. An example of use would be to |
| 442 | ;; construct :regexp dynamically as the union of all abbrev names, so | 442 | ;; construct :regexp dynamically as the union of all abbrev names, so |
| @@ -451,7 +451,7 @@ PROPS is a list of properties." | |||
| 451 | 451 | ||
| 452 | (defun abbrev-table-p (object) | 452 | (defun abbrev-table-p (object) |
| 453 | "Return non-nil if OBJECT is an abbrev table." | 453 | "Return non-nil if OBJECT is an abbrev table." |
| 454 | (and (vectorp object) | 454 | (and (obarrayp object) |
| 455 | (numberp (abbrev-table-get object :abbrev-table-modiff)))) | 455 | (numberp (abbrev-table-get object :abbrev-table-modiff)))) |
| 456 | 456 | ||
| 457 | (defun abbrev-table-empty-p (object &optional ignore-system) | 457 | (defun abbrev-table-empty-p (object &optional ignore-system) |
| @@ -460,12 +460,12 @@ If IGNORE-SYSTEM is non-nil, system definitions are ignored." | |||
| 460 | (unless (abbrev-table-p object) | 460 | (unless (abbrev-table-p object) |
| 461 | (error "Non abbrev table object")) | 461 | (error "Non abbrev table object")) |
| 462 | (not (catch 'some | 462 | (not (catch 'some |
| 463 | (mapatoms (lambda (abbrev) | 463 | (obarray-map (lambda (abbrev) |
| 464 | (unless (or (zerop (length (symbol-name abbrev))) | 464 | (unless (or (zerop (length (symbol-name abbrev))) |
| 465 | (and ignore-system | 465 | (and ignore-system |
| 466 | (abbrev-get abbrev :system))) | 466 | (abbrev-get abbrev :system))) |
| 467 | (throw 'some t))) | 467 | (throw 'some t))) |
| 468 | object)))) | 468 | object)))) |
| 469 | 469 | ||
| 470 | (defvar global-abbrev-table (make-abbrev-table) | 470 | (defvar global-abbrev-table (make-abbrev-table) |
| 471 | "The abbrev table whose abbrevs affect all buffers. | 471 | "The abbrev table whose abbrevs affect all buffers. |
| @@ -529,12 +529,12 @@ the current abbrev table before abbrev lookup happens." | |||
| 529 | (defun clear-abbrev-table (table) | 529 | (defun clear-abbrev-table (table) |
| 530 | "Undefine all abbrevs in abbrev table TABLE, leaving it empty." | 530 | "Undefine all abbrevs in abbrev table TABLE, leaving it empty." |
| 531 | (setq abbrevs-changed t) | 531 | (setq abbrevs-changed t) |
| 532 | (let* ((sym (intern-soft "" table))) | 532 | (let* ((sym (obarray-get table ""))) |
| 533 | (dotimes (i (length table)) | 533 | (dotimes (i (length table)) |
| 534 | (aset table i 0)) | 534 | (aset table i 0)) |
| 535 | ;; Preserve the table's properties. | 535 | ;; Preserve the table's properties. |
| 536 | (cl-assert sym) | 536 | (cl-assert sym) |
| 537 | (let ((newsym (intern "" table))) | 537 | (let ((newsym (obarray-put table ""))) |
| 538 | (set newsym nil) ; Make sure it won't be confused for an abbrev. | 538 | (set newsym nil) ; Make sure it won't be confused for an abbrev. |
| 539 | (setplist newsym (symbol-plist sym))) | 539 | (setplist newsym (symbol-plist sym))) |
| 540 | (abbrev-table-put table :abbrev-table-modiff | 540 | (abbrev-table-put table :abbrev-table-modiff |
| @@ -583,7 +583,7 @@ An obsolete but still supported calling form is: | |||
| 583 | (setq props (plist-put props :abbrev-table-modiff | 583 | (setq props (plist-put props :abbrev-table-modiff |
| 584 | (abbrev-table-get table :abbrev-table-modiff))) | 584 | (abbrev-table-get table :abbrev-table-modiff))) |
| 585 | (let ((system-flag (plist-get props :system)) | 585 | (let ((system-flag (plist-get props :system)) |
| 586 | (sym (intern name table))) | 586 | (sym (obarray-put table name))) |
| 587 | ;; Don't override a prior user-defined abbrev with a system abbrev, | 587 | ;; Don't override a prior user-defined abbrev with a system abbrev, |
| 588 | ;; unless system-flag is `force'. | 588 | ;; unless system-flag is `force'. |
| 589 | (unless (and (not (memq system-flag '(nil force))) | 589 | (unless (and (not (memq system-flag '(nil force))) |
| @@ -673,10 +673,10 @@ The value is nil if that abbrev is not defined." | |||
| 673 | ;; abbrevs do, we have to be careful. | 673 | ;; abbrevs do, we have to be careful. |
| 674 | (sym | 674 | (sym |
| 675 | ;; First try without case-folding. | 675 | ;; First try without case-folding. |
| 676 | (or (intern-soft abbrev table) | 676 | (or (obarray-get table abbrev) |
| 677 | (when case-fold | 677 | (when case-fold |
| 678 | ;; We didn't find any abbrev, try case-folding. | 678 | ;; We didn't find any abbrev, try case-folding. |
| 679 | (let ((sym (intern-soft (downcase abbrev) table))) | 679 | (let ((sym (obarray-get table (downcase abbrev)))) |
| 680 | ;; Only use it if it doesn't require :case-fixed. | 680 | ;; Only use it if it doesn't require :case-fixed. |
| 681 | (and sym (not (abbrev-get sym :case-fixed)) | 681 | (and sym (not (abbrev-get sym :case-fixed)) |
| 682 | sym)))))) | 682 | sym)))))) |
| @@ -1005,17 +1005,17 @@ PROMPT is the prompt to use for the keymap. | |||
| 1005 | SORTFUN is passed to `sort' to change the default ordering." | 1005 | SORTFUN is passed to `sort' to change the default ordering." |
| 1006 | (unless sortfun (setq sortfun 'string-lessp)) | 1006 | (unless sortfun (setq sortfun 'string-lessp)) |
| 1007 | (let ((entries ())) | 1007 | (let ((entries ())) |
| 1008 | (mapatoms (lambda (abbrev) | 1008 | (obarray-map (lambda (abbrev) |
| 1009 | (when (symbol-value abbrev) | 1009 | (when (symbol-value abbrev) |
| 1010 | (let ((name (symbol-name abbrev))) | 1010 | (let ((name (symbol-name abbrev))) |
| 1011 | (push `(,(intern name) menu-item ,name | 1011 | (push `(,(intern name) menu-item ,name |
| 1012 | (lambda () (interactive) | 1012 | (lambda () (interactive) |
| 1013 | (abbrev-insert ',abbrev))) | 1013 | (abbrev-insert ',abbrev))) |
| 1014 | entries)))) | 1014 | entries)))) |
| 1015 | table) | 1015 | table) |
| 1016 | (nconc (make-sparse-keymap prompt) | 1016 | (nconc (make-sparse-keymap prompt) |
| 1017 | (sort entries (lambda (x y) | 1017 | (sort entries (lambda (x y) |
| 1018 | (funcall sortfun (nth 2 x) (nth 2 y))))))) | 1018 | (funcall sortfun (nth 2 x) (nth 2 y))))))) |
| 1019 | 1019 | ||
| 1020 | ;; Keep it after define-abbrev-table, since define-derived-mode uses | 1020 | ;; Keep it after define-abbrev-table, since define-derived-mode uses |
| 1021 | ;; define-abbrev-table. | 1021 | ;; define-abbrev-table. |
diff --git a/lisp/loadup.el b/lisp/loadup.el index ef7f19fbddb..782622cd0d7 100644 --- a/lisp/loadup.el +++ b/lisp/loadup.el | |||
| @@ -153,6 +153,7 @@ | |||
| 153 | (load "emacs-lisp/nadvice") | 153 | (load "emacs-lisp/nadvice") |
| 154 | (load "emacs-lisp/cl-preloaded") | 154 | (load "emacs-lisp/cl-preloaded") |
| 155 | (load "minibuffer") ;After loaddefs, for define-minor-mode. | 155 | (load "minibuffer") ;After loaddefs, for define-minor-mode. |
| 156 | (load "obarray") ;abbrev.el is implemented in terms of obarrays. | ||
| 156 | (load "abbrev") ;lisp-mode.el and simple.el use define-abbrev-table. | 157 | (load "abbrev") ;lisp-mode.el and simple.el use define-abbrev-table. |
| 157 | (load "simple") | 158 | (load "simple") |
| 158 | 159 | ||