all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Cycling through favored buffers
@ 2013-04-24 22:59 Rami A
  2013-04-25 21:32 ` Drew Adams
       [not found] ` <mailman.24641.1366925547.855.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 4+ messages in thread
From: Rami A @ 2013-04-24 22:59 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,

I have some code in my dotemacs file that would allow me to switch between opened files and ignoring specific buffers, like "TAGS" "Messages" and some folder names "headers" "source". I am binding this behavior to both C-Tab and C-M-Tab.

I have two questions"
1. How do I ignore "all directory type buffers" and limit the switching to be between files only.

2. How do I create another list of buffers that only includes directories "headers" and "source" and when press a combination of keys lets say C-M-S-Tab to cycle through only these?

This is the snippet of code that I have:


;; Control TABbuffer Cycling
; necessary support function for buffer burial
(defun crs-delete-these (delete-these from-this-list)
  "Delete DELETE-THESE FROM-THIS-LIST."
  (cond
   ((car delete-these)
    (if (member (car delete-these) from-this-list)
	(crs-delete-these (cdr delete-these) (delete (car delete-these)
                                                     from-this-list))
      (crs-delete-these (cdr delete-these) from-this-list)))
   (t from-this-list)))

; this is the list of buffers I never want to see
(defvar crs-hated-buffers
  '("KILL" "*Compile-Log*" "*Buffer List*" "*Messages*"
    "*compilation*" "TAGS" "*scratch*" "source" "headers"))
; might as well use this for both
(setq iswitchb-buffer-ignore (append '("^ " "*Buffer") crs-hated-buffers))

(defun crs-hated-buffers ()
  "List of buffers I never want to see, converted from names to buffers."
  (delete nil
	  (append
	   (mapcar 'get-buffer crs-hated-buffers)
	   (mapcar (lambda (this-buffer)
		     (if (string-match "^ " (buffer-name this-buffer))
			 this-buffer))
		   (buffer-list)))))
; I'm sick of switching buffers only to find KILL right in front of me
(defun crs-bury-buffer (&optional n)
  (interactive)
  (unless n
    (setq n 1))
  (let ((my-buffer-list (crs-delete-these (crs-hated-buffers)
					  (buffer-list (selected-frame)))))
    (switch-to-buffer
     (if (< n 0)
	 (nth (+ (length my-buffer-list) n)
	      my-buffer-list)
       (bury-buffer)
       (nth n my-buffer-list)))))
; Key Bindings
(global-set-key [(control tab)] 'crs-bury-buffer)
(global-set-key [(control meta tab)] (lambda ()
				       (interactive)
				       (crs-bury-buffer -1)))


^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: Cycling through favored buffers
  2013-04-24 22:59 Cycling through favored buffers Rami A
@ 2013-04-25 21:32 ` Drew Adams
       [not found] ` <mailman.24641.1366925547.855.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 4+ messages in thread
From: Drew Adams @ 2013-04-25 21:32 UTC (permalink / raw)
  To: 'Rami A', help-gnu-emacs

> 1. How do I ignore "all directory type buffers" and limit the 
> switching to be between files only.

(cl-remove-if (lambda (buf)
                (with-current-buffer buf
                  (derived-mode-p 'dired-mode)))
              (buffer-list))
 
> 2. How do I create another list of buffers that only includes 
> directories "headers" and "source"

(cl-remove-if-not (lambda (buf)
                    (member (buffer-name buf) '("headers" "source"))
                  (buffer-list))




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Cycling through favored buffers
       [not found] ` <mailman.24641.1366925547.855.help-gnu-emacs@gnu.org>
@ 2013-04-25 21:38   ` Rami A
  2013-04-25 22:14     ` Drew Adams
  0 siblings, 1 reply; 4+ messages in thread
From: Rami A @ 2013-04-25 21:38 UTC (permalink / raw)
  To: help-gnu-emacs

Drew. Much appreciation for your response.
I am very new to lisp and not sure how to incorporate your suggestion in my pasted 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")) 
(setq iswitchb-buffer-ignore (append '("^ " "*Buffer") crs-hated-buffers))

How do I add the cl-remove-if to this variable so it would include all dired type buffers?

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?

Thanks.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: Cycling through favored buffers
  2013-04-25 21:38   ` Rami A
@ 2013-04-25 22:14     ` Drew Adams
  0 siblings, 0 replies; 4+ messages in thread
From: Drew Adams @ 2013-04-25 22:14 UTC (permalink / raw)
  To: 'Rami A', help-gnu-emacs

> 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...)

                     




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-04-25 22:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-24 22:59 Cycling through favored buffers Rami A
2013-04-25 21:32 ` Drew Adams
     [not found] ` <mailman.24641.1366925547.855.help-gnu-emacs@gnu.org>
2013-04-25 21:38   ` Rami A
2013-04-25 22:14     ` Drew Adams

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.