diff options
| author | Stefan Monnier | 2009-11-25 05:31:05 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2009-11-25 05:31:05 +0000 |
| commit | 5f24557b126b05f314cb3a548fe2fbfd09d017ff (patch) | |
| tree | 79057951ef7440ed01693b0630a2326f23c98b62 | |
| parent | fe4346f0da7e8cc578eb60813bfc8e4e36c62c34 (diff) | |
| download | emacs-5f24557b126b05f314cb3a548fe2fbfd09d017ff.tar.gz emacs-5f24557b126b05f314cb3a548fe2fbfd09d017ff.zip | |
(dabbrev--minibuffer-origin): Use minibuffer-selected-window.
(dabbrev-completion): Use completion-in-region.
(dabbrev--abbrev-at-point): Simplify regexp.
| -rw-r--r-- | lisp/ChangeLog | 4 | ||||
| -rw-r--r-- | lisp/dabbrev.el | 56 |
2 files changed, 20 insertions, 40 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 3049fbea5f0..92f0ed538fe 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,9 @@ | |||
| 1 | 2009-11-25 Stefan Monnier <monnier@iro.umontreal.ca> | 1 | 2009-11-25 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 2 | ||
| 3 | * dabbrev.el (dabbrev--minibuffer-origin): Use minibuffer-selected-window. | ||
| 4 | (dabbrev-completion): Use completion-in-region. | ||
| 5 | (dabbrev--abbrev-at-point): Simplify regexp. | ||
| 6 | |||
| 3 | * abbrev.el (abbrev--before-point): Use word-motion functions | 7 | * abbrev.el (abbrev--before-point): Use word-motion functions |
| 4 | if :regexp is not specified (bug#5031). | 8 | if :regexp is not specified (bug#5031). |
| 5 | 9 | ||
diff --git a/lisp/dabbrev.el b/lisp/dabbrev.el index 115d579a079..d716cbd5f38 100644 --- a/lisp/dabbrev.el +++ b/lisp/dabbrev.el | |||
| @@ -341,9 +341,9 @@ this list." | |||
| 341 | ;; Macros | 341 | ;; Macros |
| 342 | ;;---------------------------------------------------------------- | 342 | ;;---------------------------------------------------------------- |
| 343 | 343 | ||
| 344 | ;;; Get the buffer that mini-buffer was activated from | ||
| 345 | (defsubst dabbrev--minibuffer-origin () | 344 | (defsubst dabbrev--minibuffer-origin () |
| 346 | (car (cdr (buffer-list)))) | 345 | "Get the buffer from which mini-buffer." |
| 346 | (window-buffer (minibuffer-selected-window))) | ||
| 347 | 347 | ||
| 348 | ;; Make a list of some of the elements of LIST. | 348 | ;; Make a list of some of the elements of LIST. |
| 349 | ;; Check each element of LIST, storing it temporarily in the | 349 | ;; Check each element of LIST, storing it temporarily in the |
| @@ -364,7 +364,7 @@ this list." | |||
| 364 | ;;---------------------------------------------------------------- | 364 | ;;---------------------------------------------------------------- |
| 365 | 365 | ||
| 366 | ;;;###autoload (define-key esc-map "/" 'dabbrev-expand) | 366 | ;;;###autoload (define-key esc-map "/" 'dabbrev-expand) |
| 367 | ;;;??? Do we want this? | 367 | ;;??? Do we want this? |
| 368 | ;;;###autoload (define-key esc-map [?\C-/] 'dabbrev-completion) | 368 | ;;;###autoload (define-key esc-map [?\C-/] 'dabbrev-completion) |
| 369 | 369 | ||
| 370 | ;;;###autoload | 370 | ;;;###autoload |
| @@ -373,11 +373,11 @@ this list." | |||
| 373 | Like \\[dabbrev-expand] but finds all expansions in the current buffer | 373 | Like \\[dabbrev-expand] but finds all expansions in the current buffer |
| 374 | and presents suggestions for completion. | 374 | and presents suggestions for completion. |
| 375 | 375 | ||
| 376 | With a prefix argument, it searches all buffers accepted by the | 376 | With a prefix argument ARG, it searches all buffers accepted by the |
| 377 | function pointed out by `dabbrev-friend-buffer-function' to find the | 377 | function pointed out by `dabbrev-friend-buffer-function' to find the |
| 378 | completions. | 378 | completions. |
| 379 | 379 | ||
| 380 | If the prefix argument is 16 (which comes from C-u C-u), | 380 | If the prefix argument is 16 (which comes from \\[prefix-argument] \\[prefix-argument]), |
| 381 | then it searches *all* buffers." | 381 | then it searches *all* buffers." |
| 382 | (interactive "*P") | 382 | (interactive "*P") |
| 383 | (dabbrev--reset-global-variables) | 383 | (dabbrev--reset-global-variables) |
| @@ -385,6 +385,8 @@ then it searches *all* buffers." | |||
| 385 | (dabbrev-check-all-buffers | 385 | (dabbrev-check-all-buffers |
| 386 | (and arg (= (prefix-numeric-value arg) 16))) | 386 | (and arg (= (prefix-numeric-value arg) 16))) |
| 387 | (abbrev (dabbrev--abbrev-at-point)) | 387 | (abbrev (dabbrev--abbrev-at-point)) |
| 388 | (beg (progn (search-backward abbrev) (point))) | ||
| 389 | (end (progn (search-forward abbrev) (point))) | ||
| 388 | (ignore-case-p (and (if (eq dabbrev-case-fold-search 'case-fold-search) | 390 | (ignore-case-p (and (if (eq dabbrev-case-fold-search 'case-fold-search) |
| 389 | case-fold-search | 391 | case-fold-search |
| 390 | dabbrev-case-fold-search) | 392 | dabbrev-case-fold-search) |
| @@ -427,32 +429,8 @@ then it searches *all* buffers." | |||
| 427 | (intern (downcase string) my-obarray))) | 429 | (intern (downcase string) my-obarray))) |
| 428 | completion-list))) | 430 | completion-list))) |
| 429 | (setq dabbrev--last-obarray my-obarray) | 431 | (setq dabbrev--last-obarray my-obarray) |
| 430 | (setq dabbrev--last-completion-buffer (current-buffer)) | 432 | (setq dabbrev--last-completion-buffer (current-buffer)))) |
| 431 | ;; Find the longest common string. | 433 | (completion-in-region beg end my-obarray))) |
| 432 | (setq init (try-completion abbrev my-obarray)))) | ||
| 433 | ;;-------------------------------- | ||
| 434 | ;; Let the user choose between the expansions | ||
| 435 | ;;-------------------------------- | ||
| 436 | (or (stringp init) | ||
| 437 | (setq init abbrev)) | ||
| 438 | (cond | ||
| 439 | ;; * Replace string fragment with matched common substring completion. | ||
| 440 | ((and (not (string-equal init "")) | ||
| 441 | (not (string-equal (downcase init) (downcase abbrev)))) | ||
| 442 | (if (> (length (all-completions init my-obarray)) 1) | ||
| 443 | (message "Repeat `%s' to see all completions" | ||
| 444 | (key-description (this-command-keys))) | ||
| 445 | (message "The only possible completion")) | ||
| 446 | (dabbrev--substitute-expansion nil abbrev init nil)) | ||
| 447 | (t | ||
| 448 | ;; * String is a common substring completion already. Make list. | ||
| 449 | (message "Making completion list...") | ||
| 450 | (with-output-to-temp-buffer "*Completions*" | ||
| 451 | (display-completion-list (all-completions init my-obarray) | ||
| 452 | init)) | ||
| 453 | (message "Making completion list...done"))) | ||
| 454 | (and (window-minibuffer-p (selected-window)) | ||
| 455 | (message nil)))) | ||
| 456 | 434 | ||
| 457 | ;;;###autoload | 435 | ;;;###autoload |
| 458 | (defun dabbrev-expand (arg) | 436 | (defun dabbrev-expand (arg) |
| @@ -590,15 +568,15 @@ See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]." | |||
| 590 | ;; Local functions | 568 | ;; Local functions |
| 591 | ;;---------------------------------------------------------------- | 569 | ;;---------------------------------------------------------------- |
| 592 | 570 | ||
| 593 | ;;; Checks if OTHER-BUFFER has the same major mode as current buffer. | ||
| 594 | (defun dabbrev--same-major-mode-p (other-buffer) | 571 | (defun dabbrev--same-major-mode-p (other-buffer) |
| 572 | "Check if OTHER-BUFFER has the same major mode as current buffer." | ||
| 595 | (eq major-mode | 573 | (eq major-mode |
| 596 | (with-current-buffer other-buffer | 574 | (with-current-buffer other-buffer |
| 597 | major-mode))) | 575 | major-mode))) |
| 598 | 576 | ||
| 599 | ;;; Back over all abbrev type characters and then moves forward over | ||
| 600 | ;;; all skip characters. | ||
| 601 | (defun dabbrev--goto-start-of-abbrev () | 577 | (defun dabbrev--goto-start-of-abbrev () |
| 578 | "Back over all abbrev type characters and then moves forward over | ||
| 579 | all skip characters." | ||
| 602 | ;; Move backwards over abbrev chars | 580 | ;; Move backwards over abbrev chars |
| 603 | (save-match-data | 581 | (save-match-data |
| 604 | (when (> (point) (minibuffer-prompt-end)) | 582 | (when (> (point) (minibuffer-prompt-end)) |
| @@ -614,8 +592,8 @@ See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]." | |||
| 614 | (while (looking-at dabbrev-abbrev-skip-leading-regexp) | 592 | (while (looking-at dabbrev-abbrev-skip-leading-regexp) |
| 615 | (forward-char 1))))) | 593 | (forward-char 1))))) |
| 616 | 594 | ||
| 617 | ;;; Extract the symbol at point to serve as abbreviation. | ||
| 618 | (defun dabbrev--abbrev-at-point () | 595 | (defun dabbrev--abbrev-at-point () |
| 596 | "Extract the symbol at point to serve as abbreviation." | ||
| 619 | ;; Check for error | 597 | ;; Check for error |
| 620 | (if (bobp) | 598 | (if (bobp) |
| 621 | (error "No possible abbreviation preceding point")) | 599 | (error "No possible abbreviation preceding point")) |
| @@ -630,10 +608,8 @@ See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]." | |||
| 630 | (save-match-data | 608 | (save-match-data |
| 631 | (if (save-excursion | 609 | (if (save-excursion |
| 632 | (forward-char -1) | 610 | (forward-char -1) |
| 633 | (not (looking-at (concat "\\(" | 611 | (not (looking-at (or dabbrev-abbrev-char-regexp |
| 634 | (or dabbrev-abbrev-char-regexp | 612 | "\\sw\\|\\s_")))) |
| 635 | "\\sw\\|\\s_") | ||
| 636 | "\\)+")))) | ||
| 637 | (if (re-search-backward (or dabbrev-abbrev-char-regexp | 613 | (if (re-search-backward (or dabbrev-abbrev-char-regexp |
| 638 | "\\sw\\|\\s_") | 614 | "\\sw\\|\\s_") |
| 639 | nil t) | 615 | nil t) |
| @@ -644,8 +620,8 @@ See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]." | |||
| 644 | (buffer-substring-no-properties | 620 | (buffer-substring-no-properties |
| 645 | dabbrev--last-abbrev-location (point)))) | 621 | dabbrev--last-abbrev-location (point)))) |
| 646 | 622 | ||
| 647 | ;;; Initializes all global variables | ||
| 648 | (defun dabbrev--reset-global-variables () | 623 | (defun dabbrev--reset-global-variables () |
| 624 | "Initialize all global variables." | ||
| 649 | ;; dabbrev--last-obarray and dabbrev--last-completion-buffer | 625 | ;; dabbrev--last-obarray and dabbrev--last-completion-buffer |
| 650 | ;; must not be reset here. | 626 | ;; must not be reset here. |
| 651 | (setq dabbrev--last-table nil | 627 | (setq dabbrev--last-table nil |