From 5ee2ae03e7d835995fa20c12a316bf52795cedf5 Mon Sep 17 00:00:00 2001 From: jao Date: Mon, 28 Sep 2026 21:52:40 +0100 Subject: wee improvements --- custom/jao-custom-eww.el | 2 +- custom/jao-custom-org.el | 9 ++++++++ lib/doc/jao-org-focus.el | 12 ++++++++++- lib/doc/jao-words.el | 53 +++++++++++++++++++++++++----------------------- lib/eos/jao-buffers.el | 8 ++++++++ 5 files changed, 57 insertions(+), 27 deletions(-) diff --git a/custom/jao-custom-eww.el b/custom/jao-custom-eww.el index 1b9eb9b..2dc0d0a 100644 --- a/custom/jao-custom-eww.el +++ b/custom/jao-custom-eww.el @@ -183,7 +183,7 @@ (shr-blocked-images nil) (shr-inhibit-images t) (shr-max-image-proportion 0.8) - (shr-sliced-image-height 0.7) + (shr-sliced-image-height 0.2) (shr-hr-line ?―))) (use-package eww diff --git a/custom/jao-custom-org.el b/custom/jao-custom-org.el index a0b1b8b..7e84e76 100644 --- a/custom/jao-custom-org.el +++ b/custom/jao-custom-org.el @@ -362,6 +362,15 @@ (use-package jao-words :commands (jao-words-show-stats)) +(use-package org-wc :ensure t) + +(defun jao-org-num-format-roman (numbers) + (if (> (length numbers) 1) + "" + (format "%s " (org-export-number-to-roman (car numbers))))) + +;; (setq org-num-format-function #'jao-org-num-format-roman) + ;;; Keybindings (define-key mode-specific-map [?a] 'org-agenda) (define-key org-mode-map "\C-cv" 'jao-org-copy-link-at-point) diff --git a/lib/doc/jao-org-focus.el b/lib/doc/jao-org-focus.el index a8d72be..859cb65 100644 --- a/lib/doc/jao-org-focus.el +++ b/lib/doc/jao-org-focus.el @@ -124,6 +124,11 @@ 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-goto-line (n) + (interactive "NGo to line: ") + (goto-char (point-min)) + (forward-visible-line n)) + (define-minor-mode org-focus-mode "A mode where keeping track of focused children is on by default." :lighter " ◎" @@ -139,12 +144,17 @@ With arg, offer to switch to all children, regardless of their parent." (define-minor-mode org-focus-child-mode "A mode for the children of a focused org buffer." :lighter " ◉" - :keymap org-focus-mode-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))) +(set-keymap-parent org-focus-child-mode-map org-focus-mode) +(keymap-set org-focus-child-mode-map + " " + #'jao-org-focus-goto-line) + + (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)) diff --git a/lib/doc/jao-words.el b/lib/doc/jao-words.el index 52e5093..5d5111d 100644 --- a/lib/doc/jao-words.el +++ b/lib/doc/jao-words.el @@ -24,13 +24,12 @@ ;;; 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) - (car (push (cons elt 0) result))))) - finally return (sort result - (lambda (a b) (string< (car a) (car b)))))) +(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) @@ -40,36 +39,40 @@ (with-current-buffer buffer (save-excursion (goto-char (point-min)) - (while (and (re-search-forward rx nil t) (< (length lines) 12)) + (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 10) + (when (< d jao-words-min-line-distance) (when last-line - (push last-line lines) - (push line lines))) - (setq last-line (line-number-at-pos)))))) + (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* ((words (split-string (downcase (buffer-string)) "\\W+" t)) - (word-list (jao-words--count-words words)) - (buffer (current-buffer))) + (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") - (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)))) + (maphash (lambda (word count) + (let ((lines (jao-words--word-lines buffer word))) + (insert (format "| %s | %d | %s |\n" word count lines)))) + counts) (org-mode) - (indent-region (point-min) (point-max)) - (goto-char 5) - (forward-line 2) - (org-table-next-field) - (org-table-sort-lines nil ?N))) + (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*")) diff --git a/lib/eos/jao-buffers.el b/lib/eos/jao-buffers.el index 7bc3431..2390cf2 100644 --- a/lib/eos/jao-buffers.el +++ b/lib/eos/jao-buffers.el @@ -20,6 +20,14 @@ ;;; Code: +;;;; lines + +;;;###autoload +(defun jao-goto-visible-line (n) + (interactive "NGo to line: ") + (goto-char (point-min)) + (forward-visible-line n)) + ;;;; attached buffers (defun jao-display-buffer-below-selected (buffer alist) (delete-other-windows-vertically) -- cgit v1.2.3