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: Alan Schmitt
Subject: Re: Quickly Viewing Files in a File List, and then Quickly Closing
Date: Fri, 18 Oct 2013 13:32:24 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (darwin)

Eric Brown <address@hidden> writes:

> I am looking for a "QuickLook" feature for Emacs. For example, when
> scrolling through a file list in dired (or sunrise commander):
>
>  - is it possible to automatically show the contents of the file under
>    point in a second window? But if point is moved, quickly move along
>    and show the next file/image whatnot?
>
>  - is there a "hold-down-button" to view, and let off button to resume
>    browsing the file list?
>
> I currently use C-x 1 or C-x o q approaches, but I usually end up with
> e a bunch of buffers or sore fingers when going through many files.
>
> Does anyone have suggestions?  I apologize if the answer is sitting in
> the Emacs manual.

If you're using OS X, you could call the system's quicklook. This is
what I'm using here (it works great for images or pdf files, for
instance, I'm also including the code to open the file in the external
application).

#+begin_src emacs-lisp
  (defun do-ql-dwim()
    (interactive)
    (save-window-excursion
      (let* ((proc (get-buffer-process "*Async Shell Command*")))
        (if proc
            (kill-process proc)
          (dired-do-async-shell-command
           "qlmanage -p 2>/dev/null" ""
           (dired-get-marked-files))
          )
        (bury-buffer proc)
        ))
    )
  
  (defun open-in-external-app ()
    "Open the current file or dired marked files in external app.
  Works in Microsoft Windows, Mac OS X, Linux."
    (interactive)
    (let ( doIt
           (myFileList
            (cond
             ((string-equal major-mode "dired-mode") (dired-get-marked-files))
             (t (list (buffer-file-name))) ) ) )
  
      (setq doIt (if (<= (length myFileList) 5)
                     t
                   (y-or-n-p "Open more than 5 files?") ) )
      
      (when doIt
        (cond
         ((string-equal system-type "windows-nt")
          (mapc (lambda (fPath) (w32-shell-execute "open" 
(replace-regexp-in-string "/" "\\" fPath t t)) ) myFileList)
          )
         ((string-equal system-type "darwin")
          (mapc (lambda (fPath) (let ((process-connection-type nil)) 
(start-process "" nil "open" fPath)) )  myFileList) )
         ((string-equal system-type "gnu/linux")
          (mapc (lambda (fPath) (let ((process-connection-type nil)) 
(start-process "" nil "xdg-open" fPath)) ) myFileList) ) ) ) ) )
  
  (add-hook 'dired-mode-hook (lambda ()
                               (define-key dired-mode-map " " 'do-ql-dwim)
                               (define-key dired-mode-map (kbd "C-<return>") 
'open-in-external-app)
                               ))
#+end_src

Alan


reply via email to

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