[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: This code won't match buffer names. Why not?
From: |
Benjamin Andresen |
Subject: |
Re: This code won't match buffer names. Why not? |
Date: |
Sat, 22 Aug 2009 03:09:48 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux) |
Chris Seberino <cseberino@gmail.com> writes:
> When I cycle through buffers, I'd like to skip *scratch*, *Messages*
> and *Whitespace Errors* buffers.
>
> I wrote following code to skip one more buffer if I'm sitting in
> either of those 3.
>
> However, it never matches those buffers. Why not?
(current-buffer) returns an buffer and not the buffer-name.
You can check that with M-: (current-buffer)
Use (buffer-name (current-buffer)) and string-match. Or see below.
> (BTW, the (end-kbd-macro) is just a dummy function since "if" needs an
> "else" command.
> Is there a better dummy command I can add there?)
`if' also need an else part. Check C-h f if
> ; Sets F10 to execute a function that moves to another buffer.
> (global-set-key [f10] (lambda () (interactive)
> (next-buffer)
> (if (equal (current-buffer)
> "*scratch*")
> (next-buffer)
> (end-kbd-macro))
> (if (equal (current-buffer)
> "*Messages*")
> (next-buffer)
> (end-kbd-macro))
> (if (equal (current-buffer)
> "*Whitespace Errors*")
> (next-buffer)
> (end-kbd-macro))))
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))))
HTH,
benny