2017-07-05 02:33:41 +02:00
|
|
|
;;; org/org-attach/autoload/org-attach.el -*- lexical-binding: t; -*-
|
2017-02-19 19:01:47 -05:00
|
|
|
|
2017-07-05 02:33:41 +02:00
|
|
|
(defun +org-attach--icon (path)
|
|
|
|
(char-to-string
|
|
|
|
(pcase (downcase (file-name-extension path))
|
|
|
|
((or "jpg" "jpeg" "png" "gif") ?)
|
|
|
|
("pdf" ?)
|
|
|
|
((or "ppt" "pptx") ?)
|
|
|
|
((or "xls" "xlsx") ?)
|
|
|
|
((or "doc" "docx") ?)
|
|
|
|
((or "ogg" "mp3" "wav" "aiff" "flac") ?)
|
|
|
|
((or "mp4" "mov" "avi") ?)
|
|
|
|
((or "zip" "gz" "tar" "7z" "rar") ?)
|
|
|
|
(_ ?))))
|
2017-02-19 19:01:47 -05:00
|
|
|
|
|
|
|
;;;###autoload
|
2017-07-05 02:33:41 +02:00
|
|
|
(defun +org-attach-cleanup ()
|
2017-02-19 19:01:47 -05:00
|
|
|
;; "Deletes any attachments that are no longer present in the org-mode buffer."
|
|
|
|
(let* ((attachments-local (+org-attachments))
|
2017-02-25 01:34:53 -05:00
|
|
|
(attachments (directory-files org-attach-directory t "^[^.]" t))
|
|
|
|
(to-delete (cl-set-difference attachments-local attachments)))
|
2017-02-19 19:01:47 -05:00
|
|
|
;; TODO
|
|
|
|
to-delete))
|
|
|
|
|
|
|
|
(defun +org-attachments ()
|
2017-07-05 02:33:41 +02:00
|
|
|
"List all attachments in the current buffer."
|
2017-02-19 19:01:47 -05:00
|
|
|
(unless (eq major-mode 'org-mode)
|
|
|
|
(user-error "Not an org buffer"))
|
|
|
|
(org-save-outline-visibility nil
|
|
|
|
(let ((attachments '())
|
2017-06-14 21:03:20 +02:00
|
|
|
element)
|
2017-02-25 01:34:53 -05:00
|
|
|
(when (and (file-directory-p org-attach-directory)
|
|
|
|
(> (length (file-expand-wildcards (expand-file-name "*" org-attach-directory))) 0))
|
2017-02-19 19:01:47 -05:00
|
|
|
(save-excursion
|
|
|
|
(goto-char (point-min))
|
|
|
|
(while (progn (org-next-link) (not org-link-search-failed))
|
2017-02-25 01:34:53 -05:00
|
|
|
(setq element (org-element-context))
|
|
|
|
(when-let (file (and (eq (org-element-type element) 'link)
|
|
|
|
(expand-file-name (org-element-property :path element))))
|
2017-02-19 19:01:47 -05:00
|
|
|
(when (and (string= (org-element-property :type element) "file")
|
2017-02-25 01:34:53 -05:00
|
|
|
(string= (concat (file-name-base (directory-file-name (file-name-directory file))) "/")
|
|
|
|
org-attach-directory)
|
2017-02-19 19:01:47 -05:00
|
|
|
(file-exists-p file))
|
|
|
|
(push file attachments))))))
|
2017-02-25 01:34:53 -05:00
|
|
|
(cl-remove-duplicates attachments))))
|
2017-02-19 19:01:47 -05:00
|
|
|
|
|
|
|
;;;###autoload
|
2017-07-05 02:33:41 +02:00
|
|
|
(defun +org-attach-download-dnd (uri action)
|
2017-02-19 19:01:47 -05:00
|
|
|
(if (eq major-mode 'org-mode)
|
|
|
|
(doom:org-attach uri) ;; FIXME
|
|
|
|
(let ((dnd-protocol-alist
|
2017-07-05 02:33:41 +02:00
|
|
|
(rassq-delete-all '+org-attach-download-dnd
|
|
|
|
(copy-alist dnd-protocol-alist))))
|
2017-02-19 19:01:47 -05:00
|
|
|
(dnd-handle-one-url nil action uri))))
|
|
|
|
|