From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Jorgen Grahn Newsgroups: gmane.emacs.help Subject: Re: C-x C-b (switch-to-buffer) smarter suggestions? Date: 11 Feb 2010 22:45:30 GMT Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1265931647 25772 80.91.229.12 (11 Feb 2010 23:40:47 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 11 Feb 2010 23:40:47 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Feb 12 00:40:45 2010 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1NfieJ-0001fN-75 for geh-help-gnu-emacs@m.gmane.org; Fri, 12 Feb 2010 00:40:43 +0100 Original-Received: from localhost ([127.0.0.1]:43647 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NfieI-0002cR-HT for geh-help-gnu-emacs@m.gmane.org; Thu, 11 Feb 2010 18:40:42 -0500 Original-Path: news.stanford.edu!usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 50 Original-X-Trace: individual.net wDOVy/qhWW95zVTQAtzykQ6EmlwFaD9lCCvPS/fpW7Md7gYgkE Cancel-Lock: sha1:mPJZBHq+KQvtqr6co6cxVVb3Yoo= User-Agent: slrn/pre0.9.9-111 (Linux) Original-Xref: news.stanford.edu gnu.emacs.help:176739 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:71811 Archived-At: 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"' /Jorgen 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 O o .