emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [O] open file link in dired?


From: Alan Schmitt
Subject: Re: [O] open file link in dired?
Date: Thu, 11 Dec 2014 08:36:26 +0100
User-agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/24.4 (darwin)

On 2014-12-10 11:07, Steven Arntson <address@hidden> writes:

> For me, I'll construct a list of project files in an org-mode buffer.
> Then I'll be able to easily visit those files in a dired directory and
> do whatever I need to (usually copying the files to a stick drive or
> other portable media to transfer to collaborators).

I'm very glad it helps, but Bastien should get all the credit here (I
only tweaked the solution he sent me).

My main motivation for using this is that I have some code to preview a
file using Quicklook (I'm on OS X), and code to open a file in an
external app when in dired, so it's quite useful for files that emacs
cannot display:

#+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

-- 
OpenPGP Key ID : 040D0A3B4ED2E5C7

Attachment: signature.asc
Description: PGP signature


reply via email to

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