summaryrefslogtreecommitdiffhomepage
path: root/lib/doc
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2026-06-26 19:51:07 +0100
committerjao <jao@gnu.org>2026-06-26 19:52:44 +0100
commit049453597ec1324ff19da2c95cb0ca02448eb806 (patch)
treea83d2a42ceb715f0604657343038b6873f1db7b5 /lib/doc
parente7a033d37898567915d41266daa903b3c48a11f5 (diff)
downloadelibs-049453597ec1324ff19da2c95cb0ca02448eb806.tar.gz
elibs-049453597ec1324ff19da2c95cb0ca02448eb806.tar.bz2
jao-org-focus improvements, jao-words
Diffstat (limited to 'lib/doc')
-rw-r--r--lib/doc/jao-org-focus.el81
-rw-r--r--lib/doc/jao-words.el77
2 files changed, 94 insertions, 64 deletions
diff --git a/lib/doc/jao-org-focus.el b/lib/doc/jao-org-focus.el
index 6fff238..c506f07 100644
--- a/lib/doc/jao-org-focus.el
+++ b/lib/doc/jao-org-focus.el
@@ -38,6 +38,11 @@
(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)))
+
(defun jao-org-focus-jump-to-sibling ()
(interactive)
(when-let* ((title (save-excursion (jao-org-focus--header-title)))
@@ -45,7 +50,7 @@
(cdr jao-org-focus-siblings)
(car jao-org-focus-siblings)))
(link (format "[[./%s::*%s]]" file title)))
- (org-link-open-from-string link)))
+ (jao-org-focus--jump-to-title (format "./%s" file) title)))
;;; focus on subtree
(defun jao-org-focus ()
@@ -56,7 +61,10 @@ When invoked on an indirect buffer, pops back to its base."
(when (jao-org-focus--is-outline)
(jao-org-focus-jump-to-sibling))
(if-let* ((b (get-buffer (or jao-org-focus--parent ""))))
- (pop-to-buffer b)
+ (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)))
@@ -91,12 +99,15 @@ sync."
(with-current-buffer b
(save-excursion (jao-org-focus-redisplay)))))
-(defun jao-org-focus-list (&optional any-parent)
+(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)))))
+ (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)
@@ -106,69 +117,12 @@ sync."
With arg, offer to switch to all children, regardless of their parent."
(interactive "P")
- (let ((fl (mapcar 'buffer-name (jao-org-focus-list arg))))
+ (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))))
-(defun jao-org-focus--count-words (raw-word-list)
- (cl-loop with result = nil
- for elt in raw-word-list
- do (cl-incf (cdr (or (assoc elt result)
- (first (push (cons elt 0) result)))))
- finally return (sort result
- (lambda (a b) (string< (car a) (car b))))))
-
-(defun jao-org-focus--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 (re-search-forward rx nil t) (< (length lines) 12))
- (let* ((line (line-number-at-pos))
- (d (- line (or last-line line))))
- (when (<= d 10)
- (when last-line
- (push last-line lines)
- (push line lines)))
- (setq last-line (line-number-at-pos))))))
- (mapconcat #'number-to-string (nreverse lines) " ")))
-
-(defun jao-org-focus-word-stats ()
- (interactive)
- (let* ((words (split-string (downcase (buffer-string)) "\\W+" t))
- (word-list (jao-org-focus--count-words words))
- (buffer (current-buffer)))
- (with-current-buffer (get-buffer-create "*word-statistics*")
- (erase-buffer)
- (insert "| word | occurences | lines |
- |-----------+------------|--------------------|\n")
- (dolist (elt word-list)
- (let* ((word (car elt))
- (count (cdr elt))
- (lines (jao-org-focus--word-lines buffer word)))
- (insert (format "| %s | %d | %s |\n" word count lines))))
- (org-mode)
- (indent-region (point-min) (point-max))
- (goto-char 5)
- (next-line 2)
- (org-table-next-field)
- (org-table-sort-lines nil ?N)))
- (pop-to-buffer "*word-statistics*"))
-
-(defvar jao-org-focus-consult-buffer-source
- `(:name "Focus buffers"
- :category jao-org-focus-buffers
- :action switch-to-buffer
- :hidden t
- :narrow ,(cons ?o "focus")
- :history jao-org-focus--focused-history
- :items ,(lambda () (mapcar 'buffer-name (jao-org-focus-list t)))))
-
(define-minor-mode org-focus-mode
"A mode where keeping track of focused children is on by default."
:lighter " ◎"
@@ -176,8 +130,7 @@ With arg, offer to switch to all children, regardless of their parent."
("\C-cl" . jao-org-focus-switch)
("\C-cR" . jao-org-focus-redisplay)
("\C-co" . jao-org-focus)
- ("\C-cw" . count-words)
- ("\C-cW" . jao-org-focus-word-stats))
+ ("\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)))
diff --git a/lib/doc/jao-words.el b/lib/doc/jao-words.el
new file mode 100644
index 0000000..32baab8
--- /dev/null
+++ b/lib/doc/jao-words.el
@@ -0,0 +1,77 @@
+;;; 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:
+
+(defun jao-words--count-words (raw-word-list)
+ (cl-loop with result = nil
+ for elt in raw-word-list
+ do (cl-incf (cdr (or (assoc elt result)
+ (first (push (cons elt 0) result)))))
+ finally return (sort result
+ (lambda (a b) (string< (car a) (car b))))))
+
+(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 (re-search-forward rx nil t) (< (length lines) 12))
+ (let* ((line (line-number-at-pos))
+ (d (- line (or last-line line))))
+ (when (<= d 10)
+ (when last-line
+ (push last-line lines)
+ (push line lines)))
+ (setq last-line (line-number-at-pos))))))
+ (mapconcat #'number-to-string (nreverse lines) " ")))
+
+(defun jao-words-show-stats ()
+ (interactive)
+ (let* ((words (split-string (downcase (buffer-string)) "\\W+" t))
+ (word-list (jao-words--count-words words))
+ (buffer (current-buffer)))
+ (with-current-buffer (get-buffer-create "*word-statistics*")
+ (erase-buffer)
+ (insert "| word | occurences | lines |
+ |-----------+------------|--------------------|\n")
+ (dolist (elt word-list)
+ (let* ((word (car elt))
+ (count (cdr elt))
+ (lines (jao-words--word-lines buffer word)))
+ (insert (format "| %s | %d | %s |\n" word count lines))))
+ (org-mode)
+ (indent-region (point-min) (point-max))
+ (goto-char 5)
+ (next-line 2)
+ (org-table-next-field)
+ (org-table-sort-lines nil ?N)))
+ (pop-to-buffer "*word-statistics*"))
+
+
+(provide 'jao-words)
+;;; jao-words.el ends here