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

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

RE: Quickly Viewing Files in a File List, and then Quickly Closing


From: Drew Adams
Subject: RE: Quickly Viewing Files in a File List, and then Quickly Closing
Date: Fri, 18 Oct 2013 09:55:27 -0700 (PDT)

> If you hold down `Control' while doing that (i.e., `C-down') then
> you act on each file in turn.  (You can use `C-RET' to act on a file
> that you have cycled to using just `up' or `down'.)
...
> You could easily define a command that would do that, say putting
> the `kill-buffer' action on a timer or associating it with an event
> (e.g. visiting the next file).

Here is a quick command definition that does that.  It lets you use
the Icicles alternate action keys, `C-S-RET', `C-S-down', etc., which
are analogous to the main action keys, `C-RET', `C-down', etc. (which
visit the candidate), to visit the candidate in `view-mode' and at
the same time kill the buffer of the last such visited candidate.

(defun my-find-file ()
  "Like `icicle-find-file', but alt action views file temporarily.
Alternate action keys such as `C-S-down' visit the candidate file in
`view-mode' and kill the buffer of the last such viewed candidate."
  (interactive)
  (let ((icicle-candidate-alt-action-fn
         (lambda (file)
           (when (and my-last-viewed
                      (get-file-buffer my-last-viewed))
             (kill-buffer (get-file-buffer my-last-viewed)))
           (setq my-last-viewed  (abbreviate-file-name file))
           (view-file file)
           (select-frame-set-input-focus
              (window-frame (active-minibuffer-window))))))
    (icicle-find-file-of-content)))

(defvar my-last-viewed nil
  "Last file viewed by alternate action of `my-find-file'.")

So you would:

1. Use `M-x my-find-file' (or bind it to a key - e.g., `C-x C-f').
2. Optionally type part of a file name, to limit the matching names.
3. Optionally use `down' or `up' to cycle among file names.
4. Use `C-S-down' to visit the next file in order.
5. Repeat #4 to see other files in order.
6. Repeat #2 or #3 to see other sets of files.
7. End with `RET' to choose a file to visit or `C-g' to cancel.

Each file buffer you visited with `C-S-down' was killed when you
viewed the next one.  You can also mix in `C-down' or `C-RET' to
also visit files whose buffers you do not want to kill
automatically.  (Change `view-file' to `find-file' if you don't
want to visit in `view-mode', which is read-only.)

[By default, the alternate action for `icicle-find-file' is
`icicle-alt-act-fn-for-type', which prompts you for a file-
appropriate action to use on the particular candidate chosen for
the action.  Command `my-find-file' just substitutes a different
alternate action function (for all candidates you choose).]



reply via email to

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