]> code.delx.au - gnu-emacs/blobdiff - lisp/dabbrev.el
; * etc/NEWS: Typo fix.
[gnu-emacs] / lisp / dabbrev.el
index c51f1322a0a9886e9cc3b3bac9be95b0bcefe936..3557041f51c76ad2bc9994ab6a8cd8c889c49e8b 100644 (file)
@@ -1,9 +1,11 @@
-;;; dabbrev.el --- dynamic abbreviation package
+;;; dabbrev.el --- dynamic abbreviation package  -*- lexical-binding: t -*-
 
 
-;; Copyright (C) 1985, 1986, 1992, 1994, 1996, 1997, 2000, 2001, 2002,
-;;   2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;; Copyright (C) 1985-1986, 1992, 1994, 1996-1997, 2000-2016 Free
+;; Software Foundation, Inc.
 
 ;; Author: Don Morrison
 
 ;; Author: Don Morrison
+;;     Lars Lindberg
+;; (according to ack.texi)
 ;; Maintainer: Lars Lindberg <Lars.Lindberg@sypro.cap.se>
 ;; Created: 16 Mars 1992
 ;; Lindberg's last update version: 5.7
 ;; Maintainer: Lars Lindberg <Lars.Lindberg@sypro.cap.se>
 ;; Created: 16 Mars 1992
 ;; Lindberg's last update version: 5.7
 
 ;; This file is part of GNU Emacs.
 
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 3, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -22,9 +24,7 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
 
 ;;; Commentary:
 
