* This code won't match buffer names. Why not?
@ 2009-08-22 0:31 Chris Seberino
2009-08-22 1:09 ` Benjamin Andresen
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Chris Seberino @ 2009-08-22 0:31 UTC (permalink / raw)
To: help-gnu-emacs
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?
(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?)
; 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))))
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: This code won't match buffer names. Why not?
2009-08-22 0:31 This code won't match buffer names. Why not? Chris Seberino
@ 2009-08-22 1:09 ` Benjamin Andresen
2009-08-22 1:12 ` Benjamin Andresen
2009-08-29 13:06 ` David Kastrup
2009-08-22 2:50 ` Xah Lee
2009-08-22 7:27 ` Ivan Kanis
2 siblings, 2 replies; 8+ messages in thread
From: Benjamin Andresen @ 2009-08-22 1:09 UTC (permalink / raw)
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: This code won't match buffer names. Why not?
2009-08-22 1:09 ` Benjamin Andresen
@ 2009-08-22 1:12 ` Benjamin Andresen
2009-08-29 13:06 ` David Kastrup
1 sibling, 0 replies; 8+ messages in thread
From: Benjamin Andresen @ 2009-08-22 1:12 UTC (permalink / raw)
To: help-gnu-emacs
Benjamin Andresen <benny@in-ulm.de> writes:
> `if' also need an else part. Check C-h f if
^ doesn't
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: This code won't match buffer names. Why not?
2009-08-22 0:31 This code won't match buffer names. Why not? Chris Seberino
2009-08-22 1:09 ` Benjamin Andresen
@ 2009-08-22 2:50 ` Xah Lee
2009-08-22 7:27 ` Ivan Kanis
2 siblings, 0 replies; 8+ messages in thread
From: Xah Lee @ 2009-08-22 2:50 UTC (permalink / raw)
To: help-gnu-emacs
On Aug 21, 5:31 pm, Chris Seberino <cseber...@gmail.com> wrote:
> 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?
>
> (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?)
>
> ; 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))))
Wee, the code to skip emacs buffers is in ergoemacs here:
http://code.google.com/p/ergoemacs/
by default it's Ctrl + Page up/down is the shortcut, similar to
Firefox et al for switching tabs.
With shift key down, it cycle among emacs's buffers.
here's the relevant code:
(defun next-user-buffer ()
"Switch to the next user buffer.
User buffers are those whose name does not start with *."
(interactive)
(next-buffer)
(let ((i 0))
(while (and (string-match "^*" (buffer-name)) (< i 50))
(setq i (1+ i)) (next-buffer) )))
Xah
∑ http://xahlee.org/
☄
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: This code won't match buffer names. Why not?
2009-08-22 0:31 This code won't match buffer names. Why not? Chris Seberino
2009-08-22 1:09 ` Benjamin Andresen
2009-08-22 2:50 ` Xah Lee
@ 2009-08-22 7:27 ` Ivan Kanis
2 siblings, 0 replies; 8+ messages in thread
From: Ivan Kanis @ 2009-08-22 7:27 UTC (permalink / raw)
To: Chris Seberino; +Cc: help-gnu-emacs
Chris Seberino <cseberino@gmail.com> wrote:
> ; 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))
Try buffer-name instead of current-buffer and maybe string= instead of
equal. I am not sure why you call end-kbd-macro. Also there is no need
to put interactive because you won't call an anonymous function.
--
Ivan
Kanis http://kanis.fr
Deep Hack Mode--that mysterious and frightening state of
consciousness where Mortal Users fear to tread.
-- Matt Welsh
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: This code won't match buffer names. Why not?
2009-08-22 1:09 ` Benjamin Andresen
2009-08-22 1:12 ` Benjamin Andresen
@ 2009-08-29 13:06 ` David Kastrup
2009-08-31 9:13 ` Pascal J. Bourguignon
1 sibling, 1 reply; 8+ messages in thread
From: David Kastrup @ 2009-08-29 13:06 UTC (permalink / raw)
To: help-gnu-emacs
Benjamin Andresen <benny@in-ulm.de> 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?
--
David Kastrup
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: This code won't match buffer names. Why not?
2009-08-29 13:06 ` David Kastrup
@ 2009-08-31 9:13 ` Pascal J. Bourguignon
2009-08-31 12:03 ` David Kastrup
0 siblings, 1 reply; 8+ messages in thread
From: Pascal J. Bourguignon @ 2009-08-31 9:13 UTC (permalink / raw)
To: help-gnu-emacs
David Kastrup <dak@gnu.org> writes:
> Benjamin Andresen <benny@in-ulm.de> 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)
--
__Pascal Bourguignon__
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: This code won't match buffer names. Why not?
2009-08-31 9:13 ` Pascal J. Bourguignon
@ 2009-08-31 12:03 ` David Kastrup
0 siblings, 0 replies; 8+ messages in thread
From: David Kastrup @ 2009-08-31 12:03 UTC (permalink / raw)
To: help-gnu-emacs
pjb@informatimago.com (Pascal J. Bourguignon) writes:
> David Kastrup <dak@gnu.org> writes:
>
>> Benjamin Andresen <benny@in-ulm.de> 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
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2009-08-31 12:03 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-22 0:31 This code won't match buffer names. Why not? Chris Seberino
2009-08-22 1:09 ` Benjamin Andresen
2009-08-22 1:12 ` Benjamin Andresen
2009-08-29 13:06 ` David Kastrup
2009-08-31 9:13 ` Pascal J. Bourguignon
2009-08-31 12:03 ` David Kastrup
2009-08-22 2:50 ` Xah Lee
2009-08-22 7:27 ` Ivan Kanis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).