branch: master
commit 58de02ca7f543f0dfdfdb5885950051fdca9e339
Author: Oleh Krehel <[email protected]>
Commit: Oleh Krehel <[email protected]>

    counsel.el (counsel-org-file): New command
---
 counsel.el | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/counsel.el b/counsel.el
index 7dd9e5b..63e42ef 100644
--- a/counsel.el
+++ b/counsel.el
@@ -2652,6 +2652,34 @@ The face can be customized through 
`counsel-org-goto-face-style'."
             (nth (1- level) counsel-org-goto-custom-faces)))
       (propertize name 'face 'minibuffer-prompt)))
 
+;;** `counsel-org-file'
+(defun counsel-org-file-ids ()
+  (let (cands)
+    (save-excursion
+      (goto-char (point-min))
+      (while (re-search-forward "^:ID: *\\([^ \n]+\\)$" nil t)
+        (push (match-string-no-properties 1) cands)))
+    (nreverse cands)))
+
+(defun counsel-org-files ()
+  (mapcar 'file-relative-name
+          (cl-mapcan
+           (lambda (id)
+             (directory-files
+              (format "data/%s/%s"
+                      (substring id 0 2)
+                      (substring id 2))
+              t "^[^.]"))
+           (counsel-org-file-ids))))
+
+;;;###autoload
+(defun counsel-org-file ()
+  "Browse all attachments for current Org file."
+  (interactive)
+  (ivy-read "file: " (counsel-org-files)
+            :action 'counsel-locate-action-dired
+            :caller 'counsel-org-file))
+
 ;;** `counsel-mark-ring'
 (defun counsel--pad (string length)
   "Pad STRING to LENGTH with spaces."

Reply via email to