]> code.delx.au - gnu-emacs/commitdiff
* lisp/dabbrev.el: Fix cycle completion order.
authorStefan Monnier <monnier@iro.umontreal.ca>
Mon, 12 Mar 2012 20:07:45 +0000 (16:07 -0400)
committerStefan Monnier <monnier@iro.umontreal.ca>
Mon, 12 Mar 2012 20:07:45 +0000 (16:07 -0400)
(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
lisp/dabbrev.el

index 4f883b1cf942f59155749408f838eacba74b4c53..0032e07074ceecd60901b3f3ccd10219954d6d0c 100644 (file)
@@ -1,3 +1,10 @@
+2012-03-12  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+       * 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  <sdl.web@gmail.com>
 
        * simple.el (kill-new): Use equal-including-properties for
index 825402228e1ba2d73d07d72ba599d89481ef9461..c5b370bfa61d8b33633df5f03fddcfbbb36fec4d 100644 (file)
@@ -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