Hi Bastien,

On 2013-01-04 17:33, Bastien <b...@altern.org> writes:

> Hi Alan,
>
> Alan Schmitt <alan.schm...@polytechnique.org> writes:
>
>> Thank you, this would work nicely. However I don't know how to specify,
>> when I open the file, which link-type to use. Would I need to modify the
>> link itself from "file" to "file+emacs+dired" before opening it?
>
> Trying loading the attached .el file to get a new "dired" type.
> Very crude but should work.

I finally got around to test this, and here is a slightly improved
version that handles filenames with spaces.

#+begin_src emacs-lisp
  (org-add-link-type "file+emacs+dired" 'org-open-file-with-emacs-dired)
  (add-hook 'org-store-link-functions 'org-dired-store-link)

  (defun org-open-file-with-emacs-dired (path)
    "Open in dired."
    (let ((d (file-name-directory path))
          (f (file-name-nondirectory path)))
      (dired d)
      (goto-char (point-min))
      (search-forward f nil t)))

  (defun org-dired-store-link ()
    "Store link to files/directories from dired."
    (require 'dired+)
    (when (eq major-mode 'dired-mode)
      (let ((f (dired-get-filename)))
        (setq link (concat "file+emacs+dired" ":" f)
              desc (concat f " (dired)"))
        (org-add-link-props :link link :description desc)
        link)))
#+end_src

Thanks again (and thanks to Org for letting me remember this 18 months
old task),

Alan

-- 
OpenPGP Key ID : 040D0A3B4ED2E5C7

Attachment: pgpUdU2jEJpkz.pgp
Description: PGP signature

Reply via email to