2017-12-08 22:59:42 -05:00
|
|
|
;;; lang/org/autoload/org-attach.el -*- lexical-binding: t; -*-
|
2017-02-19 19:01:47 -05:00
|
|
|
|
2019-10-25 20:00:06 -04:00
|
|
|
;;;###autoload
|
|
|
|
(defun +org-attach-icon-for (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") ?)
|
|
|
|
(_ ?))))
|
|
|
|
|
2018-02-18 04:30:49 -05:00
|
|
|
;;;###autoload
|
2019-12-29 16:31:25 -05:00
|
|
|
(defun +org/open-gallery-from-attachments ()
|
|
|
|
"TODO"
|
|
|
|
(interactive)
|
|
|
|
(require 'org-attach)
|
|
|
|
(if-let (dir (org-attach-dir))
|
|
|
|
(pop-to-buffer
|
|
|
|
;; Rather than opening dired *and* image-dired windows, suppress them
|
|
|
|
;; both and open only the image-dired window.
|
|
|
|
(save-window-excursion
|
|
|
|
(image-dired dir)
|
|
|
|
(current-buffer)))
|
|
|
|
(user-error "No attachments for this node")))
|
2018-02-18 04:30:49 -05:00
|
|
|
|
|
|
|
;;;###autoload
|
2019-12-29 16:31:25 -05:00
|
|
|
(defun +org/find-file-in-attachments ()
|
2019-09-20 23:10:53 -04:00
|
|
|
"Open a file from `org-attach-id-dir'."
|
2018-02-18 04:30:49 -05:00
|
|
|
(interactive)
|
2019-09-20 23:10:53 -04:00
|
|
|
(doom-project-browse org-attach-id-dir))
|
2017-09-07 17:25:38 +02:00
|
|
|
|
|
|
|
;;;###autoload
|
2019-12-29 16:31:25 -05:00
|
|
|
(defun +org/attach-file-and-insert-link (path)
|
|
|
|
"Downloads the file at PATH and insert an org link at point.
|
|
|
|
PATH (a string) can be an url, a local file path, or a base64 encoded datauri."
|
2017-09-07 17:25:38 +02:00
|
|
|
(interactive "sUri/file: ")
|
2017-02-19 19:01:47 -05:00
|
|
|
(unless (eq major-mode 'org-mode)
|
2017-09-07 17:25:38 +02:00
|
|
|
(user-error "Not in an org buffer"))
|
|
|
|
(require 'org-download)
|
2020-04-25 01:27:25 -04:00
|
|
|
(condition-case-unless-debug e
|
2019-12-29 16:31:25 -05:00
|
|
|
(let ((raw-uri (url-unhex-string path)))
|
|
|
|
(cond ((string-match-p "^data:image/png;base64," path)
|
|
|
|
(org-download-dnd-base64 path nil))
|
2018-03-22 08:14:03 -04:00
|
|
|
((image-type-from-file-name raw-uri)
|
|
|
|
(org-download-image raw-uri))
|
2019-12-29 16:31:25 -05:00
|
|
|
((let ((new-path (expand-file-name (org-download--fullname raw-uri))))
|
2018-03-22 08:14:03 -04:00
|
|
|
;; Download the file
|
2019-12-29 16:31:25 -05:00
|
|
|
(if (string-match-p (concat "^" (regexp-opt '("http" "https" "nfs" "ftp" "file")) ":/") path)
|
2018-03-22 08:14:03 -04:00
|
|
|
(url-copy-file raw-uri new-path)
|
2019-12-29 16:31:25 -05:00
|
|
|
(copy-file path new-path))
|
2018-03-22 08:14:03 -04:00
|
|
|
;; insert the link
|
2019-12-29 16:31:25 -05:00
|
|
|
(org-download-insert-link raw-uri new-path)))))
|
|
|
|
(error
|
2020-04-25 01:27:25 -04:00
|
|
|
(user-error "Failed to attach file: %s" (error-message-string e)))))
|