2016-08-21 16:53:38 +02:00
|
|
|
;;; defuns-org-notes.el
|
2016-03-01 01:59:36 -05:00
|
|
|
|
|
|
|
;;;###autoload
|
2016-05-20 22:37:30 -04:00
|
|
|
(defun doom/org ()
|
2016-03-01 01:59:36 -05:00
|
|
|
(interactive)
|
2016-05-12 02:40:01 -04:00
|
|
|
(find-file (f-expand "inbox.org" org-directory)))
|
2016-03-01 01:59:36 -05:00
|
|
|
|
|
|
|
;;;###autoload
|
2016-05-20 22:37:30 -04:00
|
|
|
(defun doom/org-notebook-new ()
|
2016-03-01 01:59:36 -05:00
|
|
|
(interactive)
|
|
|
|
(projectile-invalidate-cache nil)
|
|
|
|
(let* ((default-directory org-directory)
|
|
|
|
(dir (projectile-complete-dir))
|
2016-05-20 22:37:30 -04:00
|
|
|
(doom-org-quicknote-dir dir))
|
2016-03-01 01:59:36 -05:00
|
|
|
(when dir
|
2016-05-20 22:37:30 -04:00
|
|
|
(doom/org-notebook-quick-note))))
|
2016-03-01 01:59:36 -05:00
|
|
|
|
|
|
|
;;;###autoload
|
2016-05-20 22:37:30 -04:00
|
|
|
(defun doom/org-notebook-quick-note ()
|
2016-03-01 01:59:36 -05:00
|
|
|
(interactive)
|
|
|
|
(let (text)
|
|
|
|
(when (evil-visual-state-p)
|
|
|
|
(setq text (buffer-substring-no-properties evil-visual-beginning evil-visual-end)))
|
|
|
|
(switch-to-buffer (generate-new-buffer "*quick-note*"))
|
2016-05-20 22:37:30 -04:00
|
|
|
(setq default-directory doom-org-quicknote-dir)
|
2016-03-01 01:59:36 -05:00
|
|
|
(erase-buffer)
|
|
|
|
(insert text)))
|
|
|
|
|
|
|
|
;;;###autoload
|
2016-05-20 22:37:30 -04:00
|
|
|
(defun doom/org-download-dnd (uri action)
|
2016-03-06 22:54:04 -05:00
|
|
|
(if (eq major-mode 'org-mode)
|
2016-05-20 22:37:30 -04:00
|
|
|
(doom:org-attach uri)
|
2016-03-01 01:59:36 -05:00
|
|
|
(let ((dnd-protocol-alist
|
2016-05-20 22:37:30 -04:00
|
|
|
(rassq-delete-all 'doom/org-download-dnd (copy-alist dnd-protocol-alist))))
|
2016-03-01 01:59:36 -05:00
|
|
|
(dnd-handle-one-url nil action uri))))
|
|
|
|
|
2016-08-21 16:53:38 +02:00
|
|
|
;;;###autoload (autoload 'doom:org-attach "defuns-org-notes" nil t)
|
2016-05-20 22:37:30 -04:00
|
|
|
(evil-define-command doom:org-attach (&optional uri)
|
2016-03-01 01:59:36 -05:00
|
|
|
(interactive "<a>")
|
2016-03-11 19:28:24 -05:00
|
|
|
(unless (eq major-mode 'org-mode)
|
|
|
|
(user-error "Not in an org-mode buffer"))
|
2016-03-01 01:59:36 -05:00
|
|
|
(if uri
|
|
|
|
(let* ((rel-path (org-download--fullname uri))
|
2016-03-06 22:54:04 -05:00
|
|
|
(new-path (f-expand rel-path))
|
|
|
|
(image-p (image-type-from-file-name uri)))
|
|
|
|
(cond ((string-match-p (concat "^" (regexp-opt '("http" "https" "nfs" "ftp" "file")) ":/") uri)
|
2016-03-01 01:59:36 -05:00
|
|
|
(url-copy-file uri new-path))
|
|
|
|
(t (copy-file uri new-path)))
|
|
|
|
(unless new-path
|
|
|
|
(user-error "No file was provided"))
|
|
|
|
(if (evil-visual-state-p)
|
|
|
|
(org-insert-link nil (format "./%s" rel-path)
|
|
|
|
(concat (buffer-substring-no-properties (region-beginning) (region-end))
|
2016-08-21 16:53:38 +02:00
|
|
|
" " (doom--org-attach-icon rel-path)))
|
2016-03-06 22:54:04 -05:00
|
|
|
|
|
|
|
(insert (if image-p
|
2016-08-21 16:53:38 +02:00
|
|
|
(format "[[./%s]] " rel-path)
|
|
|
|
(format "%s [[./%s][%s]] "
|
|
|
|
(doom--org-attach-icon rel-path)
|
2016-03-06 22:54:04 -05:00
|
|
|
rel-path (f-filename rel-path)))))
|
2016-03-01 01:59:36 -05:00
|
|
|
(when (string-match-p (regexp-opt '("jpg" "jpeg" "gif" "png")) (f-ext rel-path))
|
2016-08-21 16:53:38 +02:00
|
|
|
(org-redisplay-inline-images)))
|
|
|
|
(let ((default-directory ".attach/"))
|
|
|
|
(if (file-exists-p default-directory)
|
|
|
|
(call-interactively 'find-file)
|
|
|
|
(user-error "No attachments")))))
|
2016-03-01 01:59:36 -05:00
|
|
|
|
2016-08-21 16:53:38 +02:00
|
|
|
(defun doom--org-attach-icon (path)
|
2016-03-01 01:59:36 -05:00
|
|
|
(char-to-string (pcase (downcase (f-ext path))
|
|
|
|
("jpg" ?) ("jpeg" ?) ("png" ?) ("gif" ?)
|
|
|
|
("pdf" ?)
|
|
|
|
("ppt" ?) ("pptx" ?)
|
|
|
|
("xls" ?) ("xlsx" ?)
|
|
|
|
("doc" ?) ("docx" ?)
|
|
|
|
("ogg" ?) ("mp3" ?) ("wav" ?)
|
|
|
|
("mp4" ?) ("mov" ?) ("avi" ?)
|
|
|
|
("zip" ?) ("gz" ?) ("tar" ?) ("7z" ?) ("rar" ?)
|
2016-08-21 16:53:38 +02:00
|
|
|
(_ ?))))
|
2016-03-01 01:59:36 -05:00
|
|
|
|
|
|
|
;;;###autoload
|
2016-08-21 16:53:38 +02:00
|
|
|
(defun doom/org-cleanup-attachments ()
|
|
|
|
;; "Deletes any attachments that are no longer present in the org-mode buffer."
|
|
|
|
(let* ((attachments-local (doom-org-attachments))
|
|
|
|
(attachments (f-entries org-attach-directory))
|
|
|
|
(to-delete (-difference attachments-local attachments)))
|
|
|
|
;; TODO
|
|
|
|
to-delete))
|
|
|
|
|
|
|
|
(defun doom-org-attachments ()
|
|
|
|
(unless (eq major-mode 'org-mode)
|
|
|
|
(user-error "Not an org buffer"))
|
2016-03-06 22:54:04 -05:00
|
|
|
(org-save-outline-visibility nil
|
|
|
|
(let ((attachments '())
|
|
|
|
element
|
|
|
|
file)
|
2016-03-11 19:28:24 -05:00
|
|
|
(when (and (f-dir? org-attach-directory)
|
|
|
|
(> (length (f-glob (concat (f-slash org-attach-directory) "*"))) 0))
|
2016-03-06 22:54:04 -05:00
|
|
|
(save-excursion
|
|
|
|
(goto-char (point-min))
|
|
|
|
(while (progn (org-next-link) (not org-link-search-failed))
|
|
|
|
(setq element (org-element-lineage (org-element-context) '(link) t))
|
|
|
|
(when element
|
|
|
|
(setq file (expand-file-name (org-element-property :path element)))
|
|
|
|
(when (and (string= (org-element-property :type element) "file")
|
|
|
|
(string= (concat (f-base (f-dirname file)) "/") org-attach-directory)
|
|
|
|
(file-exists-p file))
|
|
|
|
(push file attachments))))))
|
|
|
|
(-distinct attachments))))
|
2016-03-01 01:59:36 -05:00
|
|
|
|
2016-03-10 23:55:40 -05:00
|
|
|
|
2016-08-21 16:53:38 +02:00
|
|
|
(provide 'defuns-org-notes)
|
|
|
|
;;; defuns-org-notes.el ends here
|