[comp.emacs] Buffer-menu kill all files

hollen@eta.megatek.uucp (Dion Hollenbeck) (08/09/89)

Thanks to all who responded to my question.  With help from them and
some more poking around myself, the solution is as follows for anyone
who could benefit by it.  The reason I needed this code is that I have
been using tags-search and after a search I sometimes end up with
up to 60 or so files being edited by Emacs.  This is a quick way to
kill all of them.  When the function finishes, the point is at the
bottom of the buffer list window and I can merely move up the the first
file I want to keep, use "u" on all my regular files to be kept and
then "x" to delete all the ones used in tags-search.


ALL THE FOLLOWING WERE ADDED IN MY .EMACS FILE:

;;  Add key to buffer menu mode
(defun buffer-menu-mode-hook-fun ()
    "Add key mapping for Buffer-menu-mark-all-delete function"
  (define-key Buffer-menu-mode-map "a" 'Buffer-menu-mark-all-delete)
  (use-local-map Buffer-menu-mode-map)
)

;;  Add function name to mode hook
(setq buffer-menu-mode-hook 'buffer-menu-mode-hook-fun)

;;  Define additional function for buffer menu mode
(defun Buffer-menu-mark-all-delete ()
  "Mark all buffers to be deleted by \\[Buffer-menu-execute] command.
    Finish at the end of the buffer menu."
  (interactive)
  (goto-char (point-min))
  (while (looking-at " [-M]") (forward-line 1))
  (while (looking-at "[ .]") 
    (Buffer-menu-delete)
  )
)


	Dion Hollenbeck             (619) 455-5590 x2814
	Megatek Corporation, 9645 Scranton Road, San Diego, CA  92121

        uunet!megatek!hollen       or  hollen@megatek.uucp

jcgs@wundt.harlqn.uucp (John Sturdy(Jcgs)) (08/11/89)

I have a file containing functions for doing assorted things to the
buffer list, such as deleting all those whose filenames match a given
regexp. I posted it quite a while ago, I could re-post it if people
want, or mail it if there's not enough demand for posting.

--
__John            When asked to attend a court case, Father Moses took with him
          a leaking jug of water. Asked about it, he said: "You ask me to judge
               the faults of another, while mine run out like water behind me."

                jcgs@uk.co.harlqn (UK notation) jcgs@harlqn.co.uk (most places)
    ...!mcvax!ukc!harlqn!jcgs (uucp - really has more stages, but ukc knows us)
John Sturdy                                            Telephone +44-223-872522
                      Harlequin Ltd, Barrington Hall, Barrington, Cambridge, UK

ecb@utrccm (ecb) (08/16/89)

on 9 Aug 89 15:07:44 GMT,
Dion Hollenbeck <hp-sdd!megatek!eta!hollen@hplabs.hp.COM> said:
    Dion> Sender: arpa-unix-emacs-request@bbn.COM References:
    Dion> <661@mipos3.intel.com> Source-Info: From (or Sender) name
    Dion> not authenticated.

    Dion> Thanks to all who responded to my question.  With help from
    Dion> them and some more poking around myself, the solution is as
    Dion> follows for anyone who could benefit by it.  The reason I
    Dion> needed this code is that I have been using tags-search and
    Dion> after a search I sometimes end up with up to 60 or so files
    Dion> being edited by Emacs.  This is a quick way to kill all of
    Dion> them.  When the function finishes, the point is at the
    Dion> bottom of the buffer list window and I can merely move up
    Dion> the the first file I want to keep, use "u" on all my regular
    Dion> files to be kept and then "x" to delete all the ones used in
    Dion> tags-search.

Good idea. I've had this problem myself. 

I've added an inverse of the function you posted (for when fat fingers
or brain-dead key-banging might cause me grief) and offer it here.

Also I prefer not to have modified buffers be marked for deletion by
any automatic process (too much chance that I'll purge useful changes)
so I've modified the original code to check and leave such buffers
alone.  A better solution would be to mark, in some easily recognized
way, all buffers added by a tags search, but this is beyond my skills.
Anyone else care to try?

			Bud Boman
			United Technologies Research Center
			(203) 727-7128
			ecb@utrccm.smc.utc.com


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;  Add key to buffer menu mode
(defun buffer-menu-mode-hook-fun ()
    "Add key mapping for Buffer-menu-mark-all-delete function"
  (define-key Buffer-menu-mode-map "a" 'Buffer-menu-mark-all-delete)
  (define-key Buffer-menu-mode-map "U" 'Buffer-menu-unmark-all-delete)
  (use-local-map Buffer-menu-mode-map)
)

;;  Add function name to mode hook
(setq buffer-menu-mode-hook 'buffer-menu-mode-hook-fun)

;;  Define additional function for buffer menu mode
(defun Buffer-menu-mark-all-delete ()
  "Mark all buffers to be deleted by \\[Buffer-menu-execute] command.
    Finish at the end of the buffer menu."
  (interactive)
  (goto-char (point-min))
  (while (looking-at " [-M]") (forward-line 1))
  (while (looking-at "[ .D]")
    (if (or (looking-at " \\*") (looking-at ".\\*") )
        (forward-line 1) (Buffer-menu-delete)
        )
    )
  (goto-char (point-min) )
  (next-line 2)
)

(defun Buffer-menu-unmark-all-delete ()
  "Mark all buffers to be deleted by \\[Buffer-menu-execute] command.
    Finish at the end of the buffer menu."
  (interactive)
  (goto-char (point-min))
  (while (or (looking-at " [-M]") (looking-at "\\.") ) (forward-line 1))
  (while (looking-at "[ D]") 
    (Buffer-menu-unmark)
  )
  (goto-char (point-min) )
  (next-line 2)
)