X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/f3ae252109ab36ccd232d42dd896eaaea80b5ccc..0d4afaf7ffb6d1881c9acf9ef03f386cc87254e6:/lisp/dabbrev.el?ds=sidebyside diff --git a/lisp/dabbrev.el b/lisp/dabbrev.el index cbab591d4b..1127181dca 100644 --- a/lisp/dabbrev.el +++ b/lisp/dabbrev.el @@ -1,7 +1,7 @@ ;;; dabbrev.el --- dynamic abbreviation package ;; Copyright (C) 1985, 1986, 1992, 1994, 1996, 1997, 2000, 2001, 2002, -;; 2003, 2004, 2005, 2006, 2007, 2008, 2009 +;; 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 ;; Free Software Foundation, Inc. ;; Author: Don Morrison @@ -62,8 +62,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))))) @@ -145,6 +144,7 @@ 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. @@ -185,6 +185,7 @@ 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. @@ -340,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 @@ -363,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 @@ -372,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) @@ -384,6 +385,8 @@ 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) @@ -426,32 +429,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) @@ -589,16 +568,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)) @@ -614,8 +592,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")) @@ -630,10 +608,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) @@ -644,8 +620,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