[Top][All Lists]

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

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

From: Jorgen Grahn
Subject: Re: C-x C-b (switch-to-buffer) smarter suggestions?
Date: 11 Feb 2010 22:45:30 GMT
User-agent: slrn/pre0.9.9-111 (Linux)

On Tue, 2010-02-09, Kevin Rodgers wrote:
> 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)))))

Thanks! I can't get it to work though, when just pasted into ~/.emacs:

- C-x b
- prompt appears, I type 'foo' and press return
- error message: 'Wrong type argument: listp, "foo"'


PS I'm slow to respond as you see -- so don't spend too much time
   debugging it unless you get something out of it for yourself.

  // Jorgen Grahn <grahn@  Oo  o.   .  .
\X/>   O  o   .

reply via email to

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