diff options
Diffstat (limited to 'lib/doc')
| -rw-r--r-- | lib/doc/jao-org-focus.el | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/lib/doc/jao-org-focus.el b/lib/doc/jao-org-focus.el index 2383cfc..6fff238 100644 --- a/lib/doc/jao-org-focus.el +++ b/lib/doc/jao-org-focus.el @@ -120,20 +120,43 @@ With arg, offer to switch to all children, regardless of their parent." 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))) + (word-list (jao-org-focus--count-words words)) + (buffer (current-buffer))) (with-current-buffer (get-buffer-create "*word-statistics*") (erase-buffer) - (insert "| word | occurences | - |-----------+------------|\n") + (insert "| word | occurences | lines | + |-----------+------------|--------------------|\n") (dolist (elt word-list) - (insert (format "| %s | %d |\n" (car elt) (cdr elt)))) + (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 100) - (org-cycle) + (goto-char 5) + (next-line 2) + (org-table-next-field) (org-table-sort-lines nil ?N))) (pop-to-buffer "*word-statistics*")) |
