magit-todos-1.5.3/ 0000755 0001750 0001750 00000000000 13747632621 013614 5 ustar dogsleg dogsleg magit-todos-1.5.3/README.org 0000644 0001750 0001750 00000030017 13747632621 015263 0 ustar dogsleg dogsleg #+BEGIN_HTML
#+END_HTML
* magit-todos
[[https://melpa.org/#/magit-todos][file:https://melpa.org/packages/magit-todos-badge.svg]] [[https://stable.melpa.org/#/magit-todos][file:https://stable.melpa.org/packages/magit-todos-badge.svg]]
This package displays keyword entries from source code comments and Org files in the Magit status buffer. Activating an item jumps to it in its file. By default, it uses keywords from [[https://github.com/tarsius/hl-todo][hl-todo]], minus a few (like =NOTE=).
** Contents
:PROPERTIES:
:TOC: siblings
:END:
- [[#screenshots][Screenshots]]
- [[#installation][Installation]]
- [[#usage][Usage]]
- [[#changelog][Changelog]]
- [[#credits][Credits]]
** Screenshots
[[screenshots/matrix.png]]
Items from Org files can be displayed, and can be fontified like in Org buffers:
[[screenshots/fancy-org.png]]
Items can also be automatically grouped in a customizable way, which can be helpful in large repos:
[[screenshots/emacs-grouped.png]]
This shows grouping items by the first path component, then keyword, then filename, and with optional keyword header fontification:
[[screenshots/emacs-grouped-by-path.png]]
Items in =KEYWORD(username):= format are also read:
[[screenshots/thiderman.png]]
Items specific to the current branch (or =git diff=) can be displayed in a separate list:
[[screenshots/branch-list.png]]
** Installation
:PROPERTIES:
:TOC: 0
:END:
*** External scanner
One of the following external scanners is required:
+ [[https://github.com/BurntSushi/ripgrep][ripgrep]]
+ =git grep= (built with PCRE support)
+ GNU =grep= (built with PCRE support)
Most Linux systems should have the latter two by default, but some non-standard systems may not. For example, on MacOS you may use [[https://brew.sh/][Homebrew]] to install =ripgrep=, or =git= with PCRE support, like: ~brew reinstall --with-pcre2 git~.
*** Emacs package
If you installed from MELPA, you're done!
**** Manually
Install these required packages:
- =async=
- =dash=
- =f=
- =hl-todo=
- =magit=
- =pcre2el=
- =s=
Then put this file in your =load-path=, and put this in your init file:
#+BEGIN_SRC elisp
(require 'magit-todos)
#+END_SRC
** Usage
:PROPERTIES:
:TOC: 0
:END:
Activate =magit-todos-mode=. Then open a Magit status buffer, or run ~magit-todos-list~ to show a dedicated to-do list buffer.
*** Key bindings
*In Magit status buffer:*
+ @@html:@@j T@@html:@@ :: Jump to the to-do list. If the section is empty (e.g. when using manual updates), it will scan for items.
*With point in to-do list:*
+ @@html:@@b@@html:@@ :: Show branch (=git diff=) to-do list.
+ @@html:@@B@@html:@@ :: Set commit reference used in branch to-do list.
+ @@html:@@j T@@html:@@ :: When configured for manual updates, manually update the to-do list.
+ @@html:@@j l@@html:@@ :: Open dedicated to-do list buffer.
+ @@html:@@RET@@html:@@ :: Show item at point, or open dedicated buffer if point is on top heading.
+ @@html:@@SPC@@html:@@ :: Peek at the item at point.
*** Commands
+ =magit-todos-mode= :: Activate =magit-todos-mode=, which automatically inserts the to-do list in Magit status buffers.
+ =magit-todos-list= :: Display the to-do list in a separate buffer. This also works outside of git repos.
Helm and Ivy are also supported. Note that the =helm= and =ivy= packages are not required, nor does this package depend on them; they are only used if present. Note as well that these commands can be used directly from source buffers, independently of Magit.
+ =helm-magit-todos= :: Display the project to-do list with Helm.
+ =ivy-magit-todos= :: Display the project to-do list with Ivy.
*** Tips
+ Customize settings in the =magit-todos= group.
+ Use dir-local variables to set per-repository settings. For example, to exclude files and directories from being scanned for to-dos in a repo:
1. From a buffer in the repo's directory (like a ~magit-status~ buffer), run the command ~add-dir-local-variable~.
2. Choose the mode ~magit-status-mode~.
3. Choose the variable ~magit-todos-exclude-globs~.
4. Input the glob value, like ~("*.html")~ to exclude HTML files. (Note that the input is read as a lisp value, and this variable must be a list of strings.)
5. Now Emacs will remember that setting in that repository. (You may also want to commit the =.dir-locals.el= file to the repo.)
+ The ~magit-todos-list~ command also works outside of git repos.
**** TRAMP
:PROPERTIES:
: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.
** Changelog
:PROPERTIES:
:TOC: 0
:END:
*** 1.5.3
*Fixes*
+ Remove face from indentation. (Thanks to [[https://github.com/Alexander-Miller][Alexander Miller]].)
*** 1.5.2
*Fixes*
+ Use =magit-todos-exclude-globs= in branch todo list.
*** 1.5.1
*Fixes*
+ Add insertion function to end of =magit-status-sections-hook=.
*** 1.5
*Added*
+ Support for remote repositories accessed via TRAMP. See [[#TRAMP][usage notes]].
+ Ivy history support. (Thanks to [[https://github.com/leungbk][Brian Leung]].)
+ Option =magit-todos-branch-list-merge-base-ref=.
+ Command =magit-todos-branch-list-set-commit=, bound to =B= with point in a to-do section.
*Changed*
+ Branch todo list now uses =git merge-base= to determine the ancestor commit to compare to =HEAD=.
+ Enable list-wide key bindings on both headings and to-do items.
*Removed*
+ Option =magit-todos-branch-list-commit-ref=, replaced by option =magit-todos-branch-list-merge-base-ref=.
*** 1.4.3
*Fixed*
+ Don't use =--help= option when testing =git grep= command, because it can launch a Web browser on some configurations or platforms (see [[https://github.com/alphapapa/magit-todos/issues/43][#43]]).
+ Caching when branch diff list is displayed.
+ Commands =magit-section-forward= / =backward= sometimes skipped sections (see [[https://github.com/alphapapa/magit-todos/issues/66][#66]]).
*** 1.4.2
*Fixed*
+ Refreshing =magit-todos-list= buffer. ([[https://github.com/alphapapa/magit-todos/issues/92][#92]]. Thanks to [[https://github.com/filalex77][Oleksii Filonenko]] and [[https://github.com/hlissner][Henrik Lissner]] for reporting.)
*** 1.4.1
*Fixed*
+ Compiler warning.
*** 1.4
*Added*
+ Commands =helm-magit-todos= and =ivy-magit-todos=, which display items with Helm and Ivy. (Note that Helm and Ivy are not required, nor does this package depend on them; they are only used if present.)
*Fixed*
+ Warn about files containing lines too long for Emacs's regexp matcher to handle, rather than aborting the scan ([[https://github.com/alphapapa/magit-todos/issues/63][#63]]).
*Updated*
+ Use =magit-setup-buffer= instead of =magit-mode-setup=.
*Internal*
+ Add synchronous mode to scanner functions, which return results directly usable by other code.
*** 1.3
*Added*
+ Branch diff task list. See new options =magit-todos-branch-list= and =magit-todos-branch-list-commit-ref=, and command =magit-todos-branch-list-toggle=, bound to =b= with point on to-do list heading. ([[https://github.com/alphapapa/magit-todos/issues/30][#30]], [[https://github.com/alphapapa/magit-todos/issues/77][#77]], [[https://github.com/alphapapa/magit-todos/pull/82][#82]]. Thanks to [[https://github.com/itamarst][Itamar Turner-Trauring]] and [[https://github.com/arronmabrey][Arron Mabrey]] for the suggestion, and to [[https://github.com/smaret][Sébastien Maret]] for implementing the commit-ref option.)
*Internal*
+ Put newline in section headings. ([[https://github.com/alphapapa/magit-todos/pull/68][#68]]. Thanks to [[https://github.com/vermiculus][Sean Allred]].)
*** 1.2
*Added*
+ Allow ~magit-todos-list~ to work outside git repos.
+ Option ~magit-todos-keyword-suffix~ replaces ~magit-todos-require-colon~, allowing for common and custom suffixes after item keywords (e.g. to match items like =TODO(user):=). (Fixes [[https://github.com/alphapapa/magit-todos/issues/56][#56]]. Thanks to [[https://github.com/thiderman][Lowe Thiderman]] for suggesting.)
+ Optionally group and sort by item suffixes (e.g. handy when suffixes contain usernames).
+ Bind @@html:@@RET@@html:@@ on top-level =TODOs= section heading to ~magit-todos-list~ command.
*Fixed*
+ Don't fontify section item counts. (Thanks to [[https://github.com/m-cat][Marcin Swieczkowski]].)
*Worked Around*
+ Issue in =async= regarding deleted buffers/processes. This is not an ideal solution, but it solves the problem for now.
*Removed*
+ Option ~magit-todos-require-colon~, replaced by ~magit-todos-keyword-suffix~.
*** 1.1.8
*Fixed*
+ Properly unbind key when mode is disabled. ([[https://github.com/alphapapa/magit-todos/pull/74][#74]]. Thanks to [[https://github.com/akirak][Akira Komamura]].)
+ Don't show message when key is already bound correctly. ([[https://github.com/alphapapa/magit-todos/pull/75][#75]]. Thanks to [[https://github.com/akirak][Akira Komamura]].)
*** 1.1.7
*Fixed*
+ Disable undo in hidden Org fontification buffer.
+ Expand top-level to-do list in ~magit-todos-list~ buffer.
*** 1.1.6
*Fixed*
+ Insert root section in ~magit-todos-list~ command. (Really fixes [[https://github.com/alphapapa/magit-todos/issues/55][#55]]. Thanks to [[https://github.com/tarsius][Jonas Bernoulli]].)
*** 1.1.5
*Fixed*
+ Hide process buffers. (Thanks to [[https://github.com/purcell][Steve Purcell]].)
*** 1.1.4
*Fixes*
+ ~magit-todos-depth~ number-to-string conversion.
*** 1.1.3
*Fixes*
+ Update ~magit-todos-list~ for Magit [[https://github.com/magit/magit/commit/40616d7ba57b7c491513e4130d82371460f9e94d][change]]. (Fixes [[https://github.com/alphapapa/magit-todos/issues/55][#55]]. Thanks to [[https://github.com/Oghma][Matteo Lisotto]].)
*** 1.1.2
*Fixes*
+ Convert ~magit-todos-depth~ setting appropriately for =rg= scanner.
*** 1.1.1
*Fixes*
+ Ensure mode is activated in ~magit-todos-update~ command. (Fixes #54. Thanks to [[https://github.com/smaret][Sebastien Maret]].)
*** 1.1
*Additions*
+ Dedicated to-do list buffer.
+ Option ~magit-todos-exclude-globs~, a list of glob patterns to ignore when searching for to-do items.
+ Kill running scans when Magit status buffer is closed.
*Changes*
+ Remove dependency on ~a~.
+ Remove dependency on =anaphora=.
*Fixes*
+ Add missing ~cl-~ prefix. Thanks to [[https://github.com/jellelicht][Jelle Licht]].
*** 1.0.4
*Fixes*
+ Fix =find|grep= scanner ([[https://github.com/alphapapa/magit-todos/issues/46][issue 46]]). Thanks to [[https://github.com/Ambrevar][Pierre Neidhardt]].
*** 1.0.3
*Fixes*
+ Define variables earlier to avoid compiler warnings.
+ Remove unused var ~magit-todos-ignore-file-suffixes~.
*** 1.0.2
*Fixes*
+ ~regexp-quote~ item keywords when jumping to an item. (Fixes #36. Thanks to [[https://github.com/dfeich][Derek Feichtinger]].)
+ Ensure =grep= supports =--perl-regexp=.
+ Warn when unable to find a suitable scanner (i.e. =rg=, or a PCRE-compatible version of =git= or =grep=).
*** 1.0.1
*Fixes*
+ Test whether =git grep= supports =--perl-regexp= by checking its =--help= output, rather than doing a search and checking for an error.
+ ~message~ instead of ~error~ for weird behavior. (This message exists to help track down an inconsequential bug.)
+ Remove unused ~magit-todos-ignore-directories~ option. (To be replaced in a future release.)
*** 1.0.0
Initial release.
** Credits
+ This package was inspired by [[https://github.com/danielma/magit-org-todos.el][magit-org-todos]].
+ The =ag= support was made much simpler by the great [[https://github.com/joddie/pcre2el][pcre2el]] package by Jon Oddie.
+ Thanks to [[https://github.com/zhaojiangbin][Jiangbin Zhao]] for his extensive testing and feedback.
** License
:PROPERTIES:
:TOC: ignore
:END:
GPLv3
# Local Variables:
# before-save-hook: org-make-toc
# End:
magit-todos-1.5.3/magit-todos.el 0000644 0001750 0001750 00000210004 13747632621 016362 0 ustar dogsleg dogsleg ;;; magit-todos.el --- Show source file TODOs in Magit -*- lexical-binding: t; -*-
;; Copyright (C) 2018 Adam Porter
;; Author: Adam Porter
;; URL: http://github.com/alphapapa/magit-todos
;; Version: 1.5.3
;; Package-Requires: ((emacs "25.2") (async "1.9.2") (dash "2.13.0") (f "0.17.2") (hl-todo "1.9.0") (magit "2.13.0") (pcre2el "1.8") (s "1.12.0"))
;; Keywords: magit, vc
;;; Commentary:
;; This package displays keyword entries from source code comments and Org files
;; in the Magit status buffer. Activating an item jumps to it in its file. By
;; default, it uses keywords from `hl-todo', minus a few (like "NOTE").
;;;; Usage:
;; Run `magit-todos-mode', then open a Magit status buffer.
;;;; Tips:
;; + You can customize settings in the `magit-todos' group.
;;; Installation:
;;;; MELPA
;; If you installed from MELPA, you're done.
;;;; Manual
;; Install these required packages:
;; async
;; dash
;; f
;; hl-todo
;; magit
;; pcre2el
;; s
;; Then put this file in your load-path, and put this in your init file:
;; (require 'magit-todos)
;;; License:
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see .
;;; Code:
;;;; Requirements
(require 'cl-lib)
(require 'org)
(require 'grep)
(require 'seq)
(require 'async)
(require 'dash)
(require 'f)
(require 'hl-todo)
(require 'magit)
(require 'pcre2el)
(require 's)
;;;; Structs
(cl-defstruct magit-todos-item
filename org-level line column position keyword suffix description)
;;;; Variables
(defvar magit-todos-keywords-list nil
"List of to-do keywords.
Set automatically by `magit-todos-keywords' customization.")
(defvar magit-todos-grep-result-regexp nil
"Regular expression for grep results.
This should be set automatically by customizing
`magit-todos-keywords'.")
(defvar magit-todos-ag-result-regexp nil
"Regular expression for ag results.
This should be set automatically by customizing
`magit-todos-keywords'.")
(defvar magit-todos-rg-result-regexp nil
"Regular expression for rg results.
This should be set automatically by customizing
`magit-todos-keywords'.")
(defvar magit-todos-git-grep-result-regexp nil
"Regular expression for git-grep results.
This should be set automatically by customizing
`magit-todos-keywords'.")
(defvar magit-todos-search-regexp nil
"Regular expression to match keyword items with rg, ag, and git-grep.
This should be set automatically by customizing
`magit-todos-keywords'.")
(defvar-local magit-todos-active-scan nil
"The current scan's process.
Used to avoid running multiple simultaneous scans for a
magit-status buffer.")
;; FIXME: Jumping binds. In `magit-status-mode-map' now, "j" is bound
;; to `magit-status-jump', which is a Transient command; it's no
;; longer bound to a prefix map. There doesn't seem to be a way to
;; add binds to that Transient command's body.
(defvar magit-todos-section-map
(let ((map (make-sparse-keymap)))
(define-key map "jT" #'magit-todos-jump-to-todos)
(define-key map "jl" #'magit-todos-list)
(define-key map "b" #'magit-todos-branch-list-toggle)
(define-key map "B" #'magit-todos-branch-list-set-commit)
(define-key map [remap magit-visit-thing] #'magit-todos-list)
map)
"Keymap for `magit-todos' top-level section.")
(defvar magit-todos-item-section-map
(let ((map (copy-keymap magit-todos-section-map)))
(define-key map [remap magit-visit-thing] #'magit-todos-jump-to-item)
(define-key map [remap magit-diff-show-or-scroll-up] #'magit-todos-peek-at-item)
map)
"Keymap for `magit-todos' individual to-do item sections.
See https://magit.vc/manual/magit/Creating-Sections.html for more
details about how section maps work.")
(defvar-local magit-todos-show-filenames nil
"Whether to show filenames next to to-do items.
Set automatically depending on grouping.")
(defvar-local magit-todos-updating nil
"Whether items are being updated now.")
(defvar-local magit-todos-last-update-time nil
"When the items were last updated.
A time value as returned by `current-time'.")
(defvar-local magit-todos-item-cache nil
"Items found by most recent scan.")
(defvar magit-todos-scanners nil
"Scanners defined by `magit-todos-defscanner'.")
(defvar magit-todos-section-heading "TODOs"
"Allows overriding of section heading.")
;;;; Customization
(defgroup magit-todos nil
"Show TODO items in source code comments in repos' files."
:group 'magit)
(defcustom magit-todos-scanner nil
"File scanning method.
\"Automatic\" will attempt to use rg, ag, git-grep, and
find-grep, in that order. "
:type '(choice (const :tag "Automatic" nil)
(function :tag "Custom function"))
:set (lambda (option value)
(when magit-todos-scanners
;; Only try to set when scanners are defined.
(unless value
;; Choosing automatically
(setq value (or (magit-todos--choose-scanner)
(progn
(display-warning 'magit-todos
"`magit-todos' was unable to find a suitable scanner. Please install \"rg\", or a PCRE-compatible version of \"git\" or \"grep\". Disabling `magit-todos-mode'."
:error)
(magit-todos-mode -1)
nil))))
(set-default option value))))
(defcustom magit-todos-nice t
"Run scanner with \"nice\"."
:type 'boolean)
(defcustom magit-todos-ignore-case nil
"Upcase keywords found in files.
If nil, a keyword like \"Todo:\" will not be shown. `upcase' can
be a relatively expensive function, so this can be disabled if
necessary."
:type 'boolean)
(defcustom magit-todos-update t
"When or how often to scan for to-dos.
When set to manual updates, the list can be updated with the
command `magit-todos-update'. When caching is enabled, scan for
items whenever the Magit status buffer is refreshed and at least
N seconds have passed since the last scan; otherwise, use cached
items."
:type '(choice (const :tag "Automatically, when the Magit status buffer is refreshed" t)
(integer :tag "Automatically, but cache items for N seconds")
(const :tag "Manually" nil)))
(defcustom magit-todos-fontify-keyword-headers t
"Apply keyword faces to group keyword headers."
:type 'boolean)
(defcustom magit-todos-keyword-suffix (rx (optional "(" (1+ (not (any ")"))) ")") ":")
"Regular expression matching suffixes after keywords.
e.g. to match a keyword like \"TODO(user):\", use \"([^)]+):\".
If the suffix should be optional, the entire regexp should be
made explicitly optional. However, it is not necessary to
account for optional whitespace after the suffix, as this is done
automatically.
Note: the suffix applies only to non-Org files."
:type `(choice (const :tag "Optional username in parens, then required colon (matching e.g. \"TODO:\" or \"TODO(user):\")"
,(rx (optional "(" (1+ (not (any ")"))) ")") ":"))
(const :tag "Required colon (matching e.g. \"TODO:\"" ":")
(string :tag "Custom regexp"))
:package-version '(magit-todos . "1.2"))
(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))))
(defcustom magit-todos-keywords 'hl-todo-keyword-faces
"To-do keywords to display in Magit status buffer.
If set to a list variable, may be a plain list or an alist in
which the keys are the keywords.
When set, sets `magit-todos-search-regexp' to the appropriate
regular expression."
:type '(choice (repeat :tag "Custom list" string)
(const :tag "Keywords from `hl-todo'" hl-todo-keyword-faces)
(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)))))
(defcustom magit-todos-max-items 10
"Automatically collapse the section if there are more than this many items."
:type 'integer)
(defcustom magit-todos-auto-group-items 20
"Whether or when to automatically group items."
:type '(choice (integer :tag "When there are more than this many items")
(const :tag "Always" always)
(const :tag "Never" never)))
(defcustom magit-todos-buffer-item-factor 10
"Multiply `magit-todos-auto-group-items' and `magit-todos-max-items' by this factor in dedicated `magit-todos' buffers."
:type 'integer)
(defcustom magit-todos-group-by '(magit-todos-item-keyword magit-todos-item-filename)
"How to group items.
One or more attributes may be chosen, and they will be grouped in
order."
:type '(repeat (choice (const :tag "By filename" magit-todos-item-filename)
(const :tag "By keyword" magit-todos-item-keyword)
(const :tag "By suffix" magit-todos-item-suffix)
(const :tag "By first path component" magit-todos-item-first-path-component))))
(defcustom magit-todos-fontify-org t
"Fontify items from Org files as Org headings."
:type 'boolean)
(defcustom magit-todos-sort-order '(magit-todos--sort-by-keyword
magit-todos--sort-by-filename
magit-todos--sort-by-position)
"Order in which to sort items."
:type '(repeat (choice (const :tag "Keyword" magit-todos--sort-by-keyword)
(const :tag "Suffix" magit-todos--sort-by-suffix)
(const :tag "Filename" magit-todos--sort-by-filename)
(const :tag "Buffer position" magit-todos--sort-by-position)
(function :tag "Custom function"))))
(defcustom magit-todos-depth nil
"Maximum depth of files in repo working tree to scan for to-dos.
A value of 0 means to search only the current directory, while a
value of 1 means to search directories one level deeper, etc.
Deeper scans can be slow in large projects. You may wish to set
this in a directory-local variable for certain projects."
:type '(choice (const :tag "Unlimited" nil)
(const :tag "Repo root directory only" 0)
(integer :tag "N levels below the repo root")))
(defcustom magit-todos-insert-at 'bottom
"Insert the to-dos section after this section in the Magit status buffer.
Specific sections may be chosen, using the first symbol returned
by evaluating \"(magit-section-ident (magit-current-section))\"
in the status buffer with point on the desired section,
e.g. `recent' for the \"Recent commits\" section. Note that this
may not work exactly as desired when the built-in scanner is
used."
:type '(choice (const :tag "Top" top)
(const :tag "Bottom" bottom)
(const :tag "After untracked files" untracked)
(const :tag "After unstaged files" unstaged)
(symbol :tag "After selected section")))
(defcustom magit-todos-exclude-globs nil
"Glob patterns to exclude from searches."
:type '(repeat string))
(defcustom magit-todos-branch-list 'branch
"Show branch diff to-do list.
This can be toggled locally in Magit buffers with command
`magit-todos-branch-list-toggle'."
:type '(choice (const :tag "Never" nil)
(const :tag "In non-master branches" branch)
(const :tag "Always" t)))
(defcustom magit-todos-branch-list-merge-base-ref "master"
"Commit ref passed to command \"git merge-base HEAD\".
Determines the ancestor commit from which the current branch's
todos should be searched for. May be overridden in the case that
a branch is branched off another branch rather than master. For
example, consider the following commit graph:
---A1---A2---A3 (master)
\
B1---B2---B3 (topic)
\
C1---C2---C3 (topic2, HEAD)
By default, the branch todo list would show todos from both the
\"topic\" branch and the \"topic2\" branch. To show only todos
from the \"topic2\" branch, this option could be set to
\"topic\"."
:type 'string)
;;;; Commands
;;;###autoload
(define-minor-mode magit-todos-mode
"Show list of to-do items in Magit status buffer for tracked files in repo."
:require 'magit-todos
:group 'magit-todos
:global t
(if magit-todos-mode
(progn
(pcase (lookup-key magit-status-mode-map "jT")
('nil (define-key magit-status-mode-map "jT" #'magit-todos-jump-to-todos))
('magit-todos-jump-to-todos nil)
(_ (message "magit-todos: Not overriding bind of \"jT\" in `magit-status-mode-map'.")))
(magit-add-section-hook 'magit-status-sections-hook
#'magit-todos--insert-todos
nil
'append)
(add-hook 'magit-status-mode-hook #'magit-todos--add-to-status-buffer-kill-hook 'append))
;; Disable mode
(when (equal (lookup-key magit-status-mode-map "jT") #'magit-todos-jump-to-todos)
(define-key magit-status-mode-map "jT" nil))
(remove-hook 'magit-status-sections-hook #'magit-todos--insert-todos)
(remove-hook 'magit-status-mode-hook #'magit-todos--add-to-status-buffer-kill-hook)))
(defun magit-todos-update ()
"Update the to-do list manually.
Only necessary when option `magit-todos-update' is nil."
(interactive)
(unless magit-todos-mode
(user-error "Please activate `magit-todos-mode'"))
(let ((inhibit-read-only t))
;; Delete twice since there might also be the branch-local section.
(magit-todos--delete-section [* todos])
(magit-todos--delete-section [* todos])
;; HACK: See other note on `magit-todos-updating'.
(setq magit-todos-updating t)
(magit-todos--insert-todos)))
(defun magit-todos-branch-list-toggle ()
"Toggle branch diff to-do list in current Magit buffer."
(interactive)
(setq-local magit-todos-branch-list (not magit-todos-branch-list))
(magit-todos-update))
(defun magit-todos-branch-list-set-commit (ref)
"Set commit ref used in branch to-do list."
(interactive (list (completing-read "Refname: " (magit-list-refnames))))
(setq-local magit-todos-branch-list-merge-base-ref ref)
(magit-todos-update))
(cl-defun magit-todos-jump-to-item (&key peek (item (oref (magit-current-section) value)))
"Show current item.
If PEEK is non-nil, keep focus in status buffer window."
(interactive)
(let* ((status-window (selected-window))
(buffer (magit-todos--item-buffer item)))
(pop-to-buffer buffer)
(magit-todos--goto-item item)
(when (derived-mode-p 'org-mode)
(org-show-entry))
(when peek
(select-window status-window))))
(defun magit-todos-peek-at-item ()
"Peek at current item."
(interactive)
(magit-todos-jump-to-item :peek t))
;;;;; Jump to section
(magit-define-section-jumper magit-jump-to-todos "TODOs" todos)
(defun magit-todos-jump-to-todos ()
"Jump to TODOs section, and update it if empty."
(interactive)
(let ((already-in-section-p (magit-section-match [* todos])))
(magit-jump-to-todos)
(when (and (or (integerp magit-todos-update)
(not magit-todos-update))
(or already-in-section-p
(= 0 (length (oref (magit-current-section) children)))))
(magit-todos-update))))
;;;; Dedicated buffer
;;;###autoload
(defun magit-todos-list (&optional directory)
"Show to-do list of the current Git repository in a buffer.
With prefix, prompt for repository."
;; Mostly copied from `magit-status'
(interactive
(let ((magit--refresh-cache (list (cons 0 0))))
(list (and (or current-prefix-arg (not (magit-toplevel)))
(magit-read-repository)))))
(condition-case nil
(let ((magit--refresh-cache (list (cons 0 0))))
(setq directory (if directory
(file-name-as-directory (expand-file-name directory))
default-directory))
(magit-todos-list-internal directory))
('magit-outside-git-repo (cl-letf (((symbol-function 'magit-toplevel) (lambda (&rest _) default-directory)))
(call-interactively #'magit-todos-list)))))
(put 'magit-todos-list 'interactive-only 'magit-todos-list-internal)
;;;###autoload
(defun magit-todos-list-internal (directory)
"Open buffer showing to-do list of repository at DIRECTORY."
(magit--tramp-asserts directory)
(let ((default-directory directory))
(magit-setup-buffer #'magit-todos-list-mode)))
(define-derived-mode magit-todos-list-mode magit-status-mode "Magit"
"Mode for looking at repository to-do list.
\\\
Type \\[magit-refresh] to refresh the list.
Type \\[magit-section-toggle] to expand or hide the section at point.
Type \\[magit-visit-thing] to visit the item at point.
Type \\[magit-diff-show-or-scroll-up] to peek at the item at point."
:group 'magit-todos)
(defun magit-todos-list-refresh-buffer ()
"Refresh the current `magit-todos-list-mode' buffer."
(setq-local magit-todos-max-items (* magit-todos-max-items magit-todos-buffer-item-factor))
(when (numberp magit-todos-auto-group-items)
(setq-local magit-todos-auto-group-items (* magit-todos-auto-group-items magit-todos-buffer-item-factor)))
(magit-section-show (magit-insert-section (type magit-root-section)
(magit-insert-status-headers)
(magit-todos--insert-todos))))
;;;; Functions
(defun magit-todos--coalesce-groups (groups)
"Return GROUPS, coalescing any groups with `equal' keys.
GROUPS should be an alist. Assumes that each group contains
unique items. Intended for post-processing the result of
`-group-by'."
(cl-loop with keys = (-uniq (-map #'car groups))
for key in keys
for matching-groups = (--select (equal key (car it)) groups)
collect (cons key (apply #'append (-map #'cdr matching-groups)))))
(defun magit-todos--add-to-status-buffer-kill-hook ()
"Add `magit-todos--kill-active-scan' to `kill-buffer-hook' locally."
(add-hook 'kill-buffer-hook #'magit-todos--kill-active-scan 'append 'local))
(defun magit-todos--kill-active-scan ()
"Kill `magit-todos-active-scan'.
To be called in status buffers' `kill-buffer-hook'."
(when (and magit-todos-active-scan
(process-live-p magit-todos-active-scan))
(kill-process magit-todos-active-scan)
(when-let* ((buffer (process-buffer magit-todos-active-scan))
(alive (buffer-live-p buffer)))
(kill-buffer buffer))))
(defun magit-todos--add-to-custom-type (symbol value)
"Add VALUE to the end of SYMBOL's `custom-type' property."
(declare (indent defun))
(pcase-let* ((`(,type . ,choices) (get symbol 'custom-type))
(choices (append (list value) choices)))
(put symbol 'custom-type
(append (list type) choices))))
(defun magit-todos--choose-scanner ()
"Return function to call to scan for items with.
Chooses automatically in order defined in `magit-todos-scanners'."
(cl-loop for scanner in magit-todos-scanners
;; I guess it would be better to avoid `eval', but it seems like the natural
;; way to do this.
when (eval (alist-get 'test scanner))
return (alist-get 'function scanner)))
(cl-defun magit-todos--scan-callback (&key callback magit-status-buffer results-regexp process &allow-other-keys)
"Call CALLBACK with arguments MAGIT-STATUS-BUFFER and match items.
Match items are a list of `magit-todos-item' found in PROCESS's buffer for RESULTS-REGEXP."
(funcall callback magit-status-buffer
(with-current-buffer (process-buffer process)
(magit-todos--buffer-items results-regexp))))
(defun magit-todos--buffer-items (results-regexp)
"Return list of `magit-todos-item' found in current buffer for RESULTS-REGEXP."
(let ((items))
(save-excursion
(goto-char (point-min))
(while (not (eobp))
(--when-let (condition-case err
(magit-todos--line-item results-regexp)
;; Files with very, very long lines may cause Emacs's regexp matcher to overflow.
;; Rather than abort the whole scan and raise an error, try to handle it gracefully.
;; FIXME: This may raise multiple warnings per file.
(error (if (string= "Stack overflow in regexp matcher" (error-message-string err))
(let ((filename (buffer-substring (point) (1- (re-search-forward ":")))))
(display-warning 'magit-todos (concat "File has lines too long for Emacs to search. Consider excluding it from scans: " filename)))
(signal (car err) (cdr err)))))
(push it items))
(forward-line 1)))
(nreverse items)))
(cl-defun magit-todos--git-diff-callback (&key magit-status-buffer results-regexp search-regexp-elisp process heading
exclude-globs &allow-other-keys)
"Callback for git diff scanner output."
;; NOTE: Doesn't handle newlines in filenames or diff.mnemonicPrefix.
(cl-macrolet ((next-diff () `(re-search-forward (rx bol "diff --git ") nil t))
(next-filename () `(when (re-search-forward (rx bol "+++ b/" (group (1+ nonl))) nil t)
(match-string 1)))
(next-hunk-line-number () `(when (re-search-forward (rx bol "@@ -"
(1+ digit) (optional "," (1+ digit)) (1+ space)
"+" (group (1+ digit)) (optional "," (1+ digit)))
file-end t)
(string-to-number (match-string 1))))
(file-end () `(or (save-excursion
(when (re-search-forward (rx bol "diff --git ")
nil t)
(match-beginning 0)))
(point-max)))
(hunk-end () `(or (save-excursion
(when (re-search-forward (rx (or (seq bol "diff --git ")
(seq bol "@@ ")))
nil t)
(match-beginning 0)))
(point-max))))
(with-current-buffer (process-buffer process)
(goto-char (point-min))
(let ((glob-regexps (mapcar #'wildcard-to-regexp exclude-globs))
items filename file-end hunk-end line-number)
(while (next-diff)
(while (setf filename (next-filename))
(unless (--some? (string-match it filename) glob-regexps)
(setf file-end (file-end))
(while (setf line-number (next-hunk-line-number))
(setf hunk-end (hunk-end))
(while (re-search-forward (rx bol "+") hunk-end t)
;; Since "git diff-index" doesn't accept PCREs to its "-G" option, we have to test the search regexp ourselves.
(when (re-search-forward search-regexp-elisp (line-end-position) t)
(when-let* ((line (buffer-substring (line-beginning-position) (line-end-position)))
(item (with-temp-buffer
;; NOTE: We fake grep output by inserting the filename, line number, position, etc.
;; This lets us use the same results regexp that's used for grep-like output.
(save-excursion
(insert filename ":" (number-to-string line-number) ":0: " line))
(magit-todos--line-item results-regexp filename))))
(push item items)))
(cl-incf line-number))))))
(let ((magit-todos-section-heading heading))
(magit-todos--insert-items magit-status-buffer items :branch-p t))))))
(defun magit-todos--delete-section (condition)
"Delete the section specified by CONDITION from the Magit status buffer.
See `magit-section-match'. Also delete it from root section's children."
(save-excursion
(goto-char (point-min))
(when-let ((section (cl-loop until (magit-section-match condition)
;; Use `forward-line' instead of `magit-section-forward' because
;; sometimes it skips our section.
do (forward-line 1)
when (eobp)
return nil
finally return (magit-current-section))))
;; Delete the section from root section's children. This makes the section-jumper command
;; work when a replacement section is inserted after deleting this section.
(object-remove-from-list magit-root-section 'children section)
(with-slots (start end) section
;; NOTE: We delete 1 past the end because we insert a newline after the section. I'm not
;; sure if this would generalize to all Magit sections. But if the end is the same as
;; `point-max', which may be the case if todo items have not yet been inserted, we only
;; delete up to `point-max'.
(delete-region start (if (= end (point-max))
end
(1+ end)))))))
(defun magit-todos--item-buffer (item)
"Return buffer visiting ITEM."
(or (find-buffer-visiting (magit-todos-item-filename item))
(find-file-noselect (magit-todos-item-filename item))))
(defun magit-todos--goto-item (item)
"Move point to ITEM.
Assumes current buffer is ITEM's buffer."
(pcase-let* (((cl-struct magit-todos-item position line column keyword) item))
(if position
(goto-char position)
(goto-char (point-min))
(forward-line (1- line))
(if column
(forward-char column)
(when (re-search-forward (regexp-quote keyword) (line-end-position) t)
(goto-char (match-beginning 0)))))))
(defun magit-todos--insert-todos ()
"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)))
(_ ; Caching and cache not expired, or not automatic and not manually updating now
(magit-todos--insert-items (current-buffer) magit-todos-item-cache)))
(when (or (eq magit-todos-branch-list t)
(and (eq magit-todos-branch-list 'branch)
(not (string= "master" (magit-get-current-branch)))))
;; Insert branch-local items.
(magit-todos--scan-with-git-diff :magit-status-buffer (current-buffer)
:directory default-directory
:depth magit-todos-depth
:heading (format "TODOs (branched from %s)" magit-todos-branch-list-merge-base-ref))))
(cl-defun magit-todos--insert-items (magit-status-buffer items &key branch-p)
"Insert to-do ITEMS into MAGIT-STATUS-BUFFER.
If BRANCH-P is non-nil, do not update `magit-todos-item-cache',
`magit-todos-last-update-time', and `magit-todos-updating'."
(declare (indent defun))
;; NOTE: This could be factored out into some kind of `magit-insert-section-async' macro if necessary.
;; MAYBE: Use `magit-insert-section-body'.
(when (not (buffer-live-p magit-status-buffer))
(message "`magit-todos--insert-items-callback': Callback called for deleted buffer"))
(let* ((items (magit-todos--sort items))
(num-items (length items))
(group-fns (pcase magit-todos-auto-group-items
('never nil)
('always magit-todos-group-by)
((pred integerp) (when (> num-items magit-todos-auto-group-items)
magit-todos-group-by))
(_ (error "Invalid value for magit-todos-auto-group-items"))))
(magit-todos-show-filenames (not (member 'magit-todos-item-filename group-fns)))
(magit-section-show-child-count t)
;; HACK: "For internal use only." But this makes collapsing the new section work!
(magit-insert-section--parent magit-root-section)
(inhibit-read-only t))
(when (buffer-live-p magit-status-buffer)
;; Don't try to select a killed status buffer
(with-current-buffer magit-status-buffer
(unless branch-p
;; Don't do any of this for the branch-diff scanner.
(when magit-todos-updating
(when (or (null magit-todos-update) ; Manual updates
(integerp magit-todos-update)) ; Caching
(setq magit-todos-item-cache items)
(setq magit-todos-last-update-time (current-time)))
;; HACK: I don't like setting this special var, but it works. See other comment where
;; it's set t.
(setq magit-todos-updating nil)))
(save-excursion
;; Insert items
(goto-char (point-min))
;; Go to insertion position
(pcase magit-todos-insert-at
('top (cl-loop for ((this-section . _) . _) = (magit-section-ident (magit-current-section))
until (not (member this-section '(branch tags)))
do (magit-section-forward)))
('bottom (goto-char (oref (-last-item (oref magit-root-section children)) end)))
(_ (magit-todos--skip-section (vector '* magit-todos-insert-at))))
;; Insert section
(let ((reminder (if magit-todos-update
"" ; Automatic updates: no reminder
;; Manual updates: remind user
" (update manually)")))
(if (not items)
(unless magit-todos-update
;; Manual updates: Insert section to remind user
(let ((magit-insert-section--parent magit-root-section))
(magit-insert-section (todos)
(magit-insert-heading (concat (propertize magit-todos-section-heading 'face 'magit-section-heading)
" (0)" reminder "\n")))))
(let ((section (magit-todos--insert-groups :type 'todos
:heading (format "%s (%s)%s"
(propertize magit-todos-section-heading 'face 'magit-section-heading)
num-items reminder)
:group-fns group-fns
:items items
:depth 0)))
(insert "\n")
(magit-todos--set-visibility :section section :num-items num-items)))))))))
(cl-defun magit-todos--insert-groups (&key depth group-fns heading type items)
"Insert ITEMS into grouped Magit section and return the section.
DEPTH sets indentation and should be 0 for a top-level group. It
is automatically incremented when this function calls itself.
GROUP-FNS may be a list of functions to which ITEMS are applied
with `-group-by' to group them. Items are grouped
hierarchically, i.e. when GROUP-FNS has more than one function,
items are first grouped by the first function, then subgroups are
created which group items by subsequent functions.
HEADING is a string which is the group's heading. The count of
items in each group is automatically appended.
TYPE is a symbol which is used by Magit internally to identify
sections."
;; NOTE: `magit-insert-section' seems to bind `magit-section-visibility-cache' to nil, so setting
;; visibility within calls to it probably won't work as intended.
(declare (indent defun))
(let* ((indent (propertize (s-repeat (* 2 depth) " ") 'face nil))
(heading (concat indent heading))
(magit-insert-section--parent (if (= 0 depth)
magit-root-section
magit-insert-section--parent)))
(if (and (consp group-fns)
(> (length group-fns) 0))
;; Insert more groups
(let* ((groups (--> (-group-by (car group-fns) items)
(cl-loop for group in-ref it
;; HACK: Set ":" keys to nil so they'll be grouped together.
do (pcase (car group)
(":" (setf (car group) nil)))
finally return it)
(magit-todos--coalesce-groups it)))
(section (magit-insert-section ((eval type))
(magit-insert-heading heading)
(cl-loop for (group-type . items) in groups
for group-name = (pcase group-type
;; Use "[Other]" instead of empty group name.
;; HACK: ":" is hard-coded, even though the
;; suffix regexp could differ. If users change
;; the suffix so this doesn't apply, it
;; shouldn't cause any problems, it just won't
;; look as pretty.
((or "" ":" 'nil) "[Other]")
(_ (s-chop-suffix ":" group-type)))
do (magit-todos--insert-groups
:depth (1+ depth) :group-fns (cdr group-fns)
:type (intern group-name) :items items
:heading (concat
(if (and magit-todos-fontify-keyword-headers
(member group-name magit-todos-keywords-list))
(propertize group-name 'face (magit-todos--keyword-face group-name))
group-name)
;; Item count
(if (= 1 (length group-fns))
":" ; Let Magit add the count.
;; Add count ourselves.
(concat " " (format "(%s)" (length items))))))))))
(magit-todos--set-visibility :depth depth :num-items (length items) :section section)
;; Add top-level section to root section's children
(when (= 0 depth)
(push section (oref magit-root-section children)))
;; Don't forget to return the section!
section)
;; Insert individual to-do items
(magit-todos--insert-group :depth (1+ depth) :type type :items items :heading heading))))
(cl-defun magit-todos--insert-group (&key depth heading type items)
"Insert ITEMS into Magit section and return the section.
DEPTH sets indentation and should be 0 for a top-level group.
HEADING is a string which is the group's heading. The count of
items in each group is automatically appended.
TYPE is a symbol which is used by Magit internally to identify
sections."
;; NOTE: `magit-insert-section' seems to bind `magit-section-visibility-cache' to nil, so setting
;; visibility within calls to it probably won't work as intended.
(declare (indent defun))
(let* ((indent (propertize (s-repeat (* 2 depth) " ") 'face nil))
(magit-insert-section--parent (if (= 0 depth)
magit-root-section
magit-insert-section--parent))
(width (- (window-text-width) depth))
(section (magit-insert-section ((eval type))
(magit-insert-heading heading)
(dolist (item items)
(let* ((filename (propertize (magit-todos-item-filename item) 'face 'magit-filename))
(string (--> (concat indent
(when magit-todos-show-filenames
(concat filename " "))
(funcall (if (s-suffix? ".org" filename)
#'magit-todos--format-org
#'magit-todos--format-plain)
item))
(truncate-string-to-width it width))))
(magit-insert-section (todos-item item)
(insert string "\n")))))))
(magit-todos--set-visibility :depth depth :num-items (length items) :section section)
;; Don't forget to return the section!
section))
(cl-defun magit-todos--set-visibility (&key section num-items depth)
"Set the visibility of SECTION.
If the section's visibility is cached by Magit, the cached
setting is applied. Otherwise, visibility is set according to
whether NUM-ITEMS is greater than `magit-todos-max-items'.
When DEPTH is greater than 0, NUM-ITEMS is compared to
`magit-todos-max-items' divided by DEPTH multiplied by 2,
i.e. the max number of items which cause sections to be
automatically hidden halves at each deeper level."
(declare (indent defun))
(pcase (magit-section-cached-visibility section)
('hide (magit-section-hide section))
('show (magit-section-show section))
(_ (if (> num-items (pcase depth
(0 magit-todos-max-items)
(_ (/ magit-todos-max-items (* depth 2)))))
;; HACK: We have to do this manually because the set-visibility-hook doesn't work.
(magit-section-hide section)
;; Not hidden: show section manually (necessary for some reason)
(magit-section-show section)))))
(defun magit-todos--skip-section (condition)
"Move past the section matching CONDITION.
See `magit-section-match'."
(goto-char (point-min))
(cl-loop until (magit-section-match condition)
do (magit-section-forward))
(cl-loop until (not (magit-section-match condition))
do (condition-case nil
;; `magit-section-forward' raises an error when there are no more sections.
(magit-section-forward)
(error (progn
(goto-char (1- (point-max)))
(cl-return))))))
(cl-defun magit-todos--line-item (regexp &optional filename)
"Return item on current line, parsing current buffer with REGEXP.
FILENAME is added to the item as its filename. Sets match data.
This should be called in a process's output buffer from one of
the async callback functions. The calling function should
advance to the next line."
(let ((case-fold-search magit-todos-ignore-case))
(when (re-search-forward regexp (line-end-position) t)
(make-magit-todos-item :filename (or filename
(match-string 8))
:line (--when-let (match-string 2)
(string-to-number it))
:column (--when-let (match-string 3)
(string-to-number it))
:position (--when-let (match-string 9)
(string-to-number it))
:org-level (match-string 1)
:keyword (match-string 4)
:suffix (match-string 6)
:description (match-string 5)))))
(defun magit-todos--keyword-face (keyword)
"Return face for KEYWORD."
;; TODO(alphapapa): Instead of upcasing here, upcase in the lookup, so it can still be displayed
;; non-uppercase. Preserving the distinction might be useful.
(when magit-todos-ignore-case
(setq keyword (upcase keyword)))
(let ((face (assoc-default keyword hl-todo-keyword-faces #'string=)))
(cl-typecase face
(string (list :inherit 'hl-todo :foreground face))
(t face))))
(defun magit-todos--fontify-like-in-org-mode (s &optional odd-levels)
"Fontify string S like in Org-mode.
`org-fontify-like-in-org-mode' is a very, very slow function
because it creates a new temporary buffer and runs `org-mode' for
every string it fontifies. This function reuses a single
invisible buffer and only runs `org-mode' when the buffer is
created."
(let ((buffer (get-buffer " *magit-todos--fontify-like-in-org-mode*")))
(unless buffer
(setq buffer (get-buffer-create " *magit-todos--fontify-like-in-org-mode*"))
(with-current-buffer buffer
(buffer-disable-undo)
(org-mode)))
(with-current-buffer buffer
(erase-buffer)
(insert s)
(let ((org-odd-levels-only odd-levels))
(font-lock-ensure)
(buffer-string)))))
(defun magit-todos-item-first-path-component (item)
"Return ITEM's first directory.
This assumes that ITEM's filename is already set to a path
relative to the repo's directory (i.e. this would not be very
useful with absolute paths)."
(car (f-split (magit-todos-item-filename item))))
(cl-defun magit-todos--async-start-process (name &key command finish-func)
"Start the executable PROGRAM asynchronously. See `async-start'.
PROGRAM is passed PROGRAM-ARGS, calling FINISH-FUNC with the
process object when done. If FINISH-FUNC is nil, the future
object will return the process object when the program is
finished. Set DEFAULT-DIRECTORY to change PROGRAM's current
working directory.
This is a copy of `async-start-process' that does not override
`process-connection-type'. It also uses keyword arguments."
(declare (indent defun))
;; TODO: Drop this function when possible. See
;; .
(let* ((args (cdr command))
(command (car command))
(buf (generate-new-buffer (concat " *" name "*")))
(proc (apply #'start-file-process name buf command args)))
(with-current-buffer buf
(set-process-query-on-exit-flag proc nil)
(set (make-local-variable 'async-callback) finish-func)
(set-process-sentinel proc #'magit-todos--async-when-done)
(unless (string= name "emacs")
(set (make-local-variable 'async-callback-for-process) t))
proc)))
(defun magit-todos--async-when-done (proc &optional _change)
"Process sentinel used to retrieve the value from the child process.
This is a copy of `async-when-done' that does not raise an error
if the process's buffer has already been deleted."
;; I wish it weren't necessary to copy this function here, but at the moment it seems like the
;; only reasonable way to work around this problem of `async-when-done' trying to select deleted
;; buffers. I already tried not deleting the buffers, but then I got bug reports about that and
;; had to revert it. I don't know if I'm encountering a bug in my code, in `async', or in Emacs
;; itself, because it seems that `async-when-done' is being called on the wrong buffers: When I'm
;; connected with `matrix-client', and when I have a Magit status buffer opened with
;; `magit-todos-mode' active, then when one of the `url' process buffers from Matrix gets its
;; sentinel called, I get an error from `async-when-done' trying to select the already-deleted
;; `rg' scanner buffer! It's as if Emacs is mixing up the process buffers. I really don't know
;; what's going on. But maybe I can work around it by copying this function and checking whether
;; the process's buffer is alive.
;; NOTE: TRAMP processes seem to have the status `signal' instead of
;; `exit'. I can't find documentation as to why.
(when (and (memq (process-status proc) '(exit signal))
(buffer-live-p (process-buffer proc)))
(with-current-buffer (process-buffer proc)
(let ((async-current-process proc))
;; TRAMP processes seem to have the exit status 9 instead of
;; 0. I can't find documentation or code about it.
(if (memq (process-exit-status proc) '(0 9))
(if async-callback-for-process
(if async-callback
(prog1
(funcall async-callback proc)
(unless async-debug
(kill-buffer (current-buffer))))
(set (make-local-variable 'async-callback-value) proc)
(set (make-local-variable 'async-callback-value-set) t))
(goto-char (point-max))
(backward-sexp)
(async-handle-result async-callback (read (current-buffer))
(current-buffer)))
(set (make-local-variable 'async-callback-value)
(list 'error
(format "Async process '%s' failed with exit code %d"
(process-name proc) (process-exit-status proc))))
(set (make-local-variable 'async-callback-value-set) t))))))
;;;;; Formatters
(defun magit-todos--format-plain (item)
"Return ITEM formatted as from a non-Org file."
(format "%s%s %s"
(propertize (magit-todos-item-keyword item)
'face (magit-todos--keyword-face (magit-todos-item-keyword item)))
(or (magit-todos-item-suffix item) "")
(or (magit-todos-item-description item) "")))
(defun magit-todos--format-org (item)
"Return ITEM formatted as from an Org file."
(magit-todos--fontify-like-in-org-mode
(concat (magit-todos-item-org-level item) " "
(magit-todos-item-keyword item) " "
(magit-todos-item-description item))))
;;;;; Sorting
(defun magit-todos--sort (items)
"Return ITEMS sorted according to `magit-todos-sort-order'."
(dolist (fn (reverse magit-todos-sort-order) items)
(setq items (sort items fn))))
(defun magit-todos--sort-by-keyword (a b)
"Return non-nil if A's keyword is before B's in `magit-todos-keywords-list'."
(cl-flet ((keyword-index (keyword)
(or (-elem-index keyword magit-todos-keywords-list) 0)))
(< (keyword-index (magit-todos-item-keyword a))
(keyword-index (magit-todos-item-keyword b)))))
(defun magit-todos--sort-by-position (a b)
"Return non-nil if A's position in its file is before B's."
(let ((a-position (or (magit-todos-item-position a)
(magit-todos-item-line a)))
(b-position (or (magit-todos-item-position b)
(magit-todos-item-line b))))
(< a-position b-position)))
(defun magit-todos--sort-by-filename (a b)
"Return non-nil if A's filename is `string<' B's."
(string< (magit-todos-item-filename a)
(magit-todos-item-filename b)))
(defun magit-todos--sort-by-suffix (a b)
"Return non-nil if A's suffix is `string<' B's."
(string< (magit-todos-item-suffix a)
(magit-todos-item-suffix b)))
;;;; Scanners
(cl-defmacro magit-todos-defscanner (name &key test command results-regexp
(callback (function 'magit-todos--scan-callback)))
"Define a `magit-todos' scanner named NAME.
NAME is a string, which may contain spaces. It is only used for
descriptive purposes.
TEST is an unquoted sexp which is used to determine whether the
scanner is usable. In most cases, it should use
`executable-find' to look for the scanner command.
COMMAND is a sexp which should evaluate to the scanner command,
i.e. a list of strings to be eventually passed to
`start-process'. Nil elements are removed, numbers are converted
to strings, and nested lists are flattened into a single list.
It is evaluated each time the scanner is run.
Within the COMMAND list these variables are available:
`depth': When non-nil, an integer, which is the depth that should
be passed to the scanner's max-depth option (i.e. `magit-todos-depth').
`directory': The directory in which the scan should be run.
`extra-args': The value of the customization variable
\"magit-todos-NAME-extra-args\" (see below).
`keywords': List of item keywords defined in
`magit-todos-keywords-list'.
`search-regexp-pcre': PCRE-compatible regular expression to be passed
to the scanner process.
`search-regexp-elisp': Emacs regular expression, which may be
used for scanners written as Emacs Lisp functions.
RESULTS-REGEXP is an optional string or unquoted sexp which is
used to match results in the scanner process's output buffer.
Typically this will be a sexp which calls `rx-to-string'. It is
evaluated each time the scanner is run. If nil, the appropriate
default is used which matches results in the form:
FILENAME:LINE:MATCH
Where MATCH may also match Org outline heading stars when
appropriate. Custom regexps may also match column numbers or
byte offsets in the appropriate numbered groups; see
`make-magit-todos-item'.
CALLBACK is called to process the process's output buffer.
Normally the default should be used, which inserts items into the
Magit status buffer which is passed as an argument to the scanner
function.
The macro defines the following:
\"magit-todos-NAME-extra-args\": A customization setting, a list
of strings to be passed to the scanner as extra arguments.
\"magit-todos--scan-with-NAME\": The function which runs the
scanner command.
It also adds the scanner to the customization variable
`magit-todos-scanner', and to the variable
`magit-todos-scanners' (which is used to set
`magit-todos-scanner' by calling `magit-todos--choose-scanner')."
;; TODO: Try to obviate the -scanners variable, let --choose-scanner use the
;; custom-type of -scanner directly. Maybe, anyway--I don't want to ugly up the UI
;; for users.
(declare (indent defun) (debug (stringp [&rest &or [":test" def-form]
[":command" def-form]
[":results-regexp" [&or stringp def-form]]])))
(let* ((name-without-spaces (s-replace " " "-" name))
(scan-fn-name (concat "magit-todos--scan-with-" name-without-spaces))
(scan-fn-symbol (intern scan-fn-name))
(extra-args-var (intern (format "magit-todos-%s-extra-args" name-without-spaces))))
`(progn
(defcustom ,extra-args-var nil
,(format "Extra arguments passed to %s." name)
:type '(repeat string))
;; NOTE: Both the macro and the macro-defined function have `callback' arguments. Pay attention to unquoting.
;; FIXME: That is confusing.
(cl-defun ,scan-fn-symbol (&key magit-status-buffer directory depth heading sync callback)
,(format "Scan for to-dos with %s, then call `%s'.
MAGIT-STATUS-BUFFER is what it says. DIRECTORY is the directory in which to run the scan. DEPTH should be an integer, typically the value of `magit-todos-depth'. HEADING is passed to `%s'.
When SYNC is nil, the scanner process is returned, and CALLBACK
is a function which is called by the process sentinel with one
argument, a list of match items.
When SYNC is non-nil, match items are returned."
name callback callback)
(let* ((process-connection-type 'pipe)
(directory (f-relative directory default-directory))
(extra-args (when ,extra-args-var
(--map (s-split (rx (1+ space)) it 'omit-nulls)
,extra-args-var)))
(keywords magit-todos-keywords-list)
(search-regexp-elisp (rx-to-string
`(or
;; Org item
(seq bol (group (1+ "*"))
(1+ blank)
(group (or ,@keywords))
(1+ space)
(group (1+ not-newline)))
;; Non-Org
(seq (or bol (1+ blank))
(group (or ,@keywords))
(regexp ,magit-todos-keyword-suffix)
(optional (1+ blank)
(group (1+ not-newline)))))))
(search-regexp-pcre (rxt-elisp-to-pcre search-regexp-elisp))
(results-regexp (or ,results-regexp
(rx-to-string
`(seq bol
;; Filename
(group-n 8 (1+ (not (any ":")))) ":"
;; Line
(group-n 2 (1+ digit)) ":"
(or
;; Org item
(seq (group-n 1 (1+ "*"))
(1+ blank)
(group-n 4 (or ,@keywords))
(1+ blank)
(group-n 5 (1+ not-newline)))
;; Non-Org
(seq (optional (1+ not-newline))
(group-n 4 (or ,@keywords))
(optional (group-n 6 (regexp ,magit-todos-keyword-suffix)))
(optional (1+ blank))
(optional (group-n 5 (1+ not-newline)))))))))
(command (-flatten
(-non-nil
(list (when magit-todos-nice
(list "nice" "-n5"))
,command)))))
;; Convert any numbers in command to strings (e.g. depth).
(cl-loop for elt in-ref command
when (numberp elt)
do (setf elt (number-to-string elt)))
;; Run command.
(if sync
;; Synchronous: return matching items.
(with-temp-buffer
(unless (= 0 (apply #'call-process (car command) nil (current-buffer) nil
(cdr command)))
(user-error (concat (car command) " failed")))
(magit-todos--buffer-items results-regexp))
;; Async: return process.
(magit-todos--async-start-process ,scan-fn-name
:command command
;; NOTE: This callback chain.
:finish-func (apply-partially ,callback
:callback callback
:magit-status-buffer magit-status-buffer
:results-regexp results-regexp
:search-regexp-elisp search-regexp-elisp
:heading heading
:exclude-globs magit-todos-exclude-globs
:process))))) ; Process is appended to the list.
(magit-todos--add-to-custom-type 'magit-todos-scanner
(list 'const :tag ,name #',scan-fn-symbol))
(add-to-list 'magit-todos-scanners
(list (cons 'name ,name)
(cons 'function #',scan-fn-symbol)
(cons 'test ',test))
'append))))
;; NOTE: These scanners handle the max-depth option differently. git-grep seems to handle it in the
;; most useful way, with a setting of 0 meaning to look no deeper than the current directory, and a
;; setting of 1 searching directories one level deeper. In comparison, rg and find effectively
;; subtract one from the value, as a setting of 0 returns no results, and a setting of 1 searches
;; only the current directory (which means that when the max-depth is set to 0, the whole command is
;; essentially a no-op, which is pointless). Since we want `magit-todos-depth' to behave
;; consistently with all scanners, we will treat it the way git-grep does, and for the other
;; scanners we'll add one to its value.
(magit-todos-defscanner "rg"
:test (executable-find "rg")
:command (list "rg" "--no-heading" "--line-number"
(when depth
(list "--maxdepth" (1+ depth)))
(when magit-todos-ignore-case
"--ignore-case")
(when magit-todos-exclude-globs
(--map (list "--glob" (concat "!" it))
magit-todos-exclude-globs))
extra-args search-regexp-pcre directory))
(magit-todos-defscanner "git grep"
:test (string-match "--perl-regexp" (shell-command-to-string "git grep --magit-todos-testing-git-grep"))
:command (list "git" "--no-pager" "grep"
"--full-name" "--no-color" "-n"
(when depth
(list "--max-depth" depth))
(when magit-todos-ignore-case
"--ignore-case")
"--perl-regexp"
"-e" search-regexp-pcre
extra-args "--" directory
(when magit-todos-exclude-globs
(--map (concat ":!" it)
magit-todos-exclude-globs))))
(magit-todos-defscanner "git diff"
;; NOTE: This scanner implements the regexp *searching* in elisp rather than in the
;; external process because, unlike "git grep", "git diff" does not support PCRE.
:test t
:command (progn
;; Silence byte-compiler warnings about these vars we don't use in this scanner.
(ignore search-regexp-elisp search-regexp-pcre extra-args directory depth)
(list "git" "--no-pager" "diff" "--no-color" "-U0"
(-> "git merge-base HEAD "
(concat magit-todos-branch-list-merge-base-ref)
shell-command-to-string
string-trim)))
:callback 'magit-todos--git-diff-callback)
(magit-todos-defscanner "find|grep"
;; NOTE: The filenames output by find|grep have a leading "./". I don't expect this scanner to be
;; used much, if at all, so I'm not going to go to the trouble to fix this now.
:test (string-match "--perl-regexp" (shell-command-to-string "grep --help"))
:command (let* ((grep-find-template (progn
(unless grep-find-template
(grep-compute-defaults))
(->> grep-find-template
(s-replace " grep " " grep -b -E ")
(s-replace " -nH " " -H "))))
(_ (when depth
(setq grep-find-template
(s-replace " " (concat " -maxdepth " (1+ depth) " ")
grep-find-template)))))
;; Modified from `rgrep-default-command'
(list "find" directory
(list (when grep-find-ignored-directories
(list "-type" "d"
"(" "-path"
(-interpose (list "-o" "-path")
(-non-nil (--map (cond ((stringp it)
(concat "*/" it))
((consp it)
(and (funcall (car it) it)
(concat "*/" (cdr it)))))
grep-find-ignored-directories)))
")" "-prune"))
(when grep-find-ignored-files
(list "-o" "-type" "f"
"(" "-name"
(-interpose (list "-o" "-name")
(--map (cond ((stringp it) it)
((consp it) (and (funcall (car it) it)
(cdr it))))
grep-find-ignored-files))
")" "-prune"))
(when magit-todos-exclude-globs
(list "-o" "("
(--map (list "-iname" it)
magit-todos-exclude-globs)
")" "-prune")))
(list "-o" "-type" "f")
;; NOTE: This uses "grep -P", i.e. "Interpret the pattern as a
;; Perl-compatible regular expression (PCRE). This is highly
;; experimental and grep -P may warn of unimplemented features." But it
;; does seem to work properly, at least on GNU grep. Using "grep -E"
;; with this PCRE regexp doesn't work quite right, as it doesn't match
;; all the keywords, but pcre2el doesn't convert to "extended regular
;; expressions", so this will have to do. Maybe we should test whether
;; the version of grep installed supports "-P".
;; NOTE: For some reason, when "-execdir" is used, the callback function is never
;; called, even though the process terminates and its buffer has the correct
;; output. It works correctly when "-exec" is used, so we use that.
(list "-exec" "grep" "-bPH"
(when magit-todos-ignore-case
"--ignore-case")
extra-args
search-regexp-pcre "{}" "+"))))
;;;;; Set scanner default value
;; Now that all the scanners have been defined, we can set the value.
(custom-reevaluate-setting 'magit-todos-scanner)
;;;; Helm/Ivy
;; These add optional support for Helm and Ivy. This code does not require
;; Helm or Ivy to be installed; it is only called after one of them is loaded.
(declare-function helm-make-source "ext:helm-source")
(with-eval-after-load 'helm
(defvar helm-magit-todos-source
;; We use `helm-make-source' instead of `helm-make-sync-source', which is a
;; macro, which won't be present if the user doesn't have Helm installed.
(helm-make-source "helm-magit-todos" 'helm-source-sync
:candidates #'magit-todos-candidates
:action (lambda (item)
(magit-todos-jump-to-item :item item))))
(defun helm-magit-todos ()
"Display `magit-todos' items with Helm.
Note that this uses `magit-todos-items-cache' when a Magit status
buffer is available for the repository directory, in which case
the cache is not updated from this command."
(interactive)
(helm :sources '(helm-magit-todos-source))))
(declare-function ivy-read "ext:ivy")
(with-eval-after-load 'ivy
(defvar ivy-magit-todos-history nil
"History for `ivy-magit-todos'.")
(defun ivy-magit-todos ()
"Display `magit-todos' items with Ivy.
Note that this uses `magit-todos-items-cache' when a Magit status
buffer is available for the repository directory, in which case
the cache is not updated from this command."
(interactive)
(ivy-read "TODOs: " (magit-todos-candidates)
:action (lambda (item)
(magit-todos-jump-to-item :item (cdr item)))
:history 'ivy-magit-todos-history
:caller 'ivy-magit-todos)))
;;;;; Support
;; These functions are used by both Helm and Ivy.
(defsubst magit-todos-item-cons (item)
"Return ITEM as a (DISPLAY . ITEM) pair.
Used for e.g. Helm and Ivy."
(cons (concat (magit-todos-item-filename item) " "
(funcall (if (s-suffix? ".org" (magit-todos-item-filename item))
#'magit-todos--format-org
#'magit-todos--format-plain)
item))
item))
(defun magit-todos-candidates ()
"Return list of (DISPLAY . ITEM) candidates for e.g. Helm and Ivy."
;; MAYBE: Update the cache appropriately from here.
(if-let* ((magit-status-buffer (magit-get-mode-buffer 'magit-status-mode))
(items (buffer-local-value 'magit-todos-item-cache magit-status-buffer)))
;; Use cached items.
(cl-loop for item in items
collect (magit-todos-item-cons item))
;; No cached items: run scan.
(when-let* ((items (funcall magit-todos-scanner :sync t
:directory default-directory
:depth magit-todos-depth)))
(cl-loop for item in items
collect (magit-todos-item-cons item)))))
;;;; Footer
(provide 'magit-todos)
;;; magit-todos.el ends here
magit-todos-1.5.3/LICENSE 0000644 0001750 0001750 00000104513 13747632621 014625 0 ustar dogsleg dogsleg GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
Copyright (C)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
Copyright (C)
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
.
magit-todos-1.5.3/notes.org 0000644 0001750 0001750 00000007566 13747632621 015473 0 ustar dogsleg dogsleg #+PROPERTY: LOGGING nil
* Ideas
** MAYBE Convert glob symbols to strings
It's a bit awkward and confusing for users who use ~add-dir-local-variable~ to have to remember to type quotation marks for the glob value when setting ~magit-todos-exclude-globs~. We could convert symbols to strings when building commands, so users wouldn't have to remember this.
** TODO Avoid refreshing section too often [1/2]
On large repos, updating the section from scratch takes some time. It would be good to avoid doing this too often in large repos.
*** DONE Option for when to refresh it
There should be an option for how often to refresh the to-dos section:
+ =always=
+ =manually=
+ a number of seconds (not automatically, but whenever the status buffer is refreshed and this many seconds have elapsed)
=memoize= can be used to implement this, probably with a proxy function to handle always/manually.
**** Implementation
+ [X] ~defvar magit-todos-updating~ :: Whether the items are being updated now.
+ [X] =defcustom magit-todos-update-automatically= :: Whether or how often to update the items automatically.
+ [X] ~defvar-local magit-todos-last-update-time~ :: When the items were last updated. A time value as returned by ~(current-time)~.
+ [X] ~defun magit-todos-update~ :: Called to do a new scan, update the cache, and insert the section. If the section already exists, it must be removed first.
+ [X] ~defun magit-todos--delete-section IDENT~ :: Called to delete the specified section from the status buffer.
+ [X] =defvar-local magit-todos-item-cache= :: Stores the items found by the scan function.
+ [X] =defun magit-todos--insert-items= :: Modify to call ~magit-todos--insert-items-callback~ directly with cached items when automatic updates are disabled.
+ [X] ~defun magit-todos--insert-items-callback~ :: Modify to:
- [X] Cache items when necessary
- [X] Show that section requires manual updating when no items are cached.
*** TODO Set option automatically in large repos
The parsing/insertion should be timed, and if it takes too long, the previous option should be automatically set to timeout or manual.
** TODO UI like magit-popup [2/5]
*** DONE Define scanners with a macro
This will make the changes much simpler. See =defscanner-macro= branch.
*** DONE Build regexps on scan invocation
*** TODO Choose between ~magit-popup~ and [[https://github.com/magit/transient][transient]]
*** TODO Implement UI
*** TODO Optionally set dir-local variables with it
** MAYBE Restore timeout feature
Now that we're using external scanners, I'm not sure this is important. And if we implement a feature to avoid scanning too often in big repos, it probably won't be.
** MAYBE Option to limit depth of Org items
e.g. I don't necessarily need to see each subtask under "Ignore files/directories in scanners".
** TODO Ignore files/directories in scanners
*** TODO Add default globs
e.g. these from this old var:
#+BEGIN_SRC elisp
(defcustom magit-todos-ignore-file-suffixes '(".org_archive" "#")
"Ignore files with these suffixes."
:type '(repeat string))
#+END_SRC
*** TODO rg
Should probably use =--glob=:
#+BEGIN_EXAMPLE
-g, --glob ...
Include or exclude files and directories for searching that match the given
glob. This always overrides any other ignore logic. Multiple glob flags may be
used. Globbing rules match .gitignore globs. Precede a glob with a ! to exclude
it.
--iglob ...
Include or exclude files and directories for searching that match the given
glob. This always overrides any other ignore logic. Multiple glob flags may be
used. Globbing rules match .gitignore globs. Precede a glob with a ! to exclude
it. Globs are matched case insensitively.
#+END_EXAMPLE
*** TODO ag
*** TODO git-grep
*** TODO find-grep
magit-todos-1.5.3/screenshots/ 0000755 0001750 0001750 00000000000 13747632621 016154 5 ustar dogsleg dogsleg magit-todos-1.5.3/screenshots/emacs-grouped-by-path.png 0000644 0001750 0001750 00000157201 13747632621 022765 0 ustar dogsleg dogsleg PNG
IHDR Y sBITO pHYs + $IDATx_gg3=[L̙~{{{f9>}:7zEFQ(h@" (}ְ,YT$ ߪ$;.7z UuUUIu}~W >/~]a1%