summaryrefslogtreecommitdiff
path: root/lisp/dabbrev.el
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2012-03-12 16:07:45 -0400
committerStefan Monnier <monnier@iro.umontreal.ca>2012-03-12 16:07:45 -0400
commit225979daf9b031d8f2ae82f2bd7a98de234dc0f2 (patch)
treeff7ce3a5bc0cf8ac74e08af78e113b98439bdd72 /lisp/dabbrev.el
parente2f1fdab9105065bda0212bf1558eca186c2f3cb (diff)
downloademacs-225979daf9b031d8f2ae82f2bd7a98de234dc0f2.tar.gz
* lisp/dabbrev.el: Fix cycle completion order.
(dabbrev--last-obarray, dabbrev--last-completion-buffer): Remove. (dabbrev-completion): Don't use an obarray; provide a cycle-sort-function. Fixes: debbugs:10963
Diffstat (limited to 'lisp/dabbrev.el')
-rw-r--r--lisp/dabbrev.el80
1 files changed, 32 insertions, 48 deletions
diff --git a/lisp/dabbrev.el b/lisp/dabbrev.el
index 825402228e1..c5b370bfa61 100644
--- a/lisp/dabbrev.el
+++ b/lisp/dabbrev.el
@@ -291,9 +291,6 @@ this list."
;; Internal variables
;;----------------------------------------------------------------
-;; Last obarray of completions in `dabbrev-completion'
-(defvar dabbrev--last-obarray nil)
-
;; Table of expansions seen so far
(defvar dabbrev--last-table nil)
@@ -321,9 +318,6 @@ this list."
;; The buffer we found the expansion last time.
(defvar dabbrev--last-buffer-found nil)
-;; The buffer we last did a completion in.
-(defvar dabbrev--last-completion-buffer nil)
-
;; If non-nil, a function to use when copying successive words.
;; It should be `upcase' or `downcase'.
(defvar dabbrev--last-case-pattern nil)
@@ -393,47 +387,39 @@ then it searches *all* buffers."
dabbrev-case-fold-search)
(or (not dabbrev-upcase-means-case-search)
(string= abbrev (downcase abbrev)))))
- (my-obarray dabbrev--last-obarray)
+ (list 'uninitialized)
(table
- (completion-table-dynamic
- (let ((initialized nil))
- (lambda (abbrev)
- (unless initialized
- (setq initialized t)
- (save-excursion
- ;;--------------------------------
- ;; New abbreviation to expand.
- ;;--------------------------------
- (setq dabbrev--last-abbreviation abbrev)
- ;; Find all expansion
- (let ((completion-list
- (dabbrev--find-all-expansions abbrev ignore-case-p))
- (completion-ignore-case ignore-case-p))
- ;; Make an obarray with all expansions
- (setq my-obarray (make-vector (length completion-list) 0))
- (or (> (length my-obarray) 0)
- (error "No dynamic expansion for \"%s\" found%s"
- abbrev
- (if dabbrev--check-other-buffers
- "" " in this-buffer")))
- (cond
- ((not (and ignore-case-p
- dabbrev-case-replace))
- (dolist (string completion-list)
- (intern string my-obarray)))
- ((string= abbrev (upcase abbrev))
- (dolist (string completion-list)
- (intern (upcase string) my-obarray)))
- ((string= (substring abbrev 0 1)
- (upcase (substring abbrev 0 1)))
- (dolist (string completion-list)
- (intern (capitalize string) my-obarray)))
- (t
- (dolist (string completion-list)
- (intern (downcase string) my-obarray))))
- (setq dabbrev--last-obarray my-obarray)
- (setq dabbrev--last-completion-buffer (current-buffer)))))
- my-obarray)))))
+ (lambda (s p a)
+ (if (eq a 'metadata)
+ `(metadata (cycle-sort-function . ,#'identity)
+ (category . dabbrev))
+ (when (eq list 'uninitialized)
+ (save-excursion
+ ;;--------------------------------
+ ;; New abbreviation to expand.
+ ;;--------------------------------
+ (setq dabbrev--last-abbreviation abbrev)
+ ;; Find all expansion
+ (let ((completion-list
+ (dabbrev--find-all-expansions abbrev ignore-case-p))
+ (completion-ignore-case ignore-case-p))
+ (or (consp completion-list)
+ (error "No dynamic expansion for \"%s\" found%s"
+ abbrev
+ (if dabbrev--check-other-buffers
+ "" " in this-buffer")))
+ (setq list
+ (cond
+ ((not (and ignore-case-p dabbrev-case-replace))
+ completion-list)
+ ((string= abbrev (upcase abbrev))
+ (mapcar #'upcase completion-list))
+ ((string= (substring abbrev 0 1)
+ (upcase (substring abbrev 0 1)))
+ (mapcar #'capitalize completion-list))
+ (t
+ (mapcar #'downcase completion-list)))))))
+ (complete-with-action a list s p)))))
(completion-in-region beg end table)))
;;;###autoload
@@ -627,8 +613,6 @@ all skip characters."
(defun dabbrev--reset-global-variables ()
"Initialize all global variables."
- ;; dabbrev--last-obarray and dabbrev--last-completion-buffer
- ;; must not be reset here.
(setq dabbrev--last-table nil
dabbrev--last-abbreviation nil
dabbrev--last-abbrev-location nil