-;;; 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-2014 Free
+;; Software Foundation, Inc.
;; Author: Don Morrison
;; Lars Lindberg
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)
If this variable is non-nil, dabbrev will only look in these buffers.
It will not even look in the current buffer if it is not a member of
this list."
+ :type '(choice (const nil) (repeat :tag "List of buffers" string))
:group 'dabbrev)
;;----------------------------------------------------------------
;; 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)
;; 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)
;;??? 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.
(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 (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)
(markerp dabbrev--last-abbrev-location)
(marker-position dabbrev--last-abbrev-location)
(or (eq last-command this-command)
- (and (window-minibuffer-p (selected-window))
+ (and (window-minibuffer-p)
(= dabbrev--last-abbrev-location
(point)))))
;; Find a different expansion for the same abbrev as last time.
;;--------------------------------
(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)
(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))))
"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.
"\\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
(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
(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)))
(- (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.
;; In a minibuffer, search the buffer it was activated from,
;; first after the minibuffer itself. Unless we aren't supposed
;; to search the current buffer either.
- (if (and (window-minibuffer-p (selected-window))
+ (if (and (window-minibuffer-p)
(not dabbrev-search-these-buffers-only))
(setq list
(cons (dabbrev--minibuffer-origin)
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.
(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)))
;; 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.
;;--------------------------------
(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