@@ -61,8 +61,7 @@
 ;; the article for expansion):
 ;; (set (make-local-variable 'dabbrev-friend-buffer-function)
 ;;      (lambda (buffer)
 ;; the article for expansion):
 ;; (set (make-local-variable 'dabbrev-friend-buffer-function)
 ;;      (lambda (buffer)
-;;         (save-excursion
-;;           (set-buffer buffer)
+;;         (with-current-buffer buffer
 ;;           (memq major-mode '(news-reply-mode gnus-article-mode)))))
 
 
 ;;           (memq major-mode '(news-reply-mode gnus-article-mode)))))
 
 
   :group 'convenience)
 
 (defcustom dabbrev-backward-only nil
   :group 'convenience)
 
 (defcustom dabbrev-backward-only nil
-  "*If non-nil, `dabbrev-expand' only looks backwards."
+  "If non-nil, `dabbrev-expand' only looks backwards."
   :type 'boolean
   :group 'dabbrev)
 
 (defcustom dabbrev-limit nil
   :type 'boolean
   :group 'dabbrev)
 
 (defcustom dabbrev-limit nil
-  "*Limits region searched by `dabbrev-expand' to this many chars away."
+  "Limits region searched by `dabbrev-expand' to this many chars away."
   :type '(choice (const :tag "off" nil)
                 integer)
   :group 'dabbrev)
 
 (defcustom dabbrev-abbrev-skip-leading-regexp nil
   :type '(choice (const :tag "off" nil)
                 integer)
   :group 'dabbrev)
 
 (defcustom dabbrev-abbrev-skip-leading-regexp nil
-  "*Regexp for skipping leading characters of an abbreviation.
+  "Regexp for skipping leading characters of an abbreviation.
 
 Example: Set this to \"\\\\$\" for programming languages
 in which variable names may appear with or without a leading `$'.
 
 Example: Set this to \"\\\\$\" for programming languages
 in which variable names may appear with or without a leading `$'.
-\(For example, in Makefiles.\)
+\(For example, in Makefiles.)
 
 Set this to nil if no characters should be skipped."
   :type '(choice regexp
 
 Set this to nil if no characters should be skipped."
   :type '(choice regexp
@@ -129,13 +128,13 @@ Set this to nil if no characters should be skipped."
   :group 'dabbrev)
 
 (defcustom dabbrev-eliminate-newlines t
   :group 'dabbrev)
 
 (defcustom dabbrev-eliminate-newlines t
-  "*Non-nil means dabbrev should not insert newlines.
+  "Non-nil means dabbrev should not insert newlines.
 Instead it converts them to spaces."
   :type 'boolean
   :group 'dabbrev)
 
 (defcustom dabbrev-case-fold-search 'case-fold-search
 Instead it converts them to spaces."
   :type 'boolean
   :group 'dabbrev)
 
 (defcustom dabbrev-case-fold-search 'case-fold-search
-  "*Control whether dabbrev searches should ignore case.
+  "Control whether dabbrev searches should ignore case.
 A value of nil means case is significant.
 A value of `case-fold-search' means case is significant
  if `case-fold-search' is nil.
 A value of nil means case is significant.
 A value of `case-fold-search' means case is significant
  if `case-fold-search' is nil.
@@ -144,9 +143,10 @@ Any other non-nil version means case is not significant."
                 (const :tag "like search" case-fold-search)
                 (other :tag "on" t))
   :group 'dabbrev)
                 (const :tag "like search" case-fold-search)
                 (other :tag "on" t))
   :group 'dabbrev)
+;;;###autoload(put 'dabbrev-case-fold-search 'risky-local-variable t)
 
 (defcustom dabbrev-upcase-means-case-search nil
 
 (defcustom dabbrev-upcase-means-case-search nil
-  "*The significance of an uppercase character in an abbreviation.
+  "The significance of an uppercase character in an abbreviation.
 A nil value means case fold search when searching for possible expansions;
 non-nil means case sensitive search.
 
 A nil value means case fold search when searching for possible expansions;
 non-nil means case sensitive search.
 
@@ -156,7 +156,7 @@ This variable has an effect only when the value of
   :group 'dabbrev)
 
 (defcustom dabbrev-case-distinction 'case-replace
   :group 'dabbrev)
 
 (defcustom dabbrev-case-distinction 'case-replace
-  "*Whether dabbrev treats expansions as the same if they differ in case.
+  "Whether dabbrev treats expansions as the same if they differ in case.
 
 A value of nil means treat them as different.
 A value of `case-replace' means distinguish them if `case-replace' is nil.
 
 A value of nil means treat them as different.
 A value of `case-replace' means distinguish them if `case-replace' is nil.
@@ -171,7 +171,7 @@ This variable has an effect only when the value of
   :version "22.1")
 
 (defcustom dabbrev-case-replace 'case-replace
   :version "22.1")
 
 (defcustom dabbrev-case-replace 'case-replace
-  "*Whether dabbrev applies the abbreviations's case pattern to the expansion.
+  "Whether dabbrev applies the abbreviations's case pattern to the expansion.
 
 A value of nil means preserve the expansion's case pattern.
 A value of `case-replace' means preserve it if `case-replace' is nil.
 
 A value of nil means preserve the expansion's case pattern.
 A value of `case-replace' means preserve it if `case-replace' is nil.
@@ -184,9 +184,10 @@ This variable has an effect only when the value of
                 (const :tag "based on `case-replace'" case-replace)
                 (other :tag "on" t))
   :group 'dabbrev)
                 (const :tag "based on `case-replace'" case-replace)
                 (other :tag "on" t))
   :group 'dabbrev)
+;;;###autoload(put 'dabbrev-case-replace 'risky-local-variable t)
 
 (defcustom dabbrev-abbrev-char-regexp nil
 
 (defcustom dabbrev-abbrev-char-regexp nil
-  "*Regexp to recognize a character in an abbreviation or expansion.
+  "Regexp to recognize a character in an abbreviation or expansion.
 This regexp will be surrounded with \\\\( ... \\\\) when actually used.
 
 Set this variable to \"\\\\sw\" if you want ordinary words or
 This regexp will be surrounded with \\\\( ... \\\\) when actually used.
 
 Set this variable to \"\\\\sw\" if you want ordinary words or
@@ -205,13 +206,14 @@ 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'.
 
 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)
 
 (defcustom dabbrev-check-all-buffers t
   :type '(choice (const nil)
                 regexp)
   :group 'dabbrev)
 
 (defcustom dabbrev-check-all-buffers t
-  "*Non-nil means dabbrev package should search *all* buffers.
+  "Non-nil means dabbrev package should search *all* buffers.
 
 Dabbrev always searches the current buffer first.  Then, if
 `dabbrev-check-other-buffers' says so, it searches the buffers
 
 Dabbrev always searches the current buffer first.  Then, if
 `dabbrev-check-other-buffers' says so, it searches the buffers
@@ -224,21 +226,21 @@ or matched by `dabbrev-ignored-regexps'."
   :group 'dabbrev)
 
 (defcustom dabbrev-ignored-buffer-names '("*Messages*" "*Buffer List*")
   :group 'dabbrev)
 
 (defcustom dabbrev-ignored-buffer-names '("*Messages*" "*Buffer List*")
-  "*List of buffer names that dabbrev should not check.
+  "List of buffer names that dabbrev should not check.
 See also `dabbrev-ignored-buffer-regexps'."
   :type '(repeat (string :tag "Buffer name"))
   :group 'dabbrev
   :version "20.3")
 
 (defcustom dabbrev-ignored-buffer-regexps nil
 See also `dabbrev-ignored-buffer-regexps'."
   :type '(repeat (string :tag "Buffer name"))
   :group 'dabbrev
   :version "20.3")
 
 (defcustom dabbrev-ignored-buffer-regexps nil
-  "*List of regexps matching names of buffers that dabbrev should not check.
+  "List of regexps matching names of buffers that dabbrev should not check.
 See also `dabbrev-ignored-buffer-names'."
   :type '(repeat regexp)
   :group 'dabbrev
   :version "21.1")
 
 (defcustom dabbrev-check-other-buffers t
 See also `dabbrev-ignored-buffer-names'."
   :type '(repeat regexp)
   :group 'dabbrev
   :version "21.1")
 
 (defcustom dabbrev-check-other-buffers t
-  "*Should \\[dabbrev-expand] look in other buffers?\
+  "Should \\[dabbrev-expand] look in other buffers?\
 
 nil: Don't look in other buffers.
 t: Also look for expansions in the buffers pointed out by
 
 nil: Don't look in other buffers.
 t: Also look for expansions in the buffers pointed out by
@@ -265,7 +267,7 @@ for an example.
 A mode setting this variable should make it buffer local.")
 
 (defcustom dabbrev-friend-buffer-function 'dabbrev--same-major-mode-p
 A mode setting this variable should make it buffer local.")
 
 (defcustom dabbrev-friend-buffer-function 'dabbrev--same-major-mode-p
-  "*A function to decide whether dabbrev should search OTHER-BUFFER.
+  "A function to decide whether dabbrev should search OTHER-BUFFER.
 The function should take one argument, OTHER-BUFFER, and return
 non-nil if that buffer should be searched.  Have a look at
 `dabbrev--same-major-mode-p' for an example.
 The function should take one argument, OTHER-BUFFER, and return
 non-nil if that buffer should be searched.  Have a look at
 `dabbrev--same-major-mode-p' for an example.
@@ -283,15 +285,13 @@ A mode setting this variable should make it buffer local."
 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."
 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
 ;;----------------------------------------------------------------
 
   :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)
 
 ;; Table of expansions seen so far
 (defvar dabbrev--last-table nil)
 
@@ -319,9 +319,6 @@ this list."
 ;; The buffer we found the expansion last time.
 (defvar dabbrev--last-buffer-found 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)
 ;; If non-nil, a function to use when copying successive words.
 ;; It should be `upcase' or `downcase'.
 (defvar dabbrev--last-case-pattern nil)
@@ -339,9 +336,9 @@ this list."
 ;; Macros
 ;;----------------------------------------------------------------
 
 ;; Macros
 ;;----------------------------------------------------------------
 
-;;; Get the buffer that mini-buffer was activated from
 (defsubst dabbrev--minibuffer-origin ()
 (defsubst dabbrev--minibuffer-origin ()
-  (car (cdr (buffer-list))))
+  "Get the buffer from which mini-buffer."
+  (window-buffer (minibuffer-selected-window)))
 
 ;; Make a list of some of the elements of LIST.
 ;; Check each element of LIST, storing it temporarily in the
 
 ;; Make a list of some of the elements of LIST.
 ;; Check each element of LIST, storing it temporarily in the
@@ -362,20 +359,27 @@ this list."
 ;;----------------------------------------------------------------
 
 ;;;###autoload (define-key esc-map "/" 'dabbrev-expand)
 ;;----------------------------------------------------------------
 
 ;;;###autoload (define-key esc-map "/" 'dabbrev-expand)
-;;;??? Do we want this?
+;;??? Do we want this?
 ;;;###autoload (define-key esc-map [?\C-/] 'dabbrev-completion)
 
 ;;;###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.
 Like \\[dabbrev-expand] but finds all expansions in the current buffer
 and presents suggestions for completion.
 
 ;;;###autoload
 (defun dabbrev-completion (&optional arg)
   "Completion on current word.
 Like \\[dabbrev-expand] but finds all expansions in the current buffer
 and presents suggestions for completion.
 
-With a prefix argument, it searches all buffers accepted by the
+With a prefix argument ARG, it searches all buffers accepted by the
 function pointed out by `dabbrev-friend-buffer-function' to find the
 completions.
 
 function pointed out by `dabbrev-friend-buffer-function' to find the
 completions.
 
-If the prefix argument is 16 (which comes from C-u C-u),
+If the prefix argument is 16 (which comes from \\[universal-argument] \\[universal-argument]),
 then it searches *all* buffers."
   (interactive "*P")
   (dabbrev--reset-global-variables)
 then it searches *all* buffers."
   (interactive "*P")
   (dabbrev--reset-global-variables)
@@ -383,74 +387,43 @@ then it searches *all* buffers."
         (dabbrev-check-all-buffers
          (and arg (= (prefix-numeric-value arg) 16)))
         (abbrev (dabbrev--abbrev-at-point))
         (dabbrev-check-all-buffers
          (and arg (= (prefix-numeric-value arg) 16)))
         (abbrev (dabbrev--abbrev-at-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))
-       ;; Find the longest common string.
-       (setq init (try-completion abbrev my-obarray))))
-    ;;--------------------------------
-    ;; Let the user choose between the expansions
-    ;;--------------------------------
-    (or (stringp init)
-       (setq init abbrev))
-    (cond
-     ;; * Replace string fragment with matched common substring completion.
-     ((and (not (string-equal init ""))
-          (not (string-equal (downcase init) (downcase abbrev))))
-      (if (> (length (all-completions init my-obarray)) 1)
-         (message "Repeat `%s' to see all completions"
-                  (key-description (this-command-keys)))
-       (message "The only possible completion"))
-      (dabbrev--substitute-expansion nil abbrev init nil))
-     (t
-      ;; * String is a common substring completion already.  Make list.
-      (message "Making completion list...")
-      (with-output-to-temp-buffer "*Completions*"
-       (display-completion-list (all-completions init my-obarray)
-                                init))
-      (message "Making completion list...done")))
-    (and (window-minibuffer-p (selected-window))
-        (message nil))))
+         (beg (progn (search-backward abbrev) (point)))
+         (end (progn (search-forward abbrev) (point)))
+        (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)
 
 ;;;###autoload
 (defun dabbrev-expand (arg)
@@ -485,7 +458,7 @@ See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]."
               (markerp dabbrev--last-abbrev-location)
               (marker-position dabbrev--last-abbrev-location)
               (or (eq last-command this-command)
               (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.
                        (= dabbrev--last-abbrev-location
                           (point)))))
          ;; Find a different expansion for the same abbrev as last time.
@@ -542,12 +515,9 @@ See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]."
       ;;--------------------------------
       (or expansion
          (setq expansion
       ;;--------------------------------
       (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)
     (cond
      ((not expansion)
       (dabbrev--reset-global-variables)
@@ -558,13 +528,13 @@ See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]."
            (search-backward old)
            (insert abbrev)
            (delete-region (point) (+ (point) (length old)))))
            (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))))
          (progn
      (t
       (if (not (or (eq dabbrev--last-buffer dabbrev--last-buffer-found)
                   (minibuffer-window-active-p (selected-window))))
          (progn
-           (message "Expansion found in '%s'"
+           (message "Expansion found in `%s'"
                     (buffer-name dabbrev--last-buffer))
            (setq dabbrev--last-buffer-found dabbrev--last-buffer))
        (message nil))
                     (buffer-name dabbrev--last-buffer))
            (setq dabbrev--last-buffer-found dabbrev--last-buffer))
        (message nil))
@@ -588,16 +558,15 @@ See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]."
 ;; Local functions
 ;;----------------------------------------------------------------
 
 ;; Local functions
 ;;----------------------------------------------------------------
 
-;;; Checks if OTHER-BUFFER has the same major mode as current buffer.
 (defun dabbrev--same-major-mode-p (other-buffer)
 (defun dabbrev--same-major-mode-p (other-buffer)
+  "Check if OTHER-BUFFER has the same major mode as current buffer."
   (eq major-mode
   (eq major-mode
-      (save-excursion
-       (set-buffer other-buffer)
+      (with-current-buffer other-buffer
        major-mode)))
 
        major-mode)))
 
-;;; Back over all abbrev type characters and then moves forward over
-;;; all skip characters.
 (defun dabbrev--goto-start-of-abbrev ()
 (defun dabbrev--goto-start-of-abbrev ()
+  "Back over all abbrev type characters and then moves forward over
+all skip characters."
   ;; Move backwards over abbrev chars
   (save-match-data
     (when (> (point) (minibuffer-prompt-end))
   ;; Move backwards over abbrev chars
   (save-match-data
     (when (> (point) (minibuffer-prompt-end))
@@ -613,11 +582,11 @@ See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]."
         (while (looking-at dabbrev-abbrev-skip-leading-regexp)
           (forward-char 1)))))
 
         (while (looking-at dabbrev-abbrev-skip-leading-regexp)
           (forward-char 1)))))
 
-;;; Extract the symbol at point to serve as abbreviation.
 (defun dabbrev--abbrev-at-point ()
 (defun dabbrev--abbrev-at-point ()
+  "Extract the symbol at point to serve as abbreviation."
   ;; Check for error
   (if (bobp)
   ;; 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.
   ;; Return abbrev at point
   (save-excursion
     ;; Record the end of the abbreviation.
@@ -629,24 +598,20 @@ See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]."
     (save-match-data
       (if (save-excursion
            (forward-char -1)
     (save-match-data
       (if (save-excursion
            (forward-char -1)
-           (not (looking-at (concat "\\("
-                                    (or dabbrev-abbrev-char-regexp
-                                        "\\sw\\|\\s_")
-                                    "\\)+"))))
+           (not (looking-at (or dabbrev-abbrev-char-regexp
+                                 "\\sw\\|\\s_"))))
          (if (re-search-backward (or dabbrev-abbrev-char-regexp
                                      "\\sw\\|\\s_")
                                  nil t)
              (forward-char 1)
          (if (re-search-backward (or dabbrev-abbrev-char-regexp
                                      "\\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
      dabbrev--last-abbrev-location (point))))
 
     ;; Now find the beginning of that one.
     (dabbrev--goto-start-of-abbrev)
     (buffer-substring-no-properties
      dabbrev--last-abbrev-location (point))))
 
-;;; Initializes all global variables
 (defun dabbrev--reset-global-variables ()
 (defun dabbrev--reset-global-variables ()
-  ;; dabbrev--last-obarray and dabbrev--last-completion-buffer
-  ;; must not be reset here.
+  "Initialize all global variables."
   (setq dabbrev--last-table nil
        dabbrev--last-abbreviation nil
        dabbrev--last-abbrev-location nil
   (setq dabbrev--last-table nil
        dabbrev--last-abbreviation nil
        dabbrev--last-abbrev-location nil
@@ -691,13 +656,13 @@ of the expansion in `dabbrev--last-expansion-location'."
        (let ((case-fold-search ignore-case)
              (count n))
          (while (and (> count 0)
        (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)))
            (setq count (1- count))))
        (and expansion
             (setq dabbrev--last-expansion-location (point)))
@@ -787,6 +752,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)))
                                      (- (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.
         expansion)))))
 
 ;; Compute the list of buffers to scan.
@@ -828,7 +794,7 @@ of the start of the occurrence."
     ;; 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.
     ;; 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)
             (not dabbrev-search-these-buffers-only))
        (setq list
              (cons (dabbrev--minibuffer-origin)
@@ -852,14 +818,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)
 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.
 
     ;; If we upcased or downcased the original expansion,
     ;; do likewise for the subsequent words when we copy them.
@@ -885,12 +848,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)
     (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)))
                   (string= abbrev
                            (substring expansion 0 (length abbrev)))))
          (setq use-case-replace nil)))
@@ -974,9 +938,9 @@ Leaves point at the location of the start of the expansion."
       ;; Limited search.
       (save-restriction
        (and dabbrev-limit
       ;; 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.
        ;;--------------------------------
        ;;--------------------------------
        ;; Look for a distinct expansion, using dabbrev--last-table.
        ;;--------------------------------
@@ -1011,12 +975,6 @@ Leaves point at the location of the start of the expansion."
                (cons found-string dabbrev--last-table))
          result)))))
 
                (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)
 
 (provide 'dabbrev)
 
-;; arch-tag: 29e58596-f080-4306-a409-70296cf9d46f
 ;;; dabbrev.el ends here
 ;;; dabbrev.el ends here