emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Searching all attachments in org-files
@ 2017-12-25 19:46 Narendra Joshi
  2017-12-26  0:06 ` Ihor Radchenko
  0 siblings, 1 reply; 3+ messages in thread
From: Narendra Joshi @ 2017-12-25 19:46 UTC (permalink / raw)
  To: emacs-orgmode

Hi,

Is there a way to quick get a link to an existing attachment? A lot of
times, I find myself referring to the same file. I like to keep files as
attachments so that they are committed with my org-files. Any help here,
either in fixing my workflow or helping me figure out how to get a link
to an existing file that is attached to an org-heading, would be greatly
appreciated.

Thanks,
-- 
Narendra Joshi

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Searching all attachments in org-files
  2017-12-25 19:46 Searching all attachments in org-files Narendra Joshi
@ 2017-12-26  0:06 ` Ihor Radchenko
  2017-12-26 13:56   ` Narendra Joshi
  0 siblings, 1 reply; 3+ messages in thread
From: Ihor Radchenko @ 2017-12-26  0:06 UTC (permalink / raw)
  To: Narendra Joshi, emacs-orgmode

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

Dear Narendra,

Here is what I am using:

(defun org-att-complete-link (&optional arg)
  "Completion dispatcher for att: links (rewritten from org-attach-open)"
  (let* ((attach-dir (org-attach-dir t))
	 (files (org-attach-file-list attach-dir))
	 (file (if (= (length files) 1)
		   (car files)
		 (completing-read "att: "
				  (mapcar #'list files) nil t)))
	 (path (expand-file-name file attach-dir)))
    (concat "att:" file)))
(add-to-list 'org-link-abbrev-alist '("att" . org-attach-expand-link))
(org-link-set-parameters
 "att"
 :complete 'org-att-complete-link)

Regards,
Ihor


Narendra Joshi <narendraj9@gmail.com> writes:

> Hi,
>
> Is there a way to quick get a link to an existing attachment? A lot of
> times, I find myself referring to the same file. I like to keep files as
> attachments so that they are committed with my org-files. Any help here,
> either in fixing my workflow or helping me figure out how to get a link
> to an existing file that is attached to an org-heading, would be greatly
> appreciated.
>
> Thanks,
> -- 
> Narendra Joshi
>

-- 
Ihor Radchenko,
PhD Student
Singapore University of Technology and Design,
8 Somapah Road Singapore 487372
Email: yantar92@gmail.com, ihor_radchenko@mymail.sutd.edu.sg
Tel: +6584017977

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Searching all attachments in org-files
  2017-12-26  0:06 ` Ihor Radchenko
@ 2017-12-26 13:56   ` Narendra Joshi
  0 siblings, 0 replies; 3+ messages in thread
From: Narendra Joshi @ 2017-12-26 13:56 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode

Ihor Radchenko <yantar92@gmail.com> writes:

> Dear Narendra,
>
> Here is what I am using:
>
> (defun org-att-complete-link (&optional arg)
>   "Completion dispatcher for att: links (rewritten from org-attach-open)"
>   (let* ((attach-dir (org-attach-dir t))
> 	 (files (org-attach-file-list attach-dir))
> 	 (file (if (= (length files) 1)
> 		   (car files)
> 		 (completing-read "att: "
> 				  (mapcar #'list files) nil t)))
> 	 (path (expand-file-name file attach-dir)))
>     (concat "att:" file)))
> (add-to-list 'org-link-abbrev-alist '("att" . org-attach-expand-link))
> (org-link-set-parameters
>  "att"
>  :complete 'org-att-complete-link)
#+begin_src emacs-lisp
(defun org-att-complete-link (&optional arg)
    "Completion dispatcher for att: links (rewritten from org-attach-open)"
    (let* ((attach-dir (expand-file-name org-attach-directory org-directory))
	       (file-paths (directory-files-recursively attach-dir ".*"))
           (completions (mapcar (lambda (f)
                                  (cons (file-name-base f) f))
                                file-paths))
	       (file-name (completing-read "att: " completions nil t))
	       (path (assoc-default file-name completions)))
      (concat "att:" path)))
#+end_src

This worked for me. I had to change it a bit for my use case. Thanks a
lot for the help! :)

--
Narendra Joshi

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-12-26 13:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-25 19:46 Searching all attachments in org-files Narendra Joshi
2017-12-26  0:06 ` Ihor Radchenko
2017-12-26 13:56   ` Narendra Joshi

Code repositories for project(s) associated with this public 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).