(require 'jao-org-utils) (require 'jao-org-pdfview) (jao-when-darwin (require 'jao-devon) (autoload 'jao-as-safari-doc "jao-applescript.el") (defun jao-org-insert-devon-link () (interactive) (insert (jao-devon-selection))) (defun jao-org-insert-safari-link () (interactive) (let ((ln (jao-as-safari-doc))) (when ln (jao-org-insert-link (car ln) (cdr ln))))) (org-add-link-type "x-devonthink-item" 'jao-devon-open 'identity) (define-key org-mode-map "\C-cd" 'jao-org-insert-devon-link) (define-key org-mode-map "\C-cs" 'jao-org-insert-safari-link)) (defvar jao-org--sink-dir "./") (defun jao-org-follow-doc (link) (let ((dest-path (concat "./doc/" (and (boundp 'docs-dir) (concat (symbol-name docs-dir) "/")) link))) (when (not (file-exists-p dest-path)) (let* ((sink-file (expand-file-name link jao-org--sink-dir)) (real-file (if (file-exists-p sink-file) sink-file (read-file-name "Import file: " jao-org--sink-dir link link)))) (shell-command (format "mv %s %s" real-file dest-path)))) (browse-url (format "file://%s" (expand-file-name dest-path))))) (defsubst jao-org--title->file (title) (concat (mapconcat 'downcase (split-string title nil t) "-") ".pdf")) (defun jao-org-insert-doc (title) (interactive "sDocument title: ") (insert (format "[[doc:%s][%s]]" (jao-org--title->file title) title))) (defun jao-org-links-setup (sink-dir) (org-add-link-type "doc" 'jao-org-follow-doc 'identity) (setq jao-org--sink-dir (file-name-as-directory sink-dir))) (provide 'jao-org-links)