summaryrefslogtreecommitdiffhomepage
path: root/lib/doc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/doc')
-rw-r--r--lib/doc/jao-doc-session.el33
-rw-r--r--lib/doc/jao-doc-view.el27
-rw-r--r--lib/doc/jao-org-focus.el167
-rw-r--r--lib/doc/jao-org-links.el36
-rw-r--r--lib/doc/jao-org-notes.el90
-rw-r--r--lib/doc/jao-pdf.el35
-rw-r--r--lib/doc/jao-words.el80
7 files changed, 398 insertions, 70 deletions
diff --git a/lib/doc/jao-doc-session.el b/lib/doc/jao-doc-session.el
index 877a8cb..a846302 100644
--- a/lib/doc/jao-doc-session.el
+++ b/lib/doc/jao-doc-session.el
@@ -1,6 +1,6 @@
;;; jao-doc-session.el --- persistent document sessions -*- lexical-binding: t; -*-
-;; Copyright (C) 2022, 2024 jao
+;; Copyright (C) 2022, 2024, 2025, 2026 jao
;; Author: jao <mail@jao.io>
;; Keywords: docs
@@ -20,15 +20,20 @@
;;; Code:
-(persist-defvar jao-doc-session nil "Documents session")
+(require 'multisession)
-(defvar-local jao-doc-session--is-doc nil)
+(define-multisession-variable jao-doc--session nil)
+
+(defun jao-doc-session () (multisession-value jao-doc--session))
+
+(defvar-local jao-doc-session-is-doc nil
+ "Locally marks a buffer as belonging to a session.
+
+See also `jao-doc-session-mark'.")
(defun jao-doc-session-is-doc (&optional buffer)
"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)
+ (buffer-local-value 'jao-doc-session-is-doc (or buffer (current-buffer))))
(defun jao-doc-session-save (&optional skip-current force)
"Traverse all current buffers and update the value of `jao-doc-session'."
@@ -36,24 +41,24 @@
(let ((docs '())
(cb (and skip-current (current-buffer))))
(dolist (b (buffer-list))
- (when-let (fs (and (not (eq cb b)) (jao-doc-session-is-doc b)))
- (dolist (f fs) (add-to-list 'docs f))))
+ (when-let* ((fs (and (not (eq cb b)) (jao-doc-session-is-doc b)))
+ (fs (if (listp fs) fs (list (buffer-file-name b)))))
+ (dolist (f fs) (push f docs))))
(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."
- (unless (listp jao-doc-session--is-doc)
- (setq jao-doc-session--is-doc (ensure-list jao-doc-session--is-doc)))
- (cl-pushnew (or path (buffer-file-name)) jao-doc-session--is-doc)
+ (unless (listp jao-doc-session-is-doc)
+ (setq jao-doc-session-is-doc (ensure-list jao-doc-session-is-doc)))
+ (cl-pushnew (or path (buffer-file-name)) jao-doc-session-is-doc)
(jao-doc-session-save))
(defun jao-doc-session--maybe-save ()
(when (jao-doc-session-is-doc) (jao-doc-session-save t)))
-(defvar jao-doc-session-inhibit-save nil)
-
(add-hook 'kill-buffer-hook #'jao-doc-session--maybe-save)
+(add-hook 'kill-emacs-hook #'jao-doc-session-save)
(provide 'jao-doc-session)
;;; jao-doc-session.el ends here
diff --git a/lib/doc/jao-doc-view.el b/lib/doc/jao-doc-view.el
index fe26c1d..74c4751 100644
--- a/lib/doc/jao-doc-view.el
+++ b/lib/doc/jao-doc-view.el
@@ -1,6 +1,6 @@
;;; jao-doc-view.el -- extensions for doc-view -*- lexical-binding: t; -*-
-;; Copyright (c) 2013, 2015, 2017, 2018, 2019, 2021, 2022 Jose Antonio Ortega Ruiz
+;; Copyright (c) 2013, 2015, 2017, 2018, 2019, 2021, 2022, 2026 Jose Antonio Ortega Ruiz
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
@@ -18,9 +18,15 @@
;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org>
;; Start date: Fri Feb 15, 2013 01:21
+(require 'browse-url)
+(require 'thingatpt)
(require 'doc-view)
(require 'jao-pdf)
+(declare-function pdf-view-image-size "pdf-view")
+(declare-function pdf-view-goto-page "pdf-view")
+(declare-function pdf-view-current-page "pdf-view")
+
;;; Utilities
(defmacro jao-doc-view--funcall (a b &rest args)
@@ -39,8 +45,7 @@
;;; imenu
(defun jao-doc-view-enable-imenu (file-name goto-page)
- (let ((ifun (lambda () (doc-view-imenu-index file-name goto-page)))
- (doc-view-imenu-enabled t))
+ (let ((ifun (lambda () (doc-view-imenu-index file-name goto-page))))
(doc-view-imenu-setup)
(setq-local imenu-create-index-function ifun)))
@@ -48,21 +53,21 @@
(defvar-local jao-doc-view--trail-back ())
(defvar-local jao-doc-view--trail-fwd ())
-(defun jao-doc-view--trail-push (dest-page)
- (when-let (page (jao-doc-view-current-page))
+(defun jao-doc-view--trail-push (_dest-page)
+ (when-let* ((page (jao-doc-view-current-page)))
(unless (eq (car jao-doc-view--trail-back) page)
- (push page jao-doc-view--trail-back))))
+ (cl-pushnew page jao-doc-view--trail-back))))
(defun jao-doc-view-back ()
(interactive nil doc-view-mode)
- (if-let (p (pop jao-doc-view--trail-back))
- (progn (push (jao-doc-view-current-page) jao-doc-view--trail-fwd)
+ (if-let* ((p (pop jao-doc-view--trail-back)))
+ (progn (cl-pushnew (jao-doc-view-current-page) jao-doc-view--trail-fwd)
(jao-doc-view-goto-page p))
(message "No more back marks.")))
(defun jao-doc-view-forward ()
(interactive nil doc-view-mode)
- (if-let (p (pop jao-doc-view--trail-fwd))
+ (if-let* ((p (pop jao-doc-view--trail-fwd)))
(progn (push (jao-doc-view-current-page) jao-doc-view--trail-back)
(jao-doc-view-goto-page p))
(message "No more forward marks.")))
@@ -115,8 +120,8 @@
(cond ((eq 'wait urls) (message "Extracting text, please wait and retry."))
((zerop (length urls))
(message "No URLs in this %s" (if all "document" "page")))
- (t (when-let (url (completing-read "URL: " urls nil nil
- (when (null (cdr urls)) (car urls))))
+ (t (when-let* ((url (completing-read "URL: " urls nil nil
+ (when (null (cdr urls)) (car urls)))))
(browse-url url))))))
;;; .
diff --git a/lib/doc/jao-org-focus.el b/lib/doc/jao-org-focus.el
new file mode 100644
index 0000000..0d0b02b
--- /dev/null
+++ b/lib/doc/jao-org-focus.el
@@ -0,0 +1,167 @@
+;;; jao-org-focus.el --- focusing on org subtrees -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2025, 2026 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/>.
+
+(require 'org)
+(require 'cl-lib)
+
+(defvar-local jao-org-focus--parent nil)
+(defvar-local jao-org-focus--section nil)
+
+(defvar jao-org-focus-siblings '("escaleta.org" . "novela.org"))
+
+(defun jao-org-focus--header-title ()
+ (when-let* ((elem (org-element-at-point))
+ (header (if (eq 'headline (org-element-type elem))
+ elem
+ (org-previous-visible-heading 1)
+ (org-element-at-point))))
+ (org-element-property :title header)))
+
+(defun jao-org-focus--is-outline ()
+ (string= (car jao-org-focus-siblings)
+ (file-name-nondirectory (or (buffer-file-name) ""))))
+
+(defun jao-org-focus--jump-to-title (file title)
+ (let* ((file (if (bufferp file) (buffer-file-name file) file))
+ (link (format "[[%s::*%s]]" file title)))
+ (org-link-open-from-string link)))
+
+;;;###autoload
+(defun jao-org-focus-jump-to-sibling ()
+ (interactive)
+ (when-let* ((title (save-excursion (jao-org-focus--header-title)))
+ (file (if (jao-org-focus--is-outline)
+ (cdr jao-org-focus-siblings)
+ (car jao-org-focus-siblings)))
+ (link (format "[[./%s::*%s]]" file title)))
+ (jao-org-focus--jump-to-title (format "./%s" file) title)))
+
+;;; focus on subtree
+;;;###autoload
+(defun jao-org-focus ()
+ "Pop creatingly to an indirect buffer focused on the encloing subtree.
+
+When invoked on an indirect buffer, pops back to its base."
+ (interactive)
+ (when (jao-org-focus--is-outline)
+ (jao-org-focus-jump-to-sibling))
+ (if-let* ((b (get-buffer (or jao-org-focus--parent ""))))
+ (let ((title (save-excursion
+ (goto-char (point-min))
+ (jao-org-focus--header-title))))
+ (jao-org-focus--jump-to-title b title))
+ (when-let* ((title (jao-org-focus--header-title))
+ (parent (buffer-name))
+ (bname (format "%s [%s]" title parent)))
+ (if-let* ((b (get-buffer bname)))
+ (pop-to-buffer b)
+ (clone-indirect-buffer bname t)
+ (org-focus-mode -1)
+ (org-focus-child-mode)
+ (setq jao-org-focus--parent parent
+ jao-org-focus--section title)
+ (org-narrow-to-subtree)
+ (outline-show-subtree)
+ (count-words (point-min) (point-max))))))
+
+(defun jao-org-focus-redisplay ()
+ "Redisplay a focused buffer.
+
+Useful when its parent has been reorganised and the narrowing is out of
+sync."
+ (interactive)
+ (when-let* ((title jao-org-focus--section))
+ (widen)
+ (goto-char (point-min))
+ (when (re-search-forward (format "\\*+ %s" title) nil t)
+ (org-narrow-to-subtree)
+ (goto-char (point-min)))))
+
+(defun jao-org-focus-redisplay-children ()
+ "Find focused children and redisplay them."
+ (interactive)
+ (dolist (b (jao-org-focus-list))
+ (with-current-buffer b
+ (save-excursion (jao-org-focus-redisplay)))))
+
+(defun jao-org-focus-list (&optional any-parent exclude)
+ "List of buffers that are focusing on a subtree of this one or its parent."
+ (let ((n (or jao-org-focus--parent (buffer-name))))
+ (seq-filter (lambda (b)
+ (let ((p (buffer-local-value 'jao-org-focus--parent b)))
+ (and p
+ (or any-parent (string= n p))
+ (or (not exclude)
+ (not (string= (buffer-name b) exclude))))))
+ (buffer-list))))
+
+(defvar jao-org-focus--focused-history nil)
+
+;;;###autoload
+(defun jao-org-focus-switch (arg)
+ "Read with completion a focused child and pop to it.
+
+With arg, offer to switch to all children, regardless of their parent."
+ (interactive "P")
+ (let ((fl (mapcar 'buffer-name (jao-org-focus-list arg (buffer-name)))))
+ (unless fl (error "No focused children"))
+ (pop-to-buffer
+ (completing-read "Focused child: " fl
+ nil t nil 'jao-org-focus--focused-history))))
+
+;;;###autoload
+(defun jao-org-focus-goto-line (n)
+ (interactive "NGo to line: ")
+ (goto-char (point-min))
+ (forward-visible-line n))
+
+;;;###autoload
+(define-minor-mode org-focus-mode
+ "A mode where keeping track of focused children is on by default."
+ :lighter " ◎"
+ :keymap '(("\C-ce" . jao-org-focus-jump-to-sibling)
+ ("\C-cl" . jao-org-focus-switch)
+ ("\C-cR" . jao-org-focus-redisplay)
+ ("\C-co" . jao-org-focus)
+ ("\C-cw" . count-words))
+ (if org-focus-mode
+ (add-hook 'after-save-hook #'jao-org-focus-redisplay-children nil t)
+ (remove-hook 'after-save-hook #'jao-org-focus-redisplay-children t)))
+
+;;;###autoload
+(define-minor-mode org-focus-child-mode
+ "A mode for the children of a focused org buffer."
+ :lighter " ◉"
+ :keymap (let ((map (make-keymap)))
+ (suppress-keymap map)
+ (keymap-set map "<remap> <goto-line>" #'jao-org-focus-goto-line)
+ map)
+ (when (and org-focus-child-mode (require 'symbol-overlay nil t))
+ (face-remap-reset-base 'symbol-overlay-default-face)
+ (face-remap-add-relative 'symbol-overlay-default-face 'warning 'underline)
+ (symbol-overlay-mode 1)))
+
+(with-eval-after-load 'symbol-overlay
+ (keymap-set org-focus-mode-map "M-n" 'symbol-overlay-jump-next)
+ (keymap-set org-focus-mode-map "M-p" 'symbol-overlay-jump-prev))
+
+
+(provide 'jao-org-focus)
+;;; jao-org-focus.el ends here
diff --git a/lib/doc/jao-org-links.el b/lib/doc/jao-org-links.el
index 88c0561..1bd8709 100644
--- a/lib/doc/jao-org-links.el
+++ b/lib/doc/jao-org-links.el
@@ -1,9 +1,14 @@
;; -*- lexical-binding: t; -*-
+(require 'org)
+(require 'browse-url)
(require 'jao-org-notes)
(require 'jao-doc-view)
(require 'jao-doc-session)
(require 'jao-pdf)
+(require 'jao-afio)
+
+(declare-function jao-pdf-skim-org "jao-mac")
(defvar jao-org--sink-dir "./")
(defvar jao-org-open-pdf-fun #'jao-org--default-open)
@@ -17,8 +22,9 @@
(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."
- (cond ((string-match "\\(.*\\)::\\([0-9]*\\)\\+\\+\\([[0-9]\\.*[0-9]*\\)" link)
+ "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)))
(height (string-to-number (match-string 3 link))))
@@ -45,7 +51,7 @@
(defun jao-org-links--complete-doc (&optional arg)
(let ((default-directory jao-org--sink-dir))
(let ((f (replace-regexp-in-string "^file:" "doc:"
- (org-file-complete-link arg))))
+ (org-link-complete-file arg))))
(if (jao-pdf-is-pdf-file f)
(let ((page (read-from-minibuffer "Page: " "")))
(if (> (string-to-number page) 0)
@@ -101,25 +107,33 @@
(insert "\n#+startup: latexpreview\n\n"))
;;;###autoload
-(defun jao-org-pdf-goto-org (arg)
+(defun jao-org-pdf-goto-org (arg &optional file-name)
(interactive "P")
- (when (jao-pdf-is-pdf-file buffer-file-name)
- (let* ((file (jao-org-notes-find-for-pdf))
- (new (not (file-exists-p file)))
- (title (jao-pdf-title)))
- (when (or arg new) (org-store-link nil t))
+ (when (jao-pdf-is-pdf-file (or file-name buffer-file-name))
+ (let* ((file (jao-org-notes-find-for-pdf file-name))
+ (new (not (file-exists-p file))))
+ (if (and (not file-name) (or arg new))
+ (org-store-link nil t)
+ (when (fboundp 'jao-pdf-skim-org-link)
+ (when-let* ((lnk (jao-pdf-skim-org-link nil)))
+ (kill-new lnk))))
(find-file-other-window file)
(when new
- (jao-org-insert-doc-skeleton title)
+ (jao-org-insert-doc-skeleton (jao-pdf-title file-name))
(org-insert-link)))))
;;;###autoload
(defun jao-org-pdf-goto-org* () (interactive) (jao-org-pdf-goto-org t))
;;;###autoload
+(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)
- (if-let (f (jao-org-org-to-pdf-file))
+ (if-let* ((f (jao-org-org-to-pdf-file)))
(jao-org--pdf-open f nil)
(user-error "No PDF file associated with this buffer")))
diff --git a/lib/doc/jao-org-notes.el b/lib/doc/jao-org-notes.el
index 43b8c09..929ab66 100644
--- a/lib/doc/jao-org-notes.el
+++ b/lib/doc/jao-org-notes.el
@@ -1,6 +1,6 @@
;;; jao-org-notes.el --- A simple system for org note taking -*- lexical-binding: t; -*-
-;; Copyright (C) 2020, 2021, 2022, 2024 jao
+;; Copyright (C) 2020, 2021, 2022, 2024, 2025, 2026 jao
;; Author: jao <mail@jao.io>
;; Keywords: tools
@@ -35,7 +35,7 @@
(defun jao-org-notes--rg-cmd (rgx &rest args)
`("rg" "--null" "--line-buffered" "--color=never" "--max-columns=250"
- "--type=org" "--line-number" "--no-heading" "--smart-case"
+ "--type=org" "--line-number" "--no-heading" "--smart-case" "--follow"
,@args ,default-directory "-e" ,rgx))
(defun jao-org-notes--rg-title-or-tags (str)
@@ -45,7 +45,8 @@
(default-directory
(if (file-directory-p d) (expand-file-name d) default-directory))
(ts (mapconcat #'identity (split-string str "[:,]+" t) ":|"))
- (rgx (format "^#.(title: .*%s|(tags:.*(%s:)))" str ts)))
+ (s (mapconcat #'identity (cons str (split-string str nil t)) "|"))
+ (rgx (format "^#.(title: .*(%s)|(tags:.*(%s:)))" s ts)))
(jao-org-notes--rg-cmd rgx "-m" "2")))
(defun jao-org-notes--clean-match (m)
@@ -57,7 +58,11 @@
(string-to-number (cadr m))))
(defun jao-org-notes--matches (lines)
- (mapcar (lambda (l) (jao-org-notes--clean-match (split-string l "\0" t))) lines))
+ (seq-keep (lambda (l)
+ (let ((m (split-string (or l "") "\0" t)))
+ (when (and (car m) (cadr m))
+ (jao-org-notes--clean-match m))))
+ lines))
(defun jao-org-notes--grep-rx (rx &rest rg-args)
(let ((default-directory jao-org-notes-dir))
@@ -71,14 +76,15 @@
(and (string-match-p "^[^:]+ + :" m) "tags")
"titles"))
-(defun jao-org-notes--consult-rg (prompt &optional cat no-req cmd initial)
+(defun jao-org-notes--consult-rg (prompt &optional cat no-req initial)
(let ((default-directory (expand-file-name (or cat "") jao-org-notes-dir)))
(consult--read
- (consult--async-command #'jao-org-notes--rg-title-or-tags
- (consult--async-transform jao-org-notes--matches))
+ (consult--async-pipeline
+ (consult--process-collection #'jao-org-notes--rg-title-or-tags)
+ (consult--async-transform #'jao-org-notes--matches))
:prompt prompt
- :initial (consult--async-split-initial (or initial ""))
- :add-history (concat (consult--async-split-initial (thing-at-point 'symbol)))
+ :initial (or initial "")
+ :add-history (thing-at-point 'symbol)
:require-match (not no-req)
:category 'jao-org-notes-lookup
:group 'jao-org-notes--consult-group
@@ -87,7 +93,7 @@
:history '(:input jao-org-notes--grep-history))))
(defun jao-org-notes-cats ()
- (seq-difference (directory-files jao-org-notes-dir) '("." ".." "attic")))
+ (directory-files jao-org-notes-dir nil "^[^.]"))
(defun jao-org-notes--cat ()
(let* ((cat (completing-read "Top level category: " (jao-org-notes-cats))))
@@ -96,7 +102,7 @@
(defun jao-org-notes--insert-title (&optional title)
(let* ((cat (jao-org-notes--cat))
- (note (jao-org-notes--consult-rg "Title: " cat t nil title))
+ (note (jao-org-notes--consult-rg "Title: " cat t title))
(title (file-name-base note))
(title (replace-regexp-in-string "^#" "" title)))
(when (not (string-empty-p title))
@@ -117,7 +123,8 @@
(defvar jao-org-notes--tag-history nil)
(defun jao-org-notes--read-tags ()
- (let* ((tags (completing-read-multiple "Tags: " jao-org-notes--tags nil nil nil
+ (let* ((tags (completing-read-multiple "Tags: "
+ jao-org-notes--tags nil nil nil
'jao-org-notes--tag-history)))
(setq jao-org-notes--tags (seq-union jao-org-notes--tags tags #'string=))
tags))
@@ -137,40 +144,61 @@
(let* ((file-name (or file-name buffer-file-name))
(bn (file-name-base file-name))
(rx (format "%s\\.org$" (regexp-quote bn)))
- (pred (lambda () (string-prefix-p jao-org-notes-dir buffer-file-name))))
+ (pred (lambda ()
+ (string-prefix-p jao-org-notes-dir buffer-file-name))))
(save-some-buffers nil pred)
(or (car (directory-files-recursively jao-org-notes-dir rx))
(let* ((d (completing-read "Notes subdir: " (jao-org-notes-cats) nil t))
(d (file-name-as-directory d)))
(expand-file-name (concat d bn ".org") jao-org-notes-dir)))))
+;;;###autoload
(defun jao-org-notes-open ()
- "Search for a note file, matching tags and titles with completion."
+ "Search for a note file, matching tags and titles with completion.
+
+If the search string starts with a folder name followed by a
+slash (e.g. `emacs/foo'), the search is performed only in the given
+notes folder (when it exists).
+
+Search terms that start with a colon are interpreted as tags, and can
+appear in any order in the tags list.
+"
(interactive)
- (when-let (f (jao-org-notes--consult-rg "Search notes: "))
+ (when-let* ((f (jao-org-notes--consult-rg "Search tags and titles: ")))
(find-file f)))
+(defvar jao-org-notes-consult-ripgrep-args
+ (format "%s -L" consult-ripgrep-args))
+
+(defun jao-org-notes-consult-ripgrep (&optional ask initial)
+ "Search over notes in given notes categories (or all of them), using rg."
+ (interactive "P")
+ (let ((cat (when ask (completing-read "Category: " (jao-org-notes-cats))))
+ (consult-ripgrep-args jao-org-notes-consult-ripgrep-args))
+ (consult-ripgrep (expand-file-name (or cat "") jao-org-notes-dir) initial)))
+
+(defun jao-org-notes-consult-ripgrep-category (&optional initial)
+ "Search over notes in a given notes category."
+ (interactive "P")
+ (jao-org-notes-consult-ripgrep t initial))
+
(defun jao-org-notes-consult-tags ()
"Search for a note file, matching all tags with completion."
(interactive)
(let* ((tags (jao-org-notes--read-tags))
(init (concat "^..tags: " (mapconcat #'identity tags " "))))
- (consult-ripgrep jao-org-notes-dir init)))
-
-(defun jao-org-notes-consult-ripgrep (&optional initial cat)
- (interactive)
- (consult-ripgrep (expand-file-name (or cat "") jao-org-notes-dir) initial))
+ (jao-org-notes-consult-ripgrep init)))
-(defun jao-org-notes-create (&optional title)
+(defun jao-org-notes-create (&optional title ret-buffer)
"Create a new note file, matching tags and titles with completion."
(interactive)
(when (jao-org-notes--insert-title title)
- (org-insert-time-stamp (current-time) t t "#+date: " "\n")
(insert "#+tags: :"
(mapconcat #'identity (jao-org-notes--read-tags) ":")
- ":\n"))
+ ":\n")
+ (org-insert-time-stamp (current-time) t t "#+date: " "\n"))
(save-buffer)
- (current-buffer))
+ (if ret-buffer (current-buffer) (buffer-file-name)))
(defun jao-org-notes-backlinks ()
"Show a list of note files linking to the current one."
@@ -180,7 +208,7 @@
(file (completing-read "File: " res nil t nil))
(entry (assoc file res)))
(progn (find-file (cadr entry))
- (when-let (line (caddr entry)) (goto-line line)))
+ (when-let* ((line (caddr entry))) (goto-line line)))
(message "Nobody links here!")))
(defun jao-org-notes-insert-tags ()
@@ -191,7 +219,7 @@
(defun jao-org-notes-insert-link ()
"Select a note file (with completion) and insert a link to it."
(interactive)
- (when-let (f (jao-org-notes--consult-rg "Notes file: "))
+ (when-let* ((f (jao-org-notes--consult-rg "Notes file: ")))
(let ((rel-path (file-relative-name f default-directory))
(title (with-current-buffer (find-file-noselect f)
(save-excursion
@@ -204,15 +232,15 @@
(interactive)
(message "%d notes, %d tags in %s"
(length (jao-org-notes-list))
- (length jao-org--notes-tags)
+ (length jao-org-notes--tags)
jao-org-notes-dir))
;;;###autoload
(defun jao-org-notes-setup (mnemonic)
- "Set up the notes system, providing a mnemonic character for its org template."
- (setq org-capture-templates
- (add-to-list 'org-capture-templates (jao-org-notes--template mnemonic))
- jao-org-notes--tags (jao-org-notes-all-tags))
+ "Set up the notes system, providing a mnemonic char for its org template."
+ (require 'org-capture)
+ (add-to-list 'org-capture-templates (jao-org-notes--template mnemonic))
+ (setq jao-org-notes--tags (jao-org-notes-all-tags))
(when (fboundp 'org-capture-upgrade-templates)
(org-capture-upgrade-templates org-capture-templates)))
diff --git a/lib/doc/jao-pdf.el b/lib/doc/jao-pdf.el
index 1ee74bc..01334b1 100644
--- a/lib/doc/jao-pdf.el
+++ b/lib/doc/jao-pdf.el
@@ -1,6 +1,6 @@
;;; jao-pdf.el --- utilities for pdf files -*- lexical-binding: t; -*-
-;; Copyright (C) 2022 jao
+;; Copyright (C) 2022, 2025, 2026 jao
;; Author: jao <mail@jao.io>
;; Keywords: docs
@@ -27,10 +27,14 @@
;; - Interoperability with zathura.
(require 'jao-doc-session)
+(require 'browse-url)
;;; PDF info
(declare-function 'pdf-info-outline "pdf-info")
+(defvar jao-pdf-org-dir nil)
+
+(defun jao-pdf-org-dir () jao-pdf-org-dir)
(defvar-local jao-pdf--outline nil)
@@ -56,7 +60,7 @@
(setq-local jao-pdf--outline (doc-view--pdf-outline file-name)))
(let ((page (or page
(and (derived-mode-p 'doc-view-mode) (doc-view-current-page))
- (and (derived-mode-p 'pdf-view) (pdf-view-current-page))))
+ (and (fboundp 'pdf-view-current-page) (pdf-view-current-page))))
(outline jao-pdf--outline)
(cur-page 0)
(cur-title (jao-pdf-title (or file-name buffer-file-name "title"))))
@@ -91,10 +95,35 @@
(fn (file-name-nondirectory file))
(lnk (format "doc:%s::%s" fn page))
(desc (format "%s (p. %s)" (jao-pdf-section-title page file) no)))
- (org-make-link-string lnk desc)))
+ (org-link-make-string lnk desc)))
(defun jao-pdf-zathura-org-link (title)
(jao-pdf--zathura-link (jao-pdf-zathura-file-info title)))
+;;; Open doc functions
+(defvar jao-pdf-open-in-emacs t)
+
+(defun jao-open-doc (&optional file page height)
+ (interactive)
+ (when-let* ((file (or file
+ (read-file-name "Document: "
+ (concat (jao-pdf-org-dir) "/doc/")))))
+ (funcall jao-open-doc-fun file page height)))
+
+;;; doc:// links for browse-url
+
+(defun jao-open-doc-url (url &rest _)
+ (when (string-match "doc://\\([^?]+\\)\\(\\?.*\\)?" url)
+ (let ((file (match-string 1 url))
+ (page (when-let* ((qs (match-string 2 url))
+ (long (> (length qs) 1))
+ (ps (url-parse-query-string (substring qs 1)))
+ (pn (cadr (assoc "page" ps))))
+ (string-to-number pn))))
+ (jao-open-doc (expand-file-name (concat "doc/" file) jao-org-dir) page))))
+
+(add-to-list 'browse-url-handlers (cons "^doc://.+" 'jao-open-doc-url))
+
+
(provide 'jao-pdf)
;;; jao-pdf.el ends here
diff --git a/lib/doc/jao-words.el b/lib/doc/jao-words.el
new file mode 100644
index 0000000..5d5111d
--- /dev/null
+++ b/lib/doc/jao-words.el
@@ -0,0 +1,80 @@
+;;; jao-words.el --- utilities for word stats -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2026 Jose Antonio Ortega Ruiz
+
+;; Author: Jose Antonio Ortega Ruiz <mail@jao.io>
+;; Keywords: text
+
+;; 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:
+
+;; Simple word counting and classification
+
+;;; Code:
+
+(require 'org)
+(require 'cl-lib)
+
+(defvar jao-words-min-length 3)
+(defvar jao-words-max-lines 12)
+(defvar jao-words-min-line-distance 10)
+
+(defun jao-words--word-lines (buffer word)
+ (let ((lines nil)
+ (last-line nil)
+ (case-fold-search nil)
+ (rx (format "\\b%s\\b" (regexp-quote word))))
+ (with-current-buffer buffer
+ (save-excursion
+ (goto-char (point-min))
+ (while (and (< (length lines) jao-words-max-lines)
+ (re-search-forward rx nil t))
+ (let* ((line (line-number-at-pos))
+ (d (- line (or last-line line))))
+ (when (< d jao-words-min-line-distance)
+ (when last-line
+ (cl-pushnew last-line lines)
+ (cl-pushnew line lines)))
+ (setq last-line line)))))
+ (mapconcat #'number-to-string (nreverse lines) " ")))
+
+;;;###autoload
+(defun jao-words-show-stats ()
+ (interactive)
+ (let ((counts (make-hash-table :test 'equal))
+ (buffer (current-buffer)))
+ (seq-each (lambda (word)
+ (when (>= (length word) jao-words-min-length)
+ (puthash word (1+ (gethash word counts 0)) counts)))
+ (split-string (downcase (buffer-string)) "\\W+" t))
+ (with-current-buffer (get-buffer-create "*word-statistics*")
+ (erase-buffer)
+ (insert "| word | occurences | lines |
+ |-----------+------------|--------------------|\n")
+ (maphash (lambda (word count)
+ (let ((lines (jao-words--word-lines buffer word)))
+ (insert (format "| %s | %d | %s |\n" word count lines))))
+ counts)
+ (org-mode)
+ (org-table-goto-line 2)
+ (org-table-goto-column 2)
+ (org-table-sort-lines nil ?N)
+ (org-table-align)
+ (org-table-goto-line 2)))
+ (pop-to-buffer "*word-statistics*"))
+
+
+(provide 'jao-words)
+;;; jao-words.el ends here