diff options
| -rw-r--r-- | lib/doc/jao-org-focus.el | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/lib/doc/jao-org-focus.el b/lib/doc/jao-org-focus.el index 7a73029..39c1aa4 100644 --- a/lib/doc/jao-org-focus.el +++ b/lib/doc/jao-org-focus.el @@ -1,6 +1,6 @@ ;;; jao-org-focus.el --- focusing on org subtrees -*- lexical-binding: t; -*- -;; Copyright (C) 2025 Jose Antonio Ortega Ruiz +;; Copyright (C) 2025, 2026 Jose Antonio Ortega Ruiz ;; Author: Jose Antonio Ortega Ruiz <mail@jao.io> ;; Keywords: docs @@ -19,6 +19,7 @@ ;; 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) @@ -67,7 +68,8 @@ sync." "Find focused children and redisplay them." (interactive) (dolist (b (jao-org-focus-list)) - (with-current-buffer b (jao-org-focus-redisplay)))) + (with-current-buffer b + (save-excursion (jao-org-focus-redisplay))))) (defun jao-org-focus-list (&optional any-parent) "List of buffers that are focusing on a subtree of this one or its parent." @@ -90,6 +92,31 @@ With arg, offer to switch to all children, regardless of their parent." (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-stats () + (interactive) + (let* ((words (split-string (downcase (buffer-string)) "\\W+" t)) + (word-list (jao-org-focus--count-words words))) + (with-current-buffer (get-buffer-create "*word-statistics*") + (erase-buffer) + (insert "| word | occurences | + |-----------+------------|\n") + (dolist (elt word-list) + (insert (format "| %s | %d |\n" (car elt) (cdr elt)))) + (org-mode) + (indent-region (point-min) (point-max)) + (goto-char 100) + (org-cycle) + (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 @@ -105,7 +132,8 @@ With arg, offer to switch to all children, regardless of their parent." :keymap '(("\C-cl" . jao-org-focus-switch) ("\C-cR" . jao-org-focus-redisplay) ("\C-co" . jao-org-focus) - ("\C-cw" . count-words)) + ("\C-cw" . count-words) + ("\C-cW" . jao-org-focus-word-stats)) (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))) @@ -115,5 +143,6 @@ With arg, offer to switch to all children, regardless of their parent." :lighter " ◉" :keymap org-focus-mode-map) + (provide 'jao-org-focus) ;;; jao-org-focus.el ends here |
