X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/2b0c7330457b8ca42375c92ada7dc7cefb0fa9fb..c175d44072c6a54eb921a3c55fdc2bf2f7816ddd:/lisp/dabbrev.el diff --git a/lisp/dabbrev.el b/lisp/dabbrev.el index 00e9cd60cf..d1bdd3f52b 100644 --- a/lisp/dabbrev.el +++ b/lisp/dabbrev.el @@ -1,7 +1,7 @@ -;;; dabbrev.el --- dynamic abbreviation package +;;; dabbrev.el --- dynamic abbreviation package -*- lexical-binding: t -*- -;; Copyright (C) 1985-1986, 1992, 1994, 1996-1997, 2000-2011 -;; Free Software Foundation, Inc. +;; Copyright (C) 1985-1986, 1992, 1994, 1996-1997, 2000-2013 Free +;; Software Foundation, Inc. ;; Author: Don Morrison ;; Lars Lindberg @@ -206,7 +206,8 @@ starting with or containing `no-'. If you set this variable to expanding `yes-or-no-' signals an error because `-' is not part of a word; but expanding `yes-or-no' looks for a word starting with `no'. -The recommended value is \"\\\\sw\\\\|\\\\s_\"." +The recommended value is nil, which will make dabbrev default to +using \"\\\\sw\\\\|\\\\s_\"." :type '(choice (const nil) regexp) :group 'dabbrev) @@ -290,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) @@ -320,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) @@ -366,6 +361,13 @@ this list." ;;??? Do we want this? ;;;###autoload (define-key esc-map [?\C-/] 'dabbrev-completion) +(defun dabbrev--ignore-case-p (abbrev) + (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))))) + ;;;###autoload (defun dabbrev-completion (&optional arg) "Completion on current word. @@ -386,50 +388,41 @@ then it searches *all* buffers." (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) - init) - (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 (dabbrev--ignore-case-p abbrev)) + (list 'uninitialized) + (table + (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) + (user-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 (defun dabbrev-expand (arg) @@ -521,12 +514,9 @@ See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]." ;;-------------------------------- (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 + (dabbrev--ignore-case-p abbrev))))) (cond ((not expansion) (dabbrev--reset-global-variables) @@ -537,8 +527,8 @@ See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]." (search-backward old) (insert abbrev) (delete-region (point) (+ (point) (length old))))) - (error "No%s dynamic expansion for `%s' found" - (if old " further" "") abbrev)) + (user-error "No%s dynamic expansion for `%s' found" + (if old " further" "") abbrev)) (t (if (not (or (eq dabbrev--last-buffer dabbrev--last-buffer-found) (minibuffer-window-active-p (selected-window)))) @@ -595,7 +585,7 @@ all skip characters." "Extract the symbol at point to serve as abbreviation." ;; Check for error (if (bobp) - (error "No possible abbreviation preceding point")) + (user-error "No possible abbreviation preceding point")) ;; Return abbrev at point (save-excursion ;; Record the end of the abbreviation. @@ -613,7 +603,7 @@ all skip characters." "\\sw\\|\\s_") nil t) (forward-char 1) - (error "No possible abbreviation preceding point")))) + (user-error "No possible abbreviation preceding point")))) ;; Now find the beginning of that one. (dabbrev--goto-start-of-abbrev) (buffer-substring-no-properties @@ -621,8 +611,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 @@ -667,13 +655,13 @@ of the expansion in `dabbrev--last-expansion-location'." (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))) @@ -763,6 +751,7 @@ of the start of the occurrence." (- (length dabbrev--friend-buffer-list))) (setq dabbrev--last-expansion-location (point-min)) (setq expansion (dabbrev--try-find abbrev nil 1 ignore-case))) + (progress-reporter-done dabbrev--progress-reporter) expansion))))) ;; Compute the list of buffers to scan. @@ -828,14 +817,11 @@ EXPANSION is the expansion substring to be used this time. 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 (dabbrev--ignore-case-p 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. @@ -861,12 +847,13 @@ to record whether we upcased the expansion, downcased it, or did neither." (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))) @@ -950,9 +937,9 @@ Leaves point at the location of the start of the expansion." ;; 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. ;;-------------------------------- @@ -987,11 +974,6 @@ Leaves point at the location of the start of the expansion." (cons found-string dabbrev--last-table)) result))))) -(dolist (mess '("^No dynamic expansion for .* found" - "^No further dynamic expansion for .* found$" - "^No possible abbreviation preceding point$")) - (add-to-list 'debug-ignored-errors mess)) - (provide 'dabbrev) ;;; dabbrev.el ends here