help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C-x C-b (switch-to-buffer) smarter suggestions?


From: Kevin Rodgers
Subject: Re: C-x C-b (switch-to-buffer) smarter suggestions?
Date: Mon, 08 Feb 2010 21:46:21 -0700
User-agent: Thunderbird 2.0.0.23 (Macintosh/20090812)

Jorgen Grahn wrote:
This is a minor annoyance for me daily, and I'm hoping someone has a
readymade elisp fix.  I'm not much of an elisp hacker -- my ~/.emacs
has stayed basically the same since 1996.

Let's say I have a dozen buffers, including foo.c and foo.h.  I am in
foo.c but I want to jump to foo.h. So I do

  C-x C-b foo TAB

But this doesn't complete to foo.h, because foo.c is also an
alternative -- even though that's the buffer I'm explicitly trying to
switch *from*.

(defvar switch-from-buffer nil)

(defadvice switch-to-buffer (before switch-from-buffer activate)
  "Temporarily bind `switch-from-buffer' to the current buffer
while reading args interactively.  See `internal-complete-buffer'."
  (interactive (let ((switch-from-buffer (current-buffer)))
                 (read-buffer "Switch to buffer: " (other-buffer)))))

(defun internal-complete-buffer (string predicate flag)
  "Just like Finternal_complete_buffer(), but exclude `switch-from-buffer'."
  ;; emulate buffer-alist:
  (let ((buffer-alist (mapcar (lambda (buffer)
                                (cons (buffer-name buffer) buffer))
                              (delq switch-from-buffer (buffer-list)))))
    (cond ((null flag)
           (try-completion string buffer-alist predicate))
          ((eq flag t)
           (all-completions string buffer-alist predicate t))
          (t                            ; assume `lambda'
           (test-completion string buffer-alist predicate)))))

--
Kevin Rodgers
Denver, Colorado, USA





reply via email to

[Prev in Thread] Current Thread [Next in Thread]