- (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)))