emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r107589: * lisp/dabbrev.el: Fix cycle


From: Stefan Monnier
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r107589: * lisp/dabbrev.el: Fix cycle completion.
Date: Mon, 12 Mar 2012 09:03:10 -0400
User-agent: Bazaar (2.3.1)

------------------------------------------------------------
revno: 107589
fixes bug(s): http://debbugs.gnu.org/cgi/bugreport.cgi?bug=10963
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Mon 2012-03-12 09:03:10 -0400
message:
  * lisp/dabbrev.el: Fix cycle completion.
  Use lexical binding and wrap to 80 columns.
  (dabbrev-completion): Delay computing the list of completions.
modified:
  lisp/ChangeLog
  lisp/dabbrev.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2012-03-12 07:42:02 +0000
+++ b/lisp/ChangeLog    2012-03-12 13:03:10 +0000
@@ -1,3 +1,9 @@
+2012-03-12  Stefan Monnier  <address@hidden>
+
+       * dabbrev.el: Fix cycle completion (bug#10963).
+       Use lexical binding and wrap to 80 columns.
+       (dabbrev-completion): Delay computing the list of completions.
+
 2012-03-12  Kenichi Handa  <address@hidden>
 
        * international/quail.el (quail-insert-kbd-layout): Surround each

=== modified file 'lisp/dabbrev.el'
--- a/lisp/dabbrev.el   2012-03-11 15:45:44 +0000
+++ b/lisp/dabbrev.el   2012-03-12 13:03:10 +0000
@@ -1,4 +1,4 @@
-;;; dabbrev.el --- dynamic abbreviation package
+;;; dabbrev.el --- dynamic abbreviation package  -*- lexical-binding: t -*-
 
 ;; Copyright (C) 1985-1986, 1992, 1994, 1996-1997, 2000-2012
 ;;   Free Software Foundation, Inc.
@@ -387,49 +387,54 @@
         (abbrev (dabbrev--abbrev-at-point))
          (beg (progn (search-backward abbrev) (point)))
          (end (progn (search-forward abbrev) (point)))
-        (ignore-case-p (and (if (eq dabbrev-case-fold-search 'case-fold-search)
-                                case-fold-search
-                              dabbrev-case-fold-search)
-                            (or (not dabbrev-upcase-means-case-search)
-                                (string= abbrev (downcase abbrev)))))
-        (my-obarray dabbrev--last-obarray))
-    (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
-        ((or (not ignore-case-p)
-             (not dabbrev-case-replace))
-         (mapc (function (lambda (string)
-                           (intern string my-obarray)))
-               completion-list))
-        ((string= abbrev (upcase abbrev))
-         (mapc (function (lambda (string)
-                           (intern (upcase string) my-obarray)))
-               completion-list))
-        ((string= (substring abbrev 0 1)
-                  (upcase (substring abbrev 0 1)))
-         (mapc (function (lambda (string)
-                           (intern (capitalize string) my-obarray)))
-               completion-list))
-        (t
-         (mapc (function (lambda (string)
-                           (intern (downcase string) my-obarray)))
-               completion-list)))
-       (setq dabbrev--last-obarray my-obarray)
-       (setq dabbrev--last-completion-buffer (current-buffer))))
-    (completion-in-region beg end my-obarray)))
+        (ignore-case-p
+          (and (if (eq dabbrev-case-fold-search 'case-fold-search)
+                   case-fold-search
+                 dabbrev-case-fold-search)
+               (or (not dabbrev-upcase-means-case-search)
+                   (string= abbrev (downcase abbrev)))))
+        (my-obarray dabbrev--last-obarray)
+         (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)))))
+    (completion-in-region beg end table)))
 
 ;;;###autoload
 (defun dabbrev-expand (arg)
@@ -521,12 +526,13 @@
       ;;--------------------------------
       (or expansion
          (setq expansion
-               (dabbrev--find-expansion abbrev direction
-                                        (and (if (eq dabbrev-case-fold-search 
'case-fold-search)
-                                                 case-fold-search
-                                               dabbrev-case-fold-search)
-                                             (or (not 
dabbrev-upcase-means-case-search)
-                                                 (string= abbrev (downcase 
abbrev))))))))
+               (dabbrev--find-expansion
+                 abbrev direction
+                 (and (if (eq dabbrev-case-fold-search 'case-fold-search)
+                          case-fold-search
+                        dabbrev-case-fold-search)
+                      (or (not dabbrev-upcase-means-case-search)
+                          (string= abbrev (downcase abbrev))))))))
     (cond
      ((not expansion)
       (dabbrev--reset-global-variables)
@@ -667,13 +673,13 @@
        (let ((case-fold-search ignore-case)
              (count n))
          (while (and (> count 0)
-                     (setq expansion (dabbrev--search abbrev
-                                                      reverse
-                                                      (and ignore-case
-                                                           (if (eq 
dabbrev-case-distinction 'case-replace)
-                                                               case-replace
-                                                             
dabbrev-case-distinction))
-                                                      )))
+                     (setq expansion (dabbrev--search
+                                       abbrev reverse
+                                       (and ignore-case
+                                            (if (eq dabbrev-case-distinction
+                                                    'case-replace)
+                                                case-replace
+                                              dabbrev-case-distinction)))))
            (setq count (1- count))))
        (and expansion
             (setq dabbrev--last-expansion-location (point)))
@@ -829,14 +835,15 @@
 RECORD-CASE-PATTERN, if non-nil, means set `dabbrev--last-case-pattern'
 to record whether we upcased the expansion, downcased it, or did neither."
   ;;(undo-boundary)
-  (let ((use-case-replace (and (if (eq dabbrev-case-fold-search 
'case-fold-search)
-                                  case-fold-search
-                                dabbrev-case-fold-search)
-                              (or (not dabbrev-upcase-means-case-search)
-                                  (string= abbrev (downcase abbrev)))
-                              (if (eq dabbrev-case-replace 'case-replace)
-                                  case-replace
-                                dabbrev-case-replace))))
+  (let ((use-case-replace
+         (and (if (eq dabbrev-case-fold-search 'case-fold-search)
+                  case-fold-search
+                dabbrev-case-fold-search)
+              (or (not dabbrev-upcase-means-case-search)
+                  (string= abbrev (downcase abbrev)))
+              (if (eq dabbrev-case-replace 'case-replace)
+                  case-replace
+                dabbrev-case-replace))))
 
     ;; If we upcased or downcased the original expansion,
     ;; do likewise for the subsequent words when we copy them.
@@ -862,12 +869,13 @@
     (let ((expansion-rest (substring expansion 1))
          (first-letter-position (string-match "[[:alpha:]]" abbrev)))
       (if (or (null first-letter-position)
-             (and (not (and (or (string= expansion-rest (downcase 
expansion-rest))
-                                (string= expansion-rest (upcase 
expansion-rest)))
-                            (or (string= abbrev (downcase abbrev))
-                                (and (string= abbrev (upcase abbrev))
-                                     (> (- (length abbrev) 
first-letter-position)
-                                        1)))))
+             (and (not
+                    (and (or (string= expansion-rest (downcase expansion-rest))
+                             (string= expansion-rest (upcase expansion-rest)))
+                         (or (string= abbrev (downcase abbrev))
+                             (and (string= abbrev (upcase abbrev))
+                                  (> (- (length abbrev) first-letter-position)
+                                     1)))))
                   (string= abbrev
                            (substring expansion 0 (length abbrev)))))
          (setq use-case-replace nil)))
@@ -951,9 +959,9 @@
       ;; Limited search.
       (save-restriction
        (and dabbrev-limit
-            (narrow-to-region dabbrev--last-expansion-location
-                              (+ (point)
-                                 (if reverse (- dabbrev-limit) 
dabbrev-limit))))
+            (narrow-to-region
+              dabbrev--last-expansion-location
+              (+ (point) (if reverse (- dabbrev-limit) dabbrev-limit))))
        ;;--------------------------------
        ;; Look for a distinct expansion, using dabbrev--last-table.
        ;;--------------------------------


reply via email to

[Prev in Thread] Current Thread [Next in Thread]