diff --git a/README.org b/README.org index 47bd2ff3..21a1448b 100644 --- a/README.org +++ b/README.org @@ -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: @@ -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. diff --git a/magit-todos.el b/magit-todos.el index e5fe465d..dd30488a 100644 --- a/magit-todos.el +++ b/magit-todos.el @@ -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) @@ -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.