Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request (w/ initial implementation): globalized wc mode for activity tracking #11

Open
holtzermann17 opened this issue Dec 29, 2017 · 2 comments

Comments

@holtzermann17
Copy link

I put this together to use wc-mode as an activity tracker, since none of the existing options seemed to do what I had in mind.

This is just a first attempt. If something along these lines would be useful to include in the package, please critique it, and I'll make changes and then submit a pull request.

(define-globalized-minor-mode my-global-wc-mode wc-mode
  (lambda () (wc-mode 1)))

(my-global-wc-mode 1)

(defun my-global-wc-report ()
  "Produce a list of the buffers that have changed and by how much.
In the process reset the per-buffer count for each buffer."
  (save-excursion
    (remove-if (lambda (bufct) (or (eq 0 (cdr bufct))
                                   ;; ignore org mode capture buffers and
                                   ;; the minibuffer
                                   (string-match-p "CAPTURE\\|.*Minibuf.*"
                                                   (car bufct))))
               (mapcar (lambda (b)
                         (let ((count wc-words-delta))
                           (set-buffer b)
                           (when (> count 0)
                             (wc-reset))
                           `(,(buffer-name) . ,count)))
                       (buffer-list)))))

(defun record-global-wc-report ()
  "Provides `org-mode' integration for `my-global-wc-report'.
Produce a Note that records the per-buffer changes since last run."
  (interactive)
  (let* ((modified-buffers (my-global-wc-report))
         (ct-mods (length modified-buffers)))
    (org-capture nil "n")
    (insert (concat "Word Deltas <" (current-time-string) ">"))
    (forward-line)
    (insert "| Buffer | count | comment |\n|--------+-------+---------|\n" )
    (dolist (b modified-buffers)
      (insert (format "| %s | %s| |\n" (car b) (cdr b))))
    (forward-line (- ct-mods))
    (org-table-next-field)
    (org-table-next-field)
    (org-table-next-field)
    (org-table-align)))

;; We want to routinely run `record-global-wc-report'; that can be accomplished
;; with a crontab entry like this (to run the command hourly):
;; 00  * * * * emacsclient -e "(record-global-wc-report)"
@sten0
Copy link
Contributor

sten0 commented Apr 26, 2020

@holtzermann17, I like this proposed feature! Since it operates on multiple buffers, I feel like it overlaps with my plan at 48a8afd, but progress on that has stalled, and I forget what the local state of my work is. If you'd like to also add async support as well then I'll humbly step out of the way, test your work, and support your PR.

@bnbeckwith, hypothetically, if the best technical solution relies on built-in copy of org-mode for time tracking, would you be opposed to this? Are there any restrictions on oldest supported Emacs version? If older Emacs and org-mode versions wouldn't be supported then I'd propose Emacs 26.x or ELPA org-mode_9.1.14. IIRC Emacs 26.x is the oldest feasible version to add async support without depending on an external library.

@bnbeckwith
Copy link
Owner

@sten0 I'm late to the party on this one. I think that the dependency on org-mode is fine. I suspect that even that can be optional if folks do not wish to use the reporting in pre-compatible versions of emacs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants