Replace */tasks commands w/ magit-todos-list

If we want ivy/helm interfaces to it, we should use magit-todos as a
backend.
This commit is contained in:
Henrik Lissner 2019-11-15 22:12:45 -05:00
parent 03e9dc1daf
commit bd4755123f
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
6 changed files with 2 additions and 119 deletions

View file

@ -157,88 +157,6 @@ If ARG (universal argument), open selection in other-window."
(interactive)
(+ivy--switch-buffer nil t))
(defun +ivy--tasks-candidates (tasks)
"Generate a list of task tags (specified by `+ivy-task-tags') for
`+ivy/tasks'."
(let* ((max-type-width
(cl-loop for task in +ivy-task-tags maximize (length (car task))))
(max-desc-width
(cl-loop for task in tasks maximize (length (cl-cdadr task))))
(max-width (max (+ max-desc-width 3)
25)))
(cl-loop
with fmt = (format "%%-%ds %%-%ds%%s:%%s" max-type-width max-width)
for alist in tasks
collect
(let-alist alist
(list (format fmt
(propertize .type 'face (cdr (assoc .type +ivy-task-tags)))
(substring .desc 0 (min max-desc-width (length .desc)))
(propertize (abbreviate-file-name .file) 'face 'font-lock-keyword-face)
(propertize .line 'face 'font-lock-constant-face))
.type .file .line)))))
(defun +ivy--tasks (target)
(let (case-fold-search)
(cl-loop with task-tags = (mapcar #'car +ivy-task-tags)
with out =
(cdr
(apply #'doom-call-process
(append
(or (when-let (bin (executable-find "rg"))
(list bin "--line-number"))
(when-let (bin (executable-find "ag"))
(list bin "--numbers"))
(user-error "ripgrep & the_silver_searcher are unavailable"))
(list "-H" "-S" "--no-heading" "--"
(concat "\\s("
(string-join task-tags "|")
")([\\s:]|\\([^)]+\\):?)")
target))))
for x in (and out (split-string out "\n" t))
when (condition-case-unless-debug ex
(string-match
(concat "^\\([^:]+\\):\\([0-9]+\\):.+\\("
(string-join task-tags "\\|")
"\\):?\\s-*\\(.+\\)")
x)
(error
(print! (red "Error matching task in file: (%s) %s")
(error-message-string ex)
(car (split-string x ":")))
nil))
collect `((type . ,(match-string 3 x))
(desc . ,(match-string 4 x))
(file . ,(match-string 1 x))
(line . ,(match-string 2 x))))))
(defun +ivy--tasks-open-action (x)
"Jump to the file and line of the current task."
(cl-destructuring-bind (_label type file line) x
(with-ivy-window
(find-file (expand-file-name file (doom-project-root)))
(goto-char (point-min))
(forward-line (1- (string-to-number line)))
(when (search-forward type (line-end-position) t)
(backward-char (length type)))
(recenter))))
;;;###autoload
(defun +ivy/tasks (&optional arg)
"Search through all TODO/FIXME tags in the current project. If ARG, only
search current file. See `+ivy-task-tags' to customize what this searches for."
(interactive "P")
(ivy-read (format "Tasks (%s): "
(if arg
(concat "in: " (file-relative-name buffer-file-name))
"project"))
(let ((tasks (+ivy--tasks (if arg buffer-file-name (doom-project-root)))))
(unless tasks
(user-error "No tasks in your project! Good job!"))
(+ivy--tasks-candidates tasks))
:action #'+ivy--tasks-open-action
:caller '+ivy/tasks))
;;;###autoload
(defun +ivy/woccur ()
"Invoke a wgrep buffer on the current ivy results, if supported."