mirror of
https://github.com/doomemacs/doomemacs
synced 2025-09-08 15:23:35 -05:00
Move lang/org => org/*
Since lang/org has grown (and is expected to grow much, much more), it has been given its own module category. Concerns #129, #138
This commit is contained in:
33
modules/org/org-attach/autoload/evil.el
Normal file
33
modules/org/org-attach/autoload/evil.el
Normal file
@@ -0,0 +1,33 @@
|
||||
;;; org/org-attach/autoload/evil.el -*- lexical-binding: t; -*-
|
||||
|
||||
;;;###autoload (autoload '+org-attach:dwim "org/org-attach/autoload/evil" nil t)
|
||||
(evil-define-command +org-attach:dwim (&optional uri)
|
||||
"An evil ex interface to `+org-attach/dwim'."
|
||||
(interactive "<a>")
|
||||
(unless (eq major-mode 'org-mode)
|
||||
(user-error "Not in an org-mode buffer"))
|
||||
(if uri
|
||||
(let* ((rel-path (org-download--fullname uri))
|
||||
(new-path (expand-file-name rel-path))
|
||||
(image-p (image-type-from-file-name uri)))
|
||||
(cond ((string-match-p (concat "^" (regexp-opt '("http" "https" "nfs" "ftp" "file")) ":/") uri)
|
||||
(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))
|
||||
" " (org-attach--icon rel-path)))
|
||||
|
||||
(insert (if image-p
|
||||
(format "[[./%s]] " rel-path)
|
||||
(format "%s [[./%s][%s]] "
|
||||
(org-attach--icon rel-path)
|
||||
rel-path (file-name-nondirectory (directory-file-name rel-path))))))
|
||||
(when (string-match-p (regexp-opt '("jpg" "jpeg" "gif" "png")) (file-name-extension rel-path))
|
||||
(org-redisplay-inline-images)))
|
||||
(let ((default-directory ".attach/"))
|
||||
(if (file-exists-p default-directory)
|
||||
(call-interactively 'find-file)
|
||||
(user-error "No attachments")))))
|
55
modules/org/org-attach/autoload/org-attach.el
Normal file
55
modules/org/org-attach/autoload/org-attach.el
Normal file
@@ -0,0 +1,55 @@
|
||||
;;; org/org-attach/autoload/org-attach.el -*- lexical-binding: t; -*-
|
||||
|
||||
(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") ?)
|
||||
(_ ?))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-attach-cleanup ()
|
||||
;; "Deletes any attachments that are no longer present in the org-mode buffer."
|
||||
(let* ((attachments-local (+org-attachments))
|
||||
(attachments (directory-files org-attach-directory t "^[^.]" t))
|
||||
(to-delete (cl-set-difference attachments-local attachments)))
|
||||
;; TODO
|
||||
to-delete))
|
||||
|
||||
(defun +org-attachments ()
|
||||
"List all attachments in the current buffer."
|
||||
(unless (eq major-mode 'org-mode)
|
||||
(user-error "Not an org buffer"))
|
||||
(org-save-outline-visibility nil
|
||||
(let ((attachments '())
|
||||
element)
|
||||
(when (and (file-directory-p org-attach-directory)
|
||||
(> (length (file-expand-wildcards (expand-file-name "*" org-attach-directory))) 0))
|
||||
(save-excursion
|
||||
(goto-char (point-min))
|
||||
(while (progn (org-next-link) (not org-link-search-failed))
|
||||
(setq element (org-element-context))
|
||||
(when-let (file (and (eq (org-element-type element) 'link)
|
||||
(expand-file-name (org-element-property :path element))))
|
||||
(when (and (string= (org-element-property :type element) "file")
|
||||
(string= (concat (file-name-base (directory-file-name (file-name-directory file))) "/")
|
||||
org-attach-directory)
|
||||
(file-exists-p file))
|
||||
(push file attachments))))))
|
||||
(cl-remove-duplicates attachments))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-attach-download-dnd (uri action)
|
||||
(if (eq major-mode 'org-mode)
|
||||
(doom:org-attach uri) ;; FIXME
|
||||
(let ((dnd-protocol-alist
|
||||
(rassq-delete-all '+org-attach-download-dnd
|
||||
(copy-alist dnd-protocol-alist))))
|
||||
(dnd-handle-one-url nil action uri))))
|
||||
|
49
modules/org/org-attach/config.el
Normal file
49
modules/org/org-attach/config.el
Normal file
@@ -0,0 +1,49 @@
|
||||
;;; org/org-attach/config.el -*- lexical-binding: t; -*-
|
||||
|
||||
(defvar +org-attach-dir (expand-file-name ".attach/" +org-dir)
|
||||
"Where to store attachments (relative to current org file).")
|
||||
|
||||
|
||||
(add-hook '+org-init-hook #'+org|init-attach t)
|
||||
|
||||
;; FIXME This module is broken and needs to be rewritten.
|
||||
;;
|
||||
;; I believe Org's native attachment system is over-complicated and litters
|
||||
;; files with metadata I don't want.
|
||||
;;
|
||||
;; This installs my own attachment system. It:
|
||||
;;
|
||||
;; + Centralizes attachment in a global location,
|
||||
;; + Adds drag-and-drop file support
|
||||
;; + TODO ...with attachment icons, and
|
||||
;; + TODO Offers an attachment management system.
|
||||
|
||||
(def-package! org-download
|
||||
:config
|
||||
(setq-default org-download-image-dir +org-attach-dir
|
||||
org-download-heading-lvl nil
|
||||
org-download-timestamp "_%Y%m%d_%H%M%S")
|
||||
(setq org-download-screenshot-method
|
||||
(cond (IS-MAC "screencapture -i %s")
|
||||
(IS-LINUX "maim --opengl -s %s")))
|
||||
|
||||
;; Write download paths relative to current file
|
||||
(defun +org-attach*download-fullname (path)
|
||||
(file-relative-name path (file-name-directory (buffer-file-name))))
|
||||
(advice-add #'org-download--dir-2 :override #'ignore)
|
||||
(advice-add #'org-download--fullname
|
||||
:filter-return #'+org-attach*download-fullname))
|
||||
|
||||
;;
|
||||
(defun +org-attach|init ()
|
||||
(setq org-attach-directory +org-attach-directory)
|
||||
|
||||
(push ".attach" projectile-globally-ignored-file-suffixes)
|
||||
(after! recentf
|
||||
(push (format "/%s.+$" (regexp-quote +org-attach-dir))
|
||||
recentf-exclude))
|
||||
|
||||
(require 'org-download)
|
||||
|
||||
;; Add another drag-and-drop handler that will handle anything but image files
|
||||
(push '("^\\(https?\\|ftp\\|file\\|nfs\\):\\(//\\)?" . +org-attach-download-dnd) dnd-protocol-alist))
|
4
modules/org/org-attach/packages.el
Normal file
4
modules/org/org-attach/packages.el
Normal file
@@ -0,0 +1,4 @@
|
||||
;; -*- no-byte-compile: t; -*-
|
||||
;;; org/org-attach/packages.el
|
||||
|
||||
(package! org-download)
|
Reference in New Issue
Block a user