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

Fix: evaluate magit-todos-keywords-list just in time (see #101 ) #137

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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