aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2012-03-12 09:03:10 -0400
committerStefan Monnier2012-03-12 09:03:10 -0400
commitb19490edc32e6c423f8b18174aba41a513bbe1eb (patch)
treee2d9ea25d29da2a9335e56de04b891f272590d20
parentcd001b8c9b9dc92ef03d86bc40a8d064c7bacad5 (diff)
downloademacs-b19490edc32e6c423f8b18174aba41a513bbe1eb.tar.gz
emacs-b19490edc32e6c423f8b18174aba41a513bbe1eb.zip
* lisp/dabbrev.el: Fix cycle completion.
Use lexical binding and wrap to 80 columns. (dabbrev-completion): Delay computing the list of completions. Fixes: debbugs:10963
-rw-r--r--lisp/ChangeLog6
-rw-r--r--lisp/dabbrev.el156
2 files changed, 88 insertions, 74 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index f9e7eac9123..bb03ba0b436 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,9 @@
12012-03-12 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * dabbrev.el: Fix cycle completion (bug#10963).
4 Use lexical binding and wrap to 80 columns.
5 (dabbrev-completion): Delay computing the list of completions.
6
12012-03-12 Kenichi Handa <handa@m17n.org> 72012-03-12 Kenichi Handa <handa@m17n.org>
2 8
3 * international/quail.el (quail-insert-kbd-layout): Surround each 9 * international/quail.el (quail-insert-kbd-layout): Surround each
diff --git a/lisp/dabbrev.el b/lisp/dabbrev.el
index aad3c83c32b..825402228e1 100644
--- a/lisp/dabbrev.el
+++ b/lisp/dabbrev.el
@@ -1,4 +1,4 @@
1;;; dabbrev.el --- dynamic abbreviation package 1;;; dabbrev.el --- dynamic abbreviation package -*- lexical-binding: t -*-
2 2
3;; Copyright (C) 1985-1986, 1992, 1994, 1996-1997, 2000-2012 3;; Copyright (C) 1985-1986, 1992, 1994, 1996-1997, 2000-2012
4;; Free Software Foundation, Inc. 4;; Free Software Foundation, Inc.
@@ -387,49 +387,54 @@ then it searches *all* buffers."
387 (abbrev (dabbrev--abbrev-at-point)) 387 (abbrev (dabbrev--abbrev-at-point))
388 (beg (progn (search-backward abbrev) (point))) 388 (beg (progn (search-backward abbrev) (point)))
389 (end (progn (search-forward abbrev) (point))) 389 (end (progn (search-forward abbrev) (point)))
390 (ignore-case-p (and (if (eq dabbrev-case-fold-search 'case-fold-search) 390 (ignore-case-p
391 case-fold-search 391 (and (if (eq dabbrev-case-fold-search 'case-fold-search)
392 dabbrev-case-fold-search) 392 case-fold-search
393 (or (not dabbrev-upcase-means-case-search) 393 dabbrev-case-fold-search)
394 (string= abbrev (downcase abbrev))))) 394 (or (not dabbrev-upcase-means-case-search)
395 (my-obarray dabbrev--last-obarray)) 395 (string= abbrev (downcase abbrev)))))
396 (save-excursion 396 (my-obarray dabbrev--last-obarray)
397 ;;-------------------------------- 397 (table
398 ;; New abbreviation to expand. 398 (completion-table-dynamic
399 ;;-------------------------------- 399 (let ((initialized nil))
400 (setq dabbrev--last-abbreviation abbrev) 400 (lambda (abbrev)
401 ;; Find all expansion 401 (unless initialized
402 (let ((completion-list 402 (setq initialized t)
403 (dabbrev--find-all-expansions abbrev ignore-case-p)) 403 (save-excursion
404 (completion-ignore-case ignore-case-p)) 404 ;;--------------------------------
405 ;; Make an obarray with all expansions 405 ;; New abbreviation to expand.
406 (setq my-obarray (make-vector (length completion-list) 0)) 406 ;;--------------------------------
407 (or (> (length my-obarray) 0) 407 (setq dabbrev--last-abbreviation abbrev)
408 (error "No dynamic expansion for \"%s\" found%s" 408 ;; Find all expansion
409 abbrev 409 (let ((completion-list
410 (if dabbrev--check-other-buffers "" " in this-buffer"))) 410 (dabbrev--find-all-expansions abbrev ignore-case-p))
411 (cond 411 (completion-ignore-case ignore-case-p))
412 ((or (not ignore-case-p) 412 ;; Make an obarray with all expansions
413 (not dabbrev-case-replace)) 413 (setq my-obarray (make-vector (length completion-list) 0))
414 (mapc (function (lambda (string) 414 (or (> (length my-obarray) 0)
415 (intern string my-obarray))) 415 (error "No dynamic expansion for \"%s\" found%s"
416 completion-list)) 416 abbrev
417 ((string= abbrev (upcase abbrev)) 417 (if dabbrev--check-other-buffers
418 (mapc (function (lambda (string) 418 "" " in this-buffer")))
419 (intern (upcase string) my-obarray))) 419 (cond
420 completion-list)) 420 ((not (and ignore-case-p
421 ((string= (substring abbrev 0 1) 421 dabbrev-case-replace))
422 (upcase (substring abbrev 0 1))) 422 (dolist (string completion-list)
423 (mapc (function (lambda (string) 423 (intern string my-obarray)))
424 (intern (capitalize string) my-obarray))) 424 ((string= abbrev (upcase abbrev))
425 completion-list)) 425 (dolist (string completion-list)
426 (t 426 (intern (upcase string) my-obarray)))
427 (mapc (function (lambda (string) 427 ((string= (substring abbrev 0 1)
428 (intern (downcase string) my-obarray))) 428 (upcase (substring abbrev 0 1)))
429 completion-list))) 429 (dolist (string completion-list)
430 (setq dabbrev--last-obarray my-obarray) 430 (intern (capitalize string) my-obarray)))
431 (setq dabbrev--last-completion-buffer (current-buffer)))) 431 (t
432 (completion-in-region beg end my-obarray))) 432 (dolist (string completion-list)
433 (intern (downcase string) my-obarray))))
434 (setq dabbrev--last-obarray my-obarray)
435 (setq dabbrev--last-completion-buffer (current-buffer)))))
436 my-obarray)))))
437 (completion-in-region beg end table)))
433 438
434;;;###autoload 439;;;###autoload
435(defun dabbrev-expand (arg) 440(defun dabbrev-expand (arg)
@@ -521,12 +526,13 @@ See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]."
521 ;;-------------------------------- 526 ;;--------------------------------
522 (or expansion 527 (or expansion
523 (setq expansion 528 (setq expansion
524 (dabbrev--find-expansion abbrev direction 529 (dabbrev--find-expansion
525 (and (if (eq dabbrev-case-fold-search 'case-fold-search) 530 abbrev direction
526 case-fold-search 531 (and (if (eq dabbrev-case-fold-search 'case-fold-search)
527 dabbrev-case-fold-search) 532 case-fold-search
528 (or (not dabbrev-upcase-means-case-search) 533 dabbrev-case-fold-search)
529 (string= abbrev (downcase abbrev)))))))) 534 (or (not dabbrev-upcase-means-case-search)
535 (string= abbrev (downcase abbrev))))))))
530 (cond 536 (cond
531 ((not expansion) 537 ((not expansion)
532 (dabbrev--reset-global-variables) 538 (dabbrev--reset-global-variables)
@@ -667,13 +673,13 @@ of the expansion in `dabbrev--last-expansion-location'."
667 (let ((case-fold-search ignore-case) 673 (let ((case-fold-search ignore-case)
668 (count n)) 674 (count n))
669 (while (and (> count 0) 675 (while (and (> count 0)
670 (setq expansion (dabbrev--search abbrev 676 (setq expansion (dabbrev--search
671 reverse 677 abbrev reverse
672 (and ignore-case 678 (and ignore-case
673 (if (eq dabbrev-case-distinction 'case-replace) 679 (if (eq dabbrev-case-distinction
674 case-replace 680 'case-replace)
675 dabbrev-case-distinction)) 681 case-replace
676 ))) 682 dabbrev-case-distinction)))))
677 (setq count (1- count)))) 683 (setq count (1- count))))
678 (and expansion 684 (and expansion
679 (setq dabbrev--last-expansion-location (point))) 685 (setq dabbrev--last-expansion-location (point)))
@@ -829,14 +835,15 @@ EXPANSION is the expansion substring to be used this time.
829RECORD-CASE-PATTERN, if non-nil, means set `dabbrev--last-case-pattern' 835RECORD-CASE-PATTERN, if non-nil, means set `dabbrev--last-case-pattern'
830to record whether we upcased the expansion, downcased it, or did neither." 836to record whether we upcased the expansion, downcased it, or did neither."
831 ;;(undo-boundary) 837 ;;(undo-boundary)
832 (let ((use-case-replace (and (if (eq dabbrev-case-fold-search 'case-fold-search) 838 (let ((use-case-replace
833 case-fold-search 839 (and (if (eq dabbrev-case-fold-search 'case-fold-search)
834 dabbrev-case-fold-search) 840 case-fold-search
835 (or (not dabbrev-upcase-means-case-search) 841 dabbrev-case-fold-search)
836 (string= abbrev (downcase abbrev))) 842 (or (not dabbrev-upcase-means-case-search)
837 (if (eq dabbrev-case-replace 'case-replace) 843 (string= abbrev (downcase abbrev)))
838 case-replace 844 (if (eq dabbrev-case-replace 'case-replace)
839 dabbrev-case-replace)))) 845 case-replace
846 dabbrev-case-replace))))
840 847
841 ;; If we upcased or downcased the original expansion, 848 ;; If we upcased or downcased the original expansion,
842 ;; do likewise for the subsequent words when we copy them. 849 ;; do likewise for the subsequent words when we copy them.
@@ -862,12 +869,13 @@ to record whether we upcased the expansion, downcased it, or did neither."
862 (let ((expansion-rest (substring expansion 1)) 869 (let ((expansion-rest (substring expansion 1))
863 (first-letter-position (string-match "[[:alpha:]]" abbrev))) 870 (first-letter-position (string-match "[[:alpha:]]" abbrev)))
864 (if (or (null first-letter-position) 871 (if (or (null first-letter-position)
865 (and (not (and (or (string= expansion-rest (downcase expansion-rest)) 872 (and (not
866 (string= expansion-rest (upcase expansion-rest))) 873 (and (or (string= expansion-rest (downcase expansion-rest))
867 (or (string= abbrev (downcase abbrev)) 874 (string= expansion-rest (upcase expansion-rest)))
868 (and (string= abbrev (upcase abbrev)) 875 (or (string= abbrev (downcase abbrev))
869 (> (- (length abbrev) first-letter-position) 876 (and (string= abbrev (upcase abbrev))
870 1))))) 877 (> (- (length abbrev) first-letter-position)
878 1)))))
871 (string= abbrev 879 (string= abbrev
872 (substring expansion 0 (length abbrev))))) 880 (substring expansion 0 (length abbrev)))))
873 (setq use-case-replace nil))) 881 (setq use-case-replace nil)))
@@ -951,9 +959,9 @@ Leaves point at the location of the start of the expansion."
951 ;; Limited search. 959 ;; Limited search.
952 (save-restriction 960 (save-restriction
953 (and dabbrev-limit 961 (and dabbrev-limit
954 (narrow-to-region dabbrev--last-expansion-location 962 (narrow-to-region
955 (+ (point) 963 dabbrev--last-expansion-location
956 (if reverse (- dabbrev-limit) dabbrev-limit)))) 964 (+ (point) (if reverse (- dabbrev-limit) dabbrev-limit))))
957 ;;-------------------------------- 965 ;;--------------------------------
958 ;; Look for a distinct expansion, using dabbrev--last-table. 966 ;; Look for a distinct expansion, using dabbrev--last-table.
959 ;;-------------------------------- 967 ;;--------------------------------