Subject: hippie-expand, a patch

From: Emilio C. Lopes <[email-masked]>
Date: Tue, 28 Jan 2014 08:35:37 +0100

Package: emacs
Version: 24.3
Tags: patch

Resent from http://lists.gnu.org/archive/html/emacs-devel/2014-01/msg02160.html

[ It has been quite a long time since I've submited a patch to GNU Emacs.
  Please let me know if I should be doing it differently. ]

`hippie-expand' use several methods to expand text in the current buffer.
Some of those methods search for possible expansions in multiple Emacs
buffers, controlled by the variables `hippie-expand-ignore-buffers' and
`hippie-expand-only-buffers'.

It would be useful to be able to set these two variables locally in a
Buffer (using `make-local-variable').  This would allow for example to
set up `hippie-expand' in Lisp buffers to only search for possible
expansions in other Lisp buffers.

As it is now (Emacs 24.3) the functions in `hippie-expand' using those
variables do so in the context of the buffers where potential completions
are searched for.  The patch bellow causes the lookup to occur in the
buffer where `hippie-expand' was invoked.

Regards

 Emílio

2014-01-27  Emilio C. Lopes  <[email-masked]>

    * hippie-exp.el (try-expand-line-all-buffers)
    (try-expand-list-all-buffers, try-expand-dabbrev-all-buffers):
    Use the value of `hippie-expand-only-buffers' and
    `hippie-expand-ignore-buffers' from the buffer where
    `hippie-expand' was invoked allowing these variables to be
    buffer-local.

diff --unified lisp/hippie-exp.el.\~1\~ lisp/hippie-exp.el
--- lisp/hippie-exp.el.~1~	2013-03-17 20:52:38.000000000 +0100
+++ lisp/hippie-exp.el		2014-01-27 20:29:12.000000000 +0100
@@ -642,6 +642,8 @@
                comint-use-prompt-regexp
                comint-prompt-regexp))
     (buf (current-buffer))
+        (only-buffers hippie-expand-only-buffers)
+        (ignore-buffers hippie-expand-ignore-buffers)
     (orig-case-fold-search case-fold-search))
     (if (not old)
     (progn
@@ -657,9 +659,9 @@
             (< he-searched-n-bufs hippie-expand-max-buffers)))
       (set-buffer (car he-search-bufs))
       (if (and (not (eq (current-buffer) buf))
-           (if hippie-expand-only-buffers
-               (he-buffer-member hippie-expand-only-buffers)
-             (not (he-buffer-member hippie-expand-ignore-buffers))))
+           (if only-buffers
+               (he-buffer-member only-buffers)
+             (not (he-buffer-member ignore-buffers))))
           (save-excursion
         (save-restriction
           (if hippie-expand-no-restriction
@@ -771,6 +773,8 @@
 string).  It returns t if a new completion is found, nil otherwise."
   (let ((expansion ())
     (buf (current-buffer))
+        (only-buffers hippie-expand-only-buffers)
+        (ignore-buffers hippie-expand-ignore-buffers)
     (orig-case-fold-search case-fold-search))
     (if (not old)
     (progn
@@ -786,9 +790,9 @@
             (< he-searched-n-bufs hippie-expand-max-buffers)))
       (set-buffer (car he-search-bufs))
       (if (and (not (eq (current-buffer) buf))
-           (if hippie-expand-only-buffers
-               (he-buffer-member hippie-expand-only-buffers)
-             (not (he-buffer-member hippie-expand-ignore-buffers))))
+           (if only-buffers
+               (he-buffer-member only-buffers)
+             (not (he-buffer-member ignore-buffers))))
           (save-excursion
         (save-restriction
           (if hippie-expand-no-restriction
@@ -926,6 +930,8 @@
 string).  It returns t if a new expansion is found, nil otherwise."
   (let ((expansion ())
     (buf (current-buffer))
+        (only-buffers hippie-expand-only-buffers)
+        (ignore-buffers hippie-expand-ignore-buffers)
     (orig-case-fold-search case-fold-search))
     (if (not old)
     (progn
@@ -941,9 +947,9 @@
             (< he-searched-n-bufs hippie-expand-max-buffers)))
       (set-buffer (car he-search-bufs))
       (if (and (not (eq (current-buffer) buf))
-           (if hippie-expand-only-buffers
-               (he-buffer-member hippie-expand-only-buffers)
-             (not (he-buffer-member hippie-expand-ignore-buffers))))
+           (if only-buffers
+               (he-buffer-member only-buffers)
+             (not (he-buffer-member ignore-buffers))))
           (save-excursion
         (save-restriction
           (if hippie-expand-no-restriction

Diff finished.  Mon Jan 27 22:20:31 2014