Add 2012 to FSF copyright years for Emacs files
[bpt/emacs.git] / lisp / dabbrev.el
index fd75179..7b94b53 100644 (file)
@@ -1,9 +1,11 @@
 ;;; dabbrev.el --- dynamic abbreviation package
 
-;; 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-2012
+;;   Free Software Foundation, Inc.
 
 ;; 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
@@ -59,8 +61,7 @@
 ;; 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)))))
 
 
   :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
-  "*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
-  "*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 `$'.
@@ -127,13 +128,13 @@ Set this to nil if no characters should be skipped."
   :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
-  "*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.
@@ -142,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)
+;;;###autoload(put 'dabbrev-case-fold-search 'risky-local-variable t)
 
 (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.
 
@@ -154,7 +156,7 @@ This variable has an effect only when the value of
   :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.
@@ -169,7 +171,7 @@ This variable has an effect only when the value of
   :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.
@@ -182,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)
+;;;###autoload(put 'dabbrev-case-replace 'risky-local-variable t)
 
 (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
@@ -203,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'.
 
-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
-  "*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
@@ -222,21 +226,21 @@ or matched by `dabbrev-ignored-regexps'."
   :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
-  "*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
-  "*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
@@ -263,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 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.
@@ -337,9 +341,9 @@ this list."
 ;; Macros
 ;;----------------------------------------------------------------
 
-;;; Get the buffer that mini-buffer was activated from
 (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
@@ -360,7 +364,7 @@ this list."
 ;;----------------------------------------------------------------
 
 ;;;###autoload (define-key esc-map "/" 'dabbrev-expand)
-;;;??? Do we want this?
+;;??? Do we want this?
 ;;;###autoload (define-key esc-map [?\C-/] 'dabbrev-completion)
 
 ;;;###autoload
@@ -369,11 +373,11 @@ this list."
 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.
 
-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)
@@ -381,13 +385,14 @@ then it searches *all* buffers."
         (dabbrev-check-all-buffers
          (and arg (= (prefix-numeric-value arg) 16)))
         (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)
+        (my-obarray dabbrev--last-obarray))
     (save-excursion
       ;;--------------------------------
       ;; New abbreviation to expand.
@@ -423,32 +428,8 @@ then it searches *all* buffers."
                            (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))))
+       (setq dabbrev--last-completion-buffer (current-buffer))))
+    (completion-in-region beg end my-obarray)))
 
 ;;;###autoload
 (defun dabbrev-expand (arg)
@@ -586,16 +567,15 @@ See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]."
 ;; Local functions
 ;;----------------------------------------------------------------
 
-;;; Checks if OTHER-BUFFER has the same major mode as current buffer.
 (defun dabbrev--same-major-mode-p (other-buffer)
+  "Check if OTHER-BUFFER has the same major mode as current buffer."
   (eq major-mode
-      (save-excursion
-       (set-buffer other-buffer)
+      (with-current-buffer other-buffer
        major-mode)))
 
-;;; Back over all abbrev type characters and then moves forward over
-;;; all skip characters.
 (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))
@@ -611,8 +591,8 @@ See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]."
         (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 ()
+  "Extract the symbol at point to serve as abbreviation."
   ;; Check for error
   (if (bobp)
       (error "No possible abbreviation preceding point"))
@@ -627,10 +607,8 @@ See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]."
     (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)
@@ -641,8 +619,8 @@ See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]."
     (buffer-substring-no-properties
      dabbrev--last-abbrev-location (point))))
 
-;;; Initializes all global variables
 (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
@@ -1016,5 +994,4 @@ Leaves point at the location of the start of the expansion."
 
 (provide 'dabbrev)
 
-;; arch-tag: 29e58596-f080-4306-a409-70296cf9d46f
 ;;; dabbrev.el ends here