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

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

RE: Cycling through favored buffers


From: Drew Adams
Subject: RE: Cycling through favored buffers
Date: Thu, 25 Apr 2013 15:14:04 -0700

> not sure how to incorporate your suggestion in my code.
> 
> So in the code that I have crs-hated-buffers, which are the 
> buffers to ignore:
> (defvar crs-hated-buffers
>   '("KILL" "*Compile-Log*" "*Buffer List*" "*Messages*"
>     "*compilation*" "TAGS" "*scratch*" "source" "headers")) 
> 
> How do I add the cl-remove-if to this variable so it would 
> include all dired type buffers?

You don't add it to that variable.  You treat your removal of those buffers as
one way to filter `buffer-list' and checking (derived-mode-p 'dired-mode) as
another way to filter.  IOW filter another way what you've already filtered one
way.  (Or typically better, filter both at the same time, so you traverse
`buffer-list' only once.)

> secondly, the code that I have cycles through all buffers 
> "except" the ignored ones mentioned above.
> So after I construct cl-remove-if-not that includes the 
> directories I want to only cycle through, how to apply that 
> on my code? or maybe I need a totally new function that would 
> do the trick?

Not sure what you really are trying to do.  You mentioned having two different
commands, one to remove hated stuff and dirs and the other keep only dir buffers
"headers" and "source".

But if you instead want a single command that removes (a) your hated buffers and
(b) buffers that are directories except "headers" and "source", then do just
that.

Your `crs-bury-buffer' uses a list of buffers.  Right now, you construct that
list by removing some (hated) buffers from `buffer-list'.  Conceptually, you can
do this: after you have removed those buffers, remove also the other ones you
want to remove.  And add back any others you want to keep.

But it is better to just use a single predicate (lambda (buf)...) that filters
`buffer-list' only once, in all of the ways you want, whatever they might be:
remove if this-or-that but not if such-and-such.

(let ((my-buflist
       (cl-remove-if (lambda (bf)
                       (and (or it-is-a-hated-buffer
                                it-is-a-directory)
                            (not it-is-headers-or-source)))
                     (buffer-list))))
  (switch-to-buffer...)

                     




reply via email to

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