From 225979daf9b031d8f2ae82f2bd7a98de234dc0f2 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Mon, 12 Mar 2012 16:07:45 -0400 Subject: [PATCH] * 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 --- lisp/ChangeLog | 7 +++++ lisp/dabbrev.el | 80 ++++++++++++++++++++----------------------------- 2 files changed, 39 insertions(+), 48 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 4f883b1cf94..0032e07074c 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,10 @@ +2012-03-12 Stefan Monnier + + * dabbrev.el: Fix cycle completion order (bug#10963). + (dabbrev--last-obarray, dabbrev--last-completion-buffer): Remove. + (dabbrev-completion): Don't use an obarray; provide + a cycle-sort-function. + 2012-03-12 Leo Liu * simple.el (kill-new): Use equal-including-properties for 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 -- 2.39.5