Skip to content

Commit

Permalink
Merge: (magit-todos-update-remote) New option
Browse files Browse the repository at this point in the history
See <#157>.
  • Loading branch information
alphapapa committed May 19, 2024
2 parents 020fea5 + 8f8e6dd commit 501c8db
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 33 deletions.
6 changes: 5 additions & 1 deletion README.org
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ Helm and Ivy are also supported. Note that the =helm= and =ivy= packages are no
:CUSTOM_ID: TRAMP
:END:

=magit-todos= attempts to work in remote repositories accessed via TRAMP. Note that if TRAMP can't find the scanner configured in =magit-todos-scanner=, you may need to use directory-local variables to either add the correct path to =tramp-remote-path= or choose a different scanner.
Remote repositories (i.e. ones accessed via TRAMP) are not automatically scanned for to-dos unless option ~magit-todos-update-remote~ is enabled. Otherwise, a scan may be manually initiated with the command ~magit-todos-update~.

Note that if TRAMP can't find the scanner configured in option ~magit-todos-scanner~, you may need to use directory-local variables to either add the correct path to variable ~tramp-remote-path~ or choose a different scanner.

* Changelog
:PROPERTIES:
Expand All @@ -152,8 +154,10 @@ Helm and Ivy are also supported. Note that the =helm= and =ivy= packages are no

*Additions*
+ Branch-specific TODOs are also cached (to avoid rescanning when automatic updates are disabled. This can improve performance in large repos).
+ Option ~magit-todos-upate-remote~ allows automatic scanning in remote repositories. ([[https://github.com/alphapapa/magit-todos/pull/157][#157]]. Thanks to [[https://github.com/projectgus][Angus Gratton]].)

*Changes*
+ Remote repositories are no longer automatically scanned (see new option ~magit-todos-update-remote~).
+ Option ~magit-todos-keyword-suffix~ defaults to allowing suffixes to be enclosed by parentheses or brackets (rather than just parentheses).
+ Minor improvements to warnings about files containing very long lines: display as messages instead of warnings, and signal errors from outside the process sentinel.

Expand Down
75 changes: 43 additions & 32 deletions magit-todos.el
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,14 @@ items."
(integer :tag "Automatically, but cache items for N seconds")
(const :tag "Manually" nil)))

(defcustom magit-todos-update-remote nil
"Automatically scan in remote repositories.
If nil, remote repos are only scanned when a manual scan is
initiated (see command `magit-todos-update'). Remote repos
include ones accessed via TRAMP (i.e. any path for which
`file-remote-p' returns non-nil)."
:type 'boolean)

(defcustom magit-todos-fontify-keyword-headers t
"Apply keyword faces to group keyword headers."
:type 'boolean)
Expand Down Expand Up @@ -711,38 +719,41 @@ Assumes current buffer is ITEM's buffer."
"Insert to-do items into current buffer.
This function should be called from inside a ‘magit-status’ buffer."
(declare (indent defun))
(when magit-todos-active-scan
;; Avoid running multiple scans for a single magit-status buffer.
(let ((buffer (process-buffer magit-todos-active-scan)))
(when (process-live-p magit-todos-active-scan)
(delete-process magit-todos-active-scan))
(when (buffer-live-p buffer)
(kill-buffer buffer)))
(setq magit-todos-active-scan nil))
(pcase magit-todos-update
((or 't ; Automatic
;; Manual and updating now
(and 'nil (guard magit-todos-updating))
;; Caching and cache expired
(and (pred integerp) (guard (or magit-todos-updating ; Forced update
(>= (float-time
(time-subtract (current-time)
magit-todos-last-update-time))
magit-todos-update)
(null magit-todos-last-update-time)))))
;; Scan and insert.
;; HACK: I don't like setting a special var here, because it seems like lexically binding a
;; special var should follow down the chain, but it isn't working, so we'll do this.
(setq magit-todos-updating t)
(setq magit-todos-active-scan (funcall magit-todos-scanner
:callback #'magit-todos--insert-items
:magit-status-buffer (current-buffer)
:directory default-directory
:depth magit-todos-depth))
(magit-todos--maybe-insert-branch-todos 'rescan))
(_ ; Caching and cache not expired, or not automatic and not manually updating now
(magit-todos--insert-items (current-buffer) magit-todos-item-cache)
(magit-todos--maybe-insert-branch-todos 'cached))))
(when (or magit-todos-update-remote
magit-todos-updating
(not (file-remote-p default-directory)))
(when magit-todos-active-scan
;; Avoid running multiple scans for a single magit-status buffer.
(let ((buffer (process-buffer magit-todos-active-scan)))
(when (process-live-p magit-todos-active-scan)
(delete-process magit-todos-active-scan))
(when (buffer-live-p buffer)
(kill-buffer buffer)))
(setq magit-todos-active-scan nil))
(pcase magit-todos-update
((or 't ; Automatic
;; Manual and updating now
(and 'nil (guard magit-todos-updating))
;; Caching and cache expired
(and (pred integerp) (guard (or magit-todos-updating ; Forced update
(>= (float-time
(time-subtract (current-time)
magit-todos-last-update-time))
magit-todos-update)
(null magit-todos-last-update-time)))))
;; Scan and insert.
;; HACK: I don't like setting a special var here, because it seems like lexically binding a
;; special var should follow down the chain, but it isn't working, so we'll do this.
(setq magit-todos-updating t)
(setq magit-todos-active-scan (funcall magit-todos-scanner
:callback #'magit-todos--insert-items
:magit-status-buffer (current-buffer)
:directory default-directory
:depth magit-todos-depth))
(magit-todos--maybe-insert-branch-todos 'rescan))
(_ ; Caching and cache not expired, or not automatic and not manually updating now
(magit-todos--insert-items (current-buffer) magit-todos-item-cache)
(magit-todos--maybe-insert-branch-todos 'cached)))))

(defun magit-todos--maybe-insert-branch-todos (&optional type)
"Insert branch todos when appropriate.
Expand Down

0 comments on commit 501c8db

Please sign in to comment.