Skip to content

Commit

Permalink
Fix: evaluate magit-todos-keywords-list just in time (se alphapapa#101
Browse files Browse the repository at this point in the history
 )

This make sure to pick up current keywords in case `magit-todos-keywords`
points to a list variable. It also avoids headaches about this at
customization time.
  • Loading branch information
tlotze committed Sep 3, 2022
1 parent c5030cc commit 6955b26
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
4 changes: 4 additions & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ Helm and Ivy are also supported. Note that the =helm= and =ivy= packages are no
*Added*
+ Option =magit-todos-submodule-list= controls whether to-dos in submodules are displayed (default: off). (Thanks to [[https://github.com/matsievskiysv][Matsievskiy S.V.]])

*Fixed*

+ Evaluate `magit-todos-keywords-list` just in time to pick up current keywords in case `magit-todos-keywords` points to a list variable. (See #101.)

*Changed*
+ Option =magit-todos-exclude-globs= now excludes the `.git/` directory by default. (Thanks to [[https://github.com/Amorymeltzer][Amorymeltzer]].)
+ Library ~org~ is no longer loaded automatically, but only when needed. (This can reduce load time, especially if the user's Org configuration is complex.) ([[https://github.com/alphapapa/magit-todos/issues/120][#120]]. Thanks to [[https://github.com/meedstrom][Martin Edström]] and [[https://github.com/jsigman][Johnny Sigman]] for suggesting.)
Expand Down
37 changes: 15 additions & 22 deletions magit-todos.el
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@

(defvar magit-todos-keywords-list nil
"List of to-do keywords.
Set automatically by `magit-todos-keywords' customization.")
Set automatically from `magit-todos-keywords' and
`magit-todos-ignored-keywords' before building the search regex.")

(defvar magit-todos-grep-result-regexp nil
"Regular expression for grep results.
Expand Down Expand Up @@ -226,19 +227,7 @@ Note: the suffix applies only to non-Org files."

(defcustom magit-todos-ignored-keywords '("NOTE" "DONE")
"Ignored keywords. Automatically removed from `magit-todos-keywords'."
:type '(repeat string)
:set (lambda (option value)
(set-default option value)
(when (boundp 'magit-todos-keywords)
;; Avoid setting `magit-todos-keywords' before it's defined.

;; HACK: Testing with `fboundp' is the only way I have been able to find that fixes this
;; problem. I tried using ":set-after '(magit-todos-ignored-keywords)" on
;; `magit-todos-keywords', but it had no effect. I looked in the manual, which seems to
;; suggest that using ":initialize 'custom-initialize-safe-set" might fix it--but that
;; function is no longer to be found in the Emacs source tree. It was committed in 2005,
;; and now it's gone, but the manual still mentions it. ???
(custom-reevaluate-setting 'magit-todos-keywords))))
:type '(repeat string))

(defcustom magit-todos-keywords 'hl-todo-keyword-faces
"To-do keywords to display in Magit status buffer.
Expand All @@ -252,14 +241,7 @@ regular expression."
(variable :tag "List variable"))
:set (lambda (option value)
(set-default option value)
(let ((keywords (cl-typecase value
(null (user-error "Please add some keywords"))
(symbol (if (and (consp (symbol-value value))
(consp (car (symbol-value value))))
(mapcar #'car (symbol-value value))
(symbol-value value)))
(list value))))
(setq magit-todos-keywords-list (seq-difference keywords magit-todos-ignored-keywords)))))
(when (null value) (user-error "Please add some keywords"))))

(defcustom magit-todos-max-items 10
"Automatically collapse the section if there are more than this many items."
Expand Down Expand Up @@ -495,6 +477,16 @@ Type \\[magit-diff-show-or-scroll-up] to peek at the item at point."

;;;; Functions

(defun magit-todos--compile-keywords-list ()
"Evaluate keywords setting and remove ignored keywords from the lot."
(let ((keywords (cl-typecase magit-todos-keywords
(symbol (if (and (consp (symbol-value magit-todos-keywords))
(consp (car (symbol-value magit-todos-keywords))))
(mapcar #'car (symbol-value magit-todos-keywords))
(symbol-value magit-todos-keywords)))
(list magit-todos-keywords))))
(setq magit-todos-keywords-list (seq-difference keywords magit-todos-ignored-keywords))))

(defun magit-todos--coalesce-groups (groups)
"Return GROUPS, coalescing any groups with `equal' keys.
GROUPS should be an alist. Assumes that each group contains
Expand Down Expand Up @@ -1178,6 +1170,7 @@ argument, a list of match items.
When SYNC is non-nil, match items are returned."
name callback callback)
(magit-todos--compile-keywords-list)
(let* ((process-connection-type 'pipe)
(directory (f-relative directory default-directory))
(extra-args (when ,extra-args-var
Expand Down

0 comments on commit 6955b26

Please sign in to comment.