emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Alan Schmitt <alan.schmitt@polytechnique.org>
To: Steven Arntson <steven@stevenarntson.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: open file link in dired?
Date: Thu, 11 Dec 2014 08:36:26 +0100	[thread overview]
Message-ID: <m2ppbqzlhh.fsf@charm-wifi.irisa.fr> (raw)
In-Reply-To: <87fvcn8gtg.fsf@stevenarntson.com> (Steven Arntson's message of "Wed, 10 Dec 2014 11:07:07 -0800")

[-- Attachment #1: Type: text/plain, Size: 2305 bytes --]

On 2014-12-10 11:07, Steven Arntson <steven@stevenarntson.com> 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 #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 494 bytes --]

  reply	other threads:[~2014-12-11  7:36 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-04 14:36 Alan Schmitt
2013-01-04 15:55 ` Bastien
2013-01-04 16:12   ` Alan Schmitt
2013-01-04 16:33     ` Bastien
2014-07-28  7:09       ` Alan Schmitt
2014-07-28 13:57         ` Bastien
2014-12-10  3:05         ` Steven Arntson
2014-12-10  7:48           ` Alan Schmitt
2014-12-10  9:51             ` Marcin Borkowski
2014-12-10 10:25               ` Alan Schmitt
2014-12-10 19:07                 ` Steven Arntson
2014-12-11  7:36                   ` Alan Schmitt [this message]
2014-12-11 20:22                     ` Haider Rizvi
2014-12-12  8:02                       ` Alan Schmitt
2014-12-12 15:22                         ` Haider Rizvi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2ppbqzlhh.fsf@charm-wifi.irisa.fr \
    --to=alan.schmitt@polytechnique.org \
    --cc=emacs-orgmode@gnu.org \
    --cc=steven@stevenarntson.com \
    --subject='Re: open file link in dired?' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Code repositories for project(s) associated with this inbox:

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).