all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Kevin Rodgers <kevin.d.rodgers@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: C-x C-b (switch-to-buffer) smarter suggestions?
Date: Mon, 08 Feb 2010 21:46:21 -0700	[thread overview]
Message-ID: <hkqpao$f4n$1@ger.gmane.org> (raw)
In-Reply-To: <slrnhmq8ht.1qf.grahn+nntp@frailea.sa.invalid>

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





  parent reply	other threads:[~2010-02-09  4:46 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-06  8:03 C-x C-b (switch-to-buffer) smarter suggestions? Jorgen Grahn
2010-02-07  8:47 ` Alberto Luaces
     [not found] ` <mailman.826.1265532477.14305.help-gnu-emacs@gnu.org>
2010-02-07 22:54   ` Jorgen Grahn
2010-02-08  2:11 ` Stefan Monnier
2010-02-08 12:17   ` Jorgen Grahn
2010-02-08 17:38     ` Stefan Monnier
2010-02-08 18:23       ` Teemu Likonen
2010-02-11 10:35       ` Jorgen Grahn
2010-02-11 14:48         ` Richard Riley
2010-02-09 15:15     ` Richard Riley
     [not found]     ` <mailman.926.1265729432.14305.help-gnu-emacs@gnu.org>
2010-02-11 18:59       ` Jorgen Grahn
2010-02-08  5:55 ` Dmitri Minaev
     [not found] ` <mailman.852.1265608552.14305.help-gnu-emacs@gnu.org>
2010-02-08 11:45   ` Jorgen Grahn
2010-02-10  6:16     ` Dmitri Minaev
2010-02-09  4:46 ` Kevin Rodgers [this message]
     [not found] ` <mailman.897.1265690809.14305.help-gnu-emacs@gnu.org>
2010-02-11 22:45   ` Jorgen Grahn
2010-02-12  4:42     ` Kevin Rodgers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='hkqpao$f4n$1@ger.gmane.org' \
    --to=kevin.d.rodgers@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.