* open file link in dired?
@ 2013-01-04 14:36 Alan Schmitt
2013-01-04 15:55 ` Bastien
0 siblings, 1 reply; 15+ messages in thread
From: Alan Schmitt @ 2013-01-04 14:36 UTC (permalink / raw
To: emacs-orgmode@gnu.org
Hello,
My google-fu has failed me, and
http://orgmode.org/manual/Handling-links.html does not seem to have the
answer: is it possible to open a file link in dired (i.e., a dired
buffer in the enclosing directory with the cursor on the file)?
Thanks,
Alan
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: open file link in dired?
2013-01-04 14:36 open file link in dired? Alan Schmitt
@ 2013-01-04 15:55 ` Bastien
2013-01-04 16:12 ` Alan Schmitt
0 siblings, 1 reply; 15+ messages in thread
From: Bastien @ 2013-01-04 15:55 UTC (permalink / raw
To: Alan Schmitt; +Cc: emacs-orgmode@gnu.org
Hi Alan,
Alan Schmitt <alan.schmitt@polytechnique.org> writes:
> My google-fu has failed me, and
> http://orgmode.org/manual/Handling-links.html does not seem to have the
> answer: is it possible to open a file link in dired (i.e., a dired
> buffer in the enclosing directory with the cursor on the file)?
I'd do something like this:
(org-add-link-type "file+emacs+dired" 'org-open-file-with-emacs-dired)
(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)))
which will work for a new link type file+emacs+dired.
But you can also setup `org-link-frame-setup' so that the function
associated to the file entry does the right thing for you.
HTH,
--
Bastien
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: open file link in dired?
2013-01-04 15:55 ` Bastien
@ 2013-01-04 16:12 ` Alan Schmitt
2013-01-04 16:33 ` Bastien
0 siblings, 1 reply; 15+ messages in thread
From: Alan Schmitt @ 2013-01-04 16:12 UTC (permalink / raw
To: Bastien; +Cc: emacs-orgmode@gnu.org
Bastien writes:
> Hi Alan,
>
> Alan Schmitt <alan.schmitt@polytechnique.org> writes:
>
>> My google-fu has failed me, and
>> http://orgmode.org/manual/Handling-links.html does not seem to have the
>> answer: is it possible to open a file link in dired (i.e., a dired
>> buffer in the enclosing directory with the cursor on the file)?
>
> I'd do something like this:
>
> (org-add-link-type "file+emacs+dired" 'org-open-file-with-emacs-dired)
>
> (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)))
>
> which will work for a new link type file+emacs+dired.
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?
Alan
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: open file link in dired?
2013-01-04 16:12 ` Alan Schmitt
@ 2013-01-04 16:33 ` Bastien
2014-07-28 7:09 ` Alan Schmitt
0 siblings, 1 reply; 15+ messages in thread
From: Bastien @ 2013-01-04 16:33 UTC (permalink / raw
To: Alan Schmitt; +Cc: emacs-orgmode@gnu.org
[-- Attachment #1: Type: text/plain, Size: 375 bytes --]
Hi Alan,
Alan Schmitt <alan.schmitt@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.
[-- Attachment #2: dired-link-type.el --]
[-- Type: application/emacs-lisp, Size: 675 bytes --]
[-- Attachment #3: Type: text/plain, Size: 14 bytes --]
--
Bastien
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: open file link in dired?
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
0 siblings, 2 replies; 15+ messages in thread
From: Alan Schmitt @ 2014-07-28 7:09 UTC (permalink / raw
To: Bastien; +Cc: emacs-orgmode@gnu.org
[-- Attachment #1: Type: text/plain, Size: 1497 bytes --]
Hi Bastien,
On 2013-01-04 17:33, Bastien <bzg@altern.org> writes:
> Hi Alan,
>
> Alan Schmitt <alan.schmitt@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 #2: Type: application/pgp-signature, Size: 494 bytes --]
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: open file link in dired?
2014-07-28 7:09 ` Alan Schmitt
@ 2014-07-28 13:57 ` Bastien
2014-12-10 3:05 ` Steven Arntson
1 sibling, 0 replies; 15+ messages in thread
From: Bastien @ 2014-07-28 13:57 UTC (permalink / raw
To: Alan Schmitt; +Cc: emacs-orgmode@gnu.org
Alan Schmitt <alan.schmitt@polytechnique.org> writes:
> Thanks again (and thanks to Org for letting me remember this 18 months
> old task),
Yep, I know that feeling ;)
Thanks for sharing the improved version!
--
Bastien
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: open file link in dired?
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
1 sibling, 1 reply; 15+ messages in thread
From: Steven Arntson @ 2014-12-10 3:05 UTC (permalink / raw
To: emacs-orgmode
Alan Schmitt <alan.schmitt@polytechnique.org> writes:
> Hi Bastien,
>
> On 2013-01-04 17:33, Bastien <bzg@altern.org> writes:
>
>> Hi Alan,
>>
>> Alan Schmitt <alan.schmitt@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
I've been searching many moons for this exact functionality! I'm very
glad to run across this, but as a fairly new emacser, I'm not sure what
to do with this code. I copied it into my init.el, marked it and ran
'eval-region', but what do I call to use the functions? If I can get this
working, I will be using it every day.
Thank you!
steven arntson
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: open file link in dired?
2014-12-10 3:05 ` Steven Arntson
@ 2014-12-10 7:48 ` Alan Schmitt
2014-12-10 9:51 ` Marcin Borkowski
0 siblings, 1 reply; 15+ messages in thread
From: Alan Schmitt @ 2014-12-10 7:48 UTC (permalink / raw
To: Steven Arntson; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 927 bytes --]
(I replied to Steve directly but forgot to copy the list. Here it is.)
On 2014-12-09 19:05, Steven Arntson <steven@stevenarntson.com> writes:
> I've been searching many moons for this exact functionality! I'm very
> glad to run across this, but as a fairly new emacser, I'm not sure what
> to do with this code. I copied it into my init.el, marked it and ran
> 'eval-region', but what do I call to use the functions? If I can get this
> working, I will be using it every day.
- open a directory in dired mode
- put the cursor on the file you want to link to
- call `org-store-link' (which may be bound to `C-c l')
The link is now stored. You can insert in an org file it with
`org-insert-link' (often bound to `C-c C-l').
Alternatively, you can use an org-capture template that captures a link
to the current context, and use it in dired mode.
Best,
Alan
--
OpenPGP Key ID : 040D0A3B4ED2E5C7
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 494 bytes --]
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: open file link in dired?
2014-12-10 7:48 ` Alan Schmitt
@ 2014-12-10 9:51 ` Marcin Borkowski
2014-12-10 10:25 ` Alan Schmitt
0 siblings, 1 reply; 15+ messages in thread
From: Marcin Borkowski @ 2014-12-10 9:51 UTC (permalink / raw
To: emacs-orgmode
Hi,
please note that I did not read the original message, but does this help?
http://mbork.pl/2013-10-06_Links_to_directories_in_Org-mode_files
Best,
mb
On 2014-12-10, at 08:48, Alan Schmitt wrote:
> (I replied to Steve directly but forgot to copy the list. Here it is.)
>
> On 2014-12-09 19:05, Steven Arntson <steven@stevenarntson.com> writes:
>
>> I've been searching many moons for this exact functionality! I'm very
>> glad to run across this, but as a fairly new emacser, I'm not sure what
>> to do with this code. I copied it into my init.el, marked it and ran
>> 'eval-region', but what do I call to use the functions? If I can get this
>> working, I will be using it every day.
>
> - open a directory in dired mode
> - put the cursor on the file you want to link to
> - call `org-store-link' (which may be bound to `C-c l')
>
> The link is now stored. You can insert in an org file it with
> `org-insert-link' (often bound to `C-c C-l').
>
> Alternatively, you can use an org-capture template that captures a link
> to the current context, and use it in dired mode.
>
> Best,
>
> Alan
--
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: open file link in dired?
2014-12-10 9:51 ` Marcin Borkowski
@ 2014-12-10 10:25 ` Alan Schmitt
2014-12-10 19:07 ` Steven Arntson
0 siblings, 1 reply; 15+ messages in thread
From: Alan Schmitt @ 2014-12-10 10:25 UTC (permalink / raw
To: Marcin Borkowski; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 374 bytes --]
On 2014-12-10 10:51, Marcin Borkowski <mbork@wmi.amu.edu.pl> writes:
> Hi,
>
> please note that I did not read the original message, but does this help?
>
> http://mbork.pl/2013-10-06_Links_to_directories_in_Org-mode_files
I think it's different: the goal here is too reveal the file in its
enclosing directory.
Alan
--
OpenPGP Key ID : 040D0A3B4ED2E5C7
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 494 bytes --]
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: open file link in dired?
2014-12-10 10:25 ` Alan Schmitt
@ 2014-12-10 19:07 ` Steven Arntson
2014-12-11 7:36 ` Alan Schmitt
0 siblings, 1 reply; 15+ messages in thread
From: Steven Arntson @ 2014-12-10 19:07 UTC (permalink / raw
To: emacs-orgmode
Alan Schmitt <alan.schmitt@polytechnique.org> writes:
> On 2014-12-10 10:51, Marcin Borkowski <mbork@wmi.amu.edu.pl> writes:
>
>> Hi,
>>
>> please note that I did not read the original message, but does this help?
>>
>> http://mbork.pl/2013-10-06_Links_to_directories_in_Org-mode_files
>
> I think it's different: the goal here is too reveal the file in its
> enclosing directory.
>
> Alan
Yes, that's exactly right.
Alan, I hadn't realized your code would work using the normal
keybindings. I tried it out this morning, and it works perfectly! I
really have been searching around for this kind of thing for a long
time. It seems like many people could find it useful.
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).
Thanks again!
Steven
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: open file link in dired?
2014-12-10 19:07 ` Steven Arntson
@ 2014-12-11 7:36 ` Alan Schmitt
2014-12-11 20:22 ` Haider Rizvi
0 siblings, 1 reply; 15+ messages in thread
From: Alan Schmitt @ 2014-12-11 7:36 UTC (permalink / raw
To: Steven Arntson; +Cc: emacs-orgmode
[-- 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 --]
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: open file link in dired?
2014-12-11 7:36 ` Alan Schmitt
@ 2014-12-11 20:22 ` Haider Rizvi
2014-12-12 8:02 ` Alan Schmitt
0 siblings, 1 reply; 15+ messages in thread
From: Haider Rizvi @ 2014-12-11 20:22 UTC (permalink / raw
To: emacs-orgmode
Alan Schmitt <alan.schmitt@polytechnique.org> writes:
> 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:
Alan, fyi if you don't know, openwith package does a pretty good job
of opening with external apps. I've been using it on osx for a while.
;; openwith setup to help in find-file, dired, helm, etc. for common file types
(use-package openwith
:ensure
:commands openwith-mode
:config
(progn
(openwith-mode t)
(setq openwith-associations
(quote (("\\.pdf\\'" "open" (file))
;; ("\\.svg\\'" "open" (file))
("\\.\\(?:mpe?g\\|avi\\|wmv\\)\\'" "open -a vlc" (file))
;; change .jpg to be able to show inline in .org mode
;; ("\\.\\(?:jp?g\\|png\\)\\'" "open" (file))
("\\.ppt[x]*\\'" "open" (file))
("\\.doc[x]*\\'" "open" (file))
("\\.xls[x]*\\'" "open" (file))
("\\.html\\'" "open" (file))
("\\.vNotes.*\\'" "open" (file)) ;spotlight searches for Notes open these files
)))))
Regards,
--
Haider
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: open file link in dired?
2014-12-11 20:22 ` Haider Rizvi
@ 2014-12-12 8:02 ` Alan Schmitt
2014-12-12 15:22 ` Haider Rizvi
0 siblings, 1 reply; 15+ messages in thread
From: Alan Schmitt @ 2014-12-12 8:02 UTC (permalink / raw
To: Haider Rizvi; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 625 bytes --]
On 2014-12-11 15:22, Haider Rizvi <harizvi@gmail.com> writes:
> Alan Schmitt <alan.schmitt@polytechnique.org> writes:
>
>> 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:
>
> Alan, fyi if you don't know, openwith package does a pretty good job
> of opening with external apps. I've been using it on osx for a while.
Thank you for the suggestion. Does it work well with gnus?
Alan
--
OpenPGP Key ID : 040D0A3B4ED2E5C7
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 494 bytes --]
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: open file link in dired?
2014-12-12 8:02 ` Alan Schmitt
@ 2014-12-12 15:22 ` Haider Rizvi
0 siblings, 0 replies; 15+ messages in thread
From: Haider Rizvi @ 2014-12-12 15:22 UTC (permalink / raw
To: emacs-orgmode
Alan Schmitt <alan.schmitt@polytechnique.org> writes:
>> Alan, fyi if you don't know, openwith package does a pretty good
>> job of opening with external apps. I've been using it on osx for a
>> while.
>
> Thank you for the suggestion. Does it work well with gnus?
Alan, I don't usually deal with attachments in gnus, only handling
newsgroups and simple mailing lists there. Quick check suggests it
doesn't honour openwith by default, so you'll have to find out.
Regards,
--
Haider
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2014-12-12 15:23 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-04 14:36 open file link in dired? 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
2014-12-11 20:22 ` Haider Rizvi
2014-12-12 8:02 ` Alan Schmitt
2014-12-12 15:22 ` Haider Rizvi
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.