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:
parent
03e9dc1daf
commit
bd4755123f
6 changed files with 2 additions and 119 deletions
|
@ -1,11 +1,5 @@
|
|||
;;; completion/helm/autoload/helm.el -*- lexical-binding: t; -*-
|
||||
|
||||
;;;###autoload
|
||||
(defun +helm/tasks (&optional _arg)
|
||||
(interactive "P")
|
||||
;; TODO Implement `+helm/tasks'
|
||||
(error "Not implemented yet"))
|
||||
|
||||
;;;###autoload
|
||||
(defun +helm/projectile-find-file ()
|
||||
"Call `helm-find-files' if called from HOME, otherwise
|
||||
|
|
|
@ -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."
|
||||
|
|
|
@ -7,26 +7,6 @@ When nil, don't preview anything.
|
|||
When non-nil, preview non-virtual buffers.
|
||||
When 'everything, also preview virtual buffers")
|
||||
|
||||
(defvar +ivy-task-tags
|
||||
'(("TODO" . warning)
|
||||
("FIXME" . error)
|
||||
("HACK" . font-lock-constant-face)
|
||||
("REVIEW" . font-lock-keyword-face)
|
||||
("NOTE" . success)
|
||||
("DEPRECATED" . font-lock-doc-face))
|
||||
"An alist of tags for `+ivy/tasks' to include in its search, whose CDR is the
|
||||
face to render it with.")
|
||||
|
||||
(defvar +ivy-project-search-engines '(rg ag)
|
||||
"What search tools for `+ivy/project-search' (and `+ivy-file-search' when no
|
||||
ENGINE is specified) to try, and in what order.
|
||||
|
||||
To disable a particular tool, remove it from this list. To prioritize a tool
|
||||
over others, move it to the front of the list. Later duplicates in this list are
|
||||
silently ignored.
|
||||
|
||||
If you want to already use git-grep or grep, set this to nil.")
|
||||
|
||||
(defvar +ivy-buffer-unreal-face 'font-lock-comment-face
|
||||
"The face for unreal buffers in `ivy-switch-to-buffer'.")
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@
|
|||
(:prefix ("p" . "project")
|
||||
:desc "Find file in other project" "F" #'doom/find-file-in-other-project
|
||||
:desc "Search project" "s" #'+default/search-project
|
||||
:desc "List project tasks" "t" #'+default/project-tasks
|
||||
:desc "List project tasks" "t" #'magit-todos-list
|
||||
:desc "Open project scratch buffer" "x" #'doom/open-project-scratch-buffer
|
||||
:desc "Switch to project scratch buffer" "X" #'doom/switch-to-project-scratch-buffer
|
||||
;; later expanded by projectile
|
||||
|
|
|
@ -541,7 +541,7 @@
|
|||
:desc "Save project files" "s" #'projectile-save-project-buffers
|
||||
:desc "Pop up scratch buffer" "x" #'doom/open-project-scratch-buffer
|
||||
:desc "Switch to scratch buffer" "X" #'doom/switch-to-project-scratch-buffer
|
||||
:desc "List project tasks" "t" #'+default/project-tasks
|
||||
:desc "List project tasks" "t" #'magit-todos-list
|
||||
:desc "Test project" "T" #'projectile-test-project)
|
||||
|
||||
;;; <leader> q --- quit/session
|
||||
|
|
|
@ -73,15 +73,6 @@ If ARG (universal argument), runs `compile' from the current directory."
|
|||
(with-current-buffer buffer
|
||||
(funcall (default-value 'major-mode))))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +default/project-tasks ()
|
||||
"Invokes `+ivy/tasks' or `+helm/tasks', depending on which is available."
|
||||
(interactive)
|
||||
(cond ((featurep! :tools magit)
|
||||
(call-interactively #'magit-todos-list))
|
||||
((featurep! :completion ivy) (+ivy/tasks))
|
||||
((featurep! :completion helm) (+helm/tasks))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +default/newline-above ()
|
||||
"Insert an indented new line before the current one."
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue