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

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

Re: This code won't match buffer names. Why not?


From: David Kastrup
Subject: Re: This code won't match buffer names. Why not?
Date: Mon, 31 Aug 2009 14:03:59 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux)

address@hidden (Pascal J. Bourguignon) writes:

> David Kastrup <address@hidden> writes:
>
>> Benjamin Andresen <address@hidden> writes:
>>
>>> The rewritten code would be better written like this:
>>>
>>> (global-set-key (kbd "<f10>")
>>>                 '(lambda ()
>>>                   (interactive)
>>>                   (next-buffer)
>>>                   (while (member (buffer-name (current-buffer))
>>>                                  '("*scratch*" "*Messages*" "*Whitespace 
>>> Errors*"))
>>>                     (next-buffer))))
>>
>> What if only *scratch* is left?
>
> (defvar *bad-buffers* '("*scratch*" "*Messages*" "*Whitespace Errors*"))
>
> (defun next-good-buffer ()
>    (interactive)
>    (unless (= 1 (length (buffer-list)))
>       (next-buffer)
>       (while (member (buffer-name (current-buffer)) *bad-buffers*)
>           (next-buffer))))
>
> (global-set-key (kbd "<f10>") 'next-good-buffer)

What if both *scratch* and *Messages* are left?

I mean, think before you post.

Something like
(defun next-good-buffer ()
  (interactive)
  (let ((old-buffer (current-buffer)))
    (while (and (not (eq old-buffer (progn (next-buffer) (current-buffer))))
                (member (buffer-name (current-buffer)) *bad-buffers*)))))

I am not sure whether next-buffer is supposed to revisit a hidden buffer
when starting out from it, so this is not completely fool-proof.  But I
am short of time right now...

-- 
David Kastrup


reply via email to

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