From bd4755123f2f1f710a05090dedc040140b9f1e90 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Fri, 15 Nov 2019 22:12:45 -0500 Subject: [PATCH] Replace */tasks commands w/ magit-todos-list If we want ivy/helm interfaces to it, we should use magit-todos as a backend. --- modules/completion/helm/autoload/helm.el | 6 -- modules/completion/ivy/autoload/ivy.el | 82 ---------------------- modules/completion/ivy/config.el | 20 ------ modules/config/default/+emacs-bindings.el | 2 +- modules/config/default/+evil-bindings.el | 2 +- modules/config/default/autoload/default.el | 9 --- 6 files changed, 2 insertions(+), 119 deletions(-) diff --git a/modules/completion/helm/autoload/helm.el b/modules/completion/helm/autoload/helm.el index c132b29a2..3859281be 100644 --- a/modules/completion/helm/autoload/helm.el +++ b/modules/completion/helm/autoload/helm.el @@ -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 diff --git a/modules/completion/ivy/autoload/ivy.el b/modules/completion/ivy/autoload/ivy.el index 4332aafaa..a698d31b0 100644 --- a/modules/completion/ivy/autoload/ivy.el +++ b/modules/completion/ivy/autoload/ivy.el @@ -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." diff --git a/modules/completion/ivy/config.el b/modules/completion/ivy/config.el index f12ddf55d..669e16eb4 100644 --- a/modules/completion/ivy/config.el +++ b/modules/completion/ivy/config.el @@ -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'.") diff --git a/modules/config/default/+emacs-bindings.el b/modules/config/default/+emacs-bindings.el index 4b6bf75af..e63e544ce 100644 --- a/modules/config/default/+emacs-bindings.el +++ b/modules/config/default/+emacs-bindings.el @@ -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 diff --git a/modules/config/default/+evil-bindings.el b/modules/config/default/+evil-bindings.el index ebc0c964b..4450d4003 100644 --- a/modules/config/default/+evil-bindings.el +++ b/modules/config/default/+evil-bindings.el @@ -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) ;;; q --- quit/session diff --git a/modules/config/default/autoload/default.el b/modules/config/default/autoload/default.el index 08cf7b8cf..ad49e2f6d 100644 --- a/modules/config/default/autoload/default.el +++ b/modules/config/default/autoload/default.el @@ -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."