Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

counsel.el (counsel-org-file): Handle ATTACH_DIR property #2042

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 12 additions & 15 deletions counsel.el
Expand Up @@ -3294,26 +3294,23 @@ attachment directory associated with the current buffer, all
contained files are listed, so the return value could conceivably
include attachments of other Org buffers."
(require 'org-attach)
(let* ((ids (let (res)
(save-excursion
(goto-char (point-min))
(while (re-search-forward "^:ID:[\t ]+\\(.*\\)$" nil t)
(push (match-string-no-properties 1) res))
(nreverse res))))
(files
(cl-remove-if-not
#'file-exists-p
(mapcar (lambda (id)
(expand-file-name
(concat (substring id 0 2) "/" (substring id 2))
org-attach-directory))
ids))))
(let (dirs)
(save-excursion
(goto-char (point-min))
(while (re-search-forward "^:\\(ATTACH_DIR\\|ID\\):[\t ]+\\(.*\\)$" nil t)
(let ((dir (match-string-no-properties 2)))
(when (string= "ID" (match-string-no-properties 1))
(setq dir (expand-file-name
(concat (substring dir 0 2) "/" (substring dir 2))
org-attach-directory)))
(when (file-exists-p dir)
(push dir dirs)))))
(cl-mapcan
(lambda (dir)
(mapcar (lambda (file)
(file-relative-name (expand-file-name file dir)))
(org-attach-file-list dir)))
files)))
(nreverse dirs))))

;;;###autoload
(defun counsel-org-file ()
Expand Down