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-doc-session.el8
-rw-r--r--lib/doc/jao-mac.el102
-rw-r--r--lib/doc/jao-org-links.el4
-rw-r--r--lib/doc/jao-pdf.el17
5 files changed, 113 insertions, 73 deletions
diff --git a/lib/doc/jao-devon.el b/lib/doc/jao-devon.el
deleted file mode 100644
index 489307e..0000000
--- a/lib/doc/jao-devon.el
+++ /dev/null
@@ -1,55 +0,0 @@
-;;; 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-doc-session.el b/lib/doc/jao-doc-session.el
index b54a942..d2076c1 100644
--- a/lib/doc/jao-doc-session.el
+++ b/lib/doc/jao-doc-session.el
@@ -20,7 +20,9 @@
;;; Code:
-(persist-defvar jao-doc-session nil "Documents session")
+(define-multisession-variable jao-doc--session nil)
+
+(defun jao-doc-session () (multisession-value jao-doc--session))
(defvar-local jao-doc-session-is-doc nil
"Setting this variable as t in a buffer will mark it as belonging to a session.
@@ -31,8 +33,6 @@ See also `jao-doc-session-mark'.")
"Check whether the given or current buffer belong to the doc session."
(buffer-local-value 'jao-doc-session-is-doc (or buffer (current-buffer))))
-(defun jao-doc-session (&optional file) jao-doc-session)
-
(defun jao-doc-session-save (&optional skip-current force)
"Traverse all current buffers and update the value of `jao-doc-session'."
(interactive)
@@ -43,7 +43,7 @@ See also `jao-doc-session-mark'.")
(fs (if (listp fs) fs (list (buffer-file-name b)))))
(dolist (f fs) (add-to-list 'docs f))))
(when (or force (> (length docs) 0))
- (setq jao-doc-session docs))))
+ (setf (multisession-value jao-doc--session) docs))))
(defun jao-doc-session-mark (&optional path)
"Mark the current buffer's file, or PATH, as persistent across sessions."
diff --git a/lib/doc/jao-mac.el b/lib/doc/jao-mac.el
new file mode 100644
index 0000000..f40ca10
--- /dev/null
+++ b/lib/doc/jao-mac.el
@@ -0,0 +1,102 @@
+;;; jao-mac.el --- Running applescript. -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2025 Jose Antonio Ortega Ruiz
+
+;; Author: Jose Antonio Ortega Ruiz <mail@jao.io>
+;; Keywords: lisp
+
+;; 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/>.
+
+(require 'jao-shell)
+
+;;; Applescript
+(defun jao-mac-run-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-mac-run-applescript* (&rest script-lines)
+ (jao-mac-run-applescript (mapconcat 'identity script-lines "\r")))
+
+(defun jao-mac-tell-app (app &rest script-lines)
+ (let* ((app-id (string-split app))
+ (id (if (> (length app-id) 1) (car app-id) ""))
+ (app (if (> (length app-id) 1) (cadr app-id) (car app-id)))
+ (pre (list (format "tell application %s %S" id app)))
+ (post '("end tell\n")))
+ (jao-mac-run-applescript* (append pre script-lines post))))
+
+;;; open
+
+(defun jao-mac-open (thing &rest args)
+ "Invoke open after formatting thing with args, using `format'"
+ (jao-shell-exec (format "open %s" (apply #'format thing args))))
+
+(defun jao-mac-open-in-skim (&optional file page height)
+ (interactive)
+ (let* ((file (if file (expand-file-name file) (buffer-file-name)))
+ (page (or page (and (derived-mode-p 'doc-view-mode)
+ (doc-view-current-page)))))
+ (jao-mac-open "skim://%s%s" file (if page (format "#page=%s" page) ""))))
+
+;; https://alvinalexander.com/macos/applescript-how-to-open-pdf-file-in-preview-go-to-page/
+;; This will work as long as Preview is the default app for the file at hand.
+(defun jao-mac-open-in-preview (&optional file page height)
+ (interactive)
+ (let ((file (if file (expand-file-name file) (buffer-file-name)))
+ (page (or page (and (derived-mode-p 'doc-view-doc)
+ (doc-view-current-page)))))
+ (jao-mac-run-applescript*
+ (format "tell application id \"com.apple.Preview\" to open (POSIX file %S)\r\r"
+ (file-truename file))
+ "delay 1"
+ "tell application \"System Events\""
+ "keystroke \"g\" using {option down, command down}"
+ (format "keystroke %s" (or page 1))
+ "delay 0.1\rkeystroke return\rend tell")))
+
+;;; DevonThink
+
+(defun jao-devon-tell (&rest script-lines)
+ (apply #'jao-mac-tell-app "id DNtp" script-lines ))
+
+(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 \"\""))
+
+(defun jao-devon-show-search (s)
+ (jao-devon-tell (format "show search %S" s) "activate"))
+
+(defun jao-devon-open (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)))
+ (jao-mac-open "%s%s" url p)))))
+
+(provide 'jao-mac)
+;;; jao-mac.el ends here
diff --git a/lib/doc/jao-org-links.el b/lib/doc/jao-org-links.el
index 3f26650..5f2304a 100644
--- a/lib/doc/jao-org-links.el
+++ b/lib/doc/jao-org-links.el
@@ -116,6 +116,10 @@
;;;###autoload
(defun jao-org-pdf-goto-org* () (interactive) (jao-org-pdf-goto-org t))
+(defun jao-org-org-to-pdf-file ()
+ (expand-file-name (concat "doc/" (file-name-base buffer-file-name) ".pdf")
+ (file-name-directory jao-org-notes-dir)))
+
;;;###autoload
(defun jao-org-goto-pdf ()
(interactive)
diff --git a/lib/doc/jao-pdf.el b/lib/doc/jao-pdf.el
index 15e403a..079beff 100644
--- a/lib/doc/jao-pdf.el
+++ b/lib/doc/jao-pdf.el
@@ -106,20 +106,9 @@
(cmd (format "xdotool windowactivate %s%s" id page)))
(jao-shell-exec cmd t)))))
-;;; DevonThink
+;;; Mac
-(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))))))
+(jao-when-darwin (require 'jao-mac))
;;; Open doc functions
@@ -147,7 +136,7 @@
(defun jao-select-pdf ()
(interactive)
- (jao-buffer-same-mode '(pdf-view-mode doc-view-mode)
+ (jao-buffer-same-mode '(pdf-view-mode doc-view-mode org-mode)
#'jao-afio-goto-docs))
(defun jao-open-with-zathura ()