summaryrefslogtreecommitdiffhomepage
path: root/lib/doc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/doc')
-rw-r--r--lib/doc/jao-devon.el55
-rw-r--r--lib/doc/jao-org-links.el2
-rw-r--r--lib/doc/jao-pdf.el24
3 files changed, 68 insertions, 13 deletions
diff --git a/lib/doc/jao-devon.el b/lib/doc/jao-devon.el
new file mode 100644
index 0000000..489307e
--- /dev/null
+++ b/lib/doc/jao-devon.el
@@ -0,0 +1,55 @@
+;;; jao-devon.el --- Utilities to interact with devonthink -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2025 Jose Antonio Ortega Ruiz
+
+;; Author: Jose Antonio Ortega Ruiz <mail@jao.io>
+;; Keywords: docs
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Searches and general scripting in devon.
+
+;;; Code:
+
+(defun jao-devon--do-applescript (script)
+ (let (start cmd return)
+ (while (string-match "\n" script)
+ (setq script (replace-match "\r" t t script)))
+ (while (string-match "'" script start)
+ (setq start (+ 2 (match-beginning 0))
+ script (replace-match "\\'" t t script)))
+ (setq cmd (concat "osascript -e '" script "'"))
+ (setq return (shell-command-to-string cmd))
+ (string-trim return)))
+
+(defun jao-devon-tell (&rest script-lines)
+ (let ((scpt (mapconcat 'identity
+ (append (cons "tell application id \"DNtp\""
+ script-lines)
+ '("end tell\n"))
+ "\n")))
+ (jao-devon--do-applescript scpt)))
+
+(defun jao-devon-find-url (file)
+ (jao-devon-tell
+ "repeat with db in databases"
+ (format "set res to lookup records with path %S in db" (file-truename file))
+ "if res /= {} then return the reference URL of (item 1 of res)"
+ "end repeat"
+ "return \"\""))
+
+(provide 'jao-devon)
+;;; jao-devon.el ends here
diff --git a/lib/doc/jao-org-links.el b/lib/doc/jao-org-links.el
index 88c0561..3f26650 100644
--- a/lib/doc/jao-org-links.el
+++ b/lib/doc/jao-org-links.el
@@ -17,7 +17,7 @@
(funcall (or jao-org-open-pdf-fun #'jao-org--default-open) path page height))
(defun jao-org-links--open-pdf (link)
- "Open LINK in pdf-view-mode."
+ "Open LINK using `jaor-org-open-pdf-fn'."
(cond ((string-match "\\(.*\\)::\\([0-9]*\\)\\+\\+\\([[0-9]\\.*[0-9]*\\)" link)
(let* ((path (match-string 1 link))
(page (string-to-number (match-string 2 link)))
diff --git a/lib/doc/jao-pdf.el b/lib/doc/jao-pdf.el
index 9bf0098..15e403a 100644
--- a/lib/doc/jao-pdf.el
+++ b/lib/doc/jao-pdf.el
@@ -108,18 +108,18 @@
;;; DevonThink
-(defun jao-pdf--devon-link (file)
- (jao-shell-string "osascript"
- (expand-file-name "find-devon-url.scpt" jao-data-dir)
- (file-truename file)))
-
-(defun jao-pdf-open-in-devon (file &optional page height)
- (let ((url (jao-pdf--devon-link file)))
- (unless (string-empty-p (or url ""))
- (let* ((p (if page (format "?page=%s" (- page 1)) ""))
- (u (format "%s%s" url p)))
- (message "Opening %s ..." u)
- (jao-shell-exec* "open" u)))))
+(jao-when-darwin
+ (require 'jao-devon)
+
+ (defun jao-pdf-open-in-devon (file &optional page height)
+ (let ((url (jao-devon-find-url file)))
+ (if (string-empty-p (or url ""))
+ (let ((jao-browse-doc-use-emacs-p t))
+ (jao-find-or-open file page height))
+ (let* ((p (if page (format "?page=%s" (- page 1)) ""))
+ (u (format "%s%s" url p)))
+ (message "Opening %s ..." u)
+ (jao-shell-exec* t "open" u))))))
;;; Open doc functions