8

Similar to this question, I'd like a tool/minor mode to quickly preview my files by merely having the cursor positioned over them (e.g. the currently selected file is displayed in the active buffer window). I don't care about depressing events and I don't want an overlay. If it's selected, I want it displayed in the active window. Pressing enter and switching to the buffer is too slow to skim through a bunch of raw data files. How could I do this?

  • For those users who use OSX, there is a native application called qlmanage that can be used to display the file contents or pdf or image. Another forum participant has written a function to delete subsequent processes when viewing multiple items (one after another) with said application. Here is the link to the relevant thread: stackoverflow.com/questions/20023458/… I currently have it set up so that I can use the arrow key up or down in a file manager mode and qlmanage displays the file contents at point. – lawlist Mar 28 '15 at 2:44
4

This StackOverflow question is the same as yours. And the accepted answer by the OP is a good one. There are other good answers there, as well.

Similarly, this question to help-gnu-emacs@gnu.org is essentially the same also.

My own answer to both questions is to use Icicles and to define this command:

    (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'.")

Then you can:

  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.

See the linked posts for more info.

  • 1
    I know its your right to choose your development model. As a user I would like it be on github or in some git repository rather than emacswiki. You don't need to reply to me, just writing here to let you know what I feel. Thanks by the way, for your long continuing efforts in helping emacs users. – kindahero Oct 23 '14 at 3:36
  • @kindahero: FWIW, all of my libraries are also on [MELPA](www.melpa.org). – Drew Oct 23 '14 at 15:38
12

I discovered this functionality is already built-in to Helm. To use it, use the up and down arrows and press C-up/C-down.

  • 1
    Thank you for mentioning this. There is always something else simple yet amazing to learn about Helm! – blujay Mar 29 '15 at 11:08
  • I remember that this used to work at one point, but I tried it recently and got the error message "Helm-follow-mode allowed only on images, disabling". I tried removing the bit that checks that, and helm-follow-mode appears to still work with regular files, though it's a bit slow to open each file. Does anyone know why they changed this behavior? – 0x5453 May 2 '18 at 17:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.