+ivy/tasks: ag as a fallback
This commit is contained in:
parent
a4bacca812
commit
5c34732266
1 changed files with 40 additions and 37 deletions
|
@ -71,46 +71,49 @@ limit to buffers in the current workspace."
|
||||||
"Generate a list of task tags (specified by `+ivy-task-tags') for
|
"Generate a list of task tags (specified by `+ivy-task-tags') for
|
||||||
`+ivy/tasks'."
|
`+ivy/tasks'."
|
||||||
(let* ((max-type-width (seq-max (mapcar #'length (mapcar #'car +ivy-task-tags))))
|
(let* ((max-type-width (seq-max (mapcar #'length (mapcar #'car +ivy-task-tags))))
|
||||||
(max-desc-width (seq-max (mapcar #'length (mapcar #'cadr tasks))))
|
(max-desc-width (seq-max (mapcar #'length (mapcar #'cl-cdadr tasks))))
|
||||||
(max-width (max 25 (min (- (window-width) (+ max-type-width 1))
|
(max-width (max 25 (min (- (frame-width) (+ max-type-width 1))
|
||||||
(seq-max (mapcar #'length (mapcar #'cadr tasks))))))
|
max-desc-width)))
|
||||||
(fmt (format "%%-%ds %%-%ds%%s%%s:%%s" max-type-width max-width)))
|
(fmt (format "%%-%ds %%-%ds%%s%%s:%%s" max-type-width max-desc-width))
|
||||||
(mapcar (lambda (task)
|
lines)
|
||||||
(let ((file (nth 2 task))
|
(dolist (alist tasks (nreverse lines))
|
||||||
(line (nth 3 task))
|
(let-alist alist
|
||||||
(type (nth 0 task))
|
(push (format fmt
|
||||||
(desc (nth 1 task)))
|
(propertize .type 'face (cdr (assoc .type +ivy-task-tags)))
|
||||||
(format fmt
|
(substring .desc 0 (min max-desc-width (length .desc)))
|
||||||
(propertize type 'face (cdr (assoc type +ivy-task-tags)))
|
(propertize " | " 'face 'font-lock-comment-face)
|
||||||
(substring desc 0 (min max-width (length desc)))
|
(propertize (abbreviate-file-name .file) 'face 'font-lock-keyword-face)
|
||||||
(propertize " | " 'face 'font-lock-comment-face)
|
(propertize .line 'face 'font-lock-constant-face))
|
||||||
(propertize (abbreviate-file-name file) 'face 'font-lock-keyword-face)
|
lines)))))
|
||||||
(propertize line 'face 'font-lock-constant-face))))
|
|
||||||
tasks)))
|
|
||||||
|
|
||||||
(defun +ivy--tasks (target)
|
(defun +ivy--tasks (target)
|
||||||
(let (case-fold-search)
|
(let (case-fold-search)
|
||||||
(mapcar (lambda (x)
|
(delq
|
||||||
(save-match-data
|
nil
|
||||||
(string-match (concat "^\\([^:]+\\):\\([0-9]+\\):.+\\("
|
(mapcar (lambda (x)
|
||||||
(string-join (mapcar #'car +ivy-task-tags) "\\|")
|
(save-match-data
|
||||||
"\\):?\\s-*\\(.+\\)")
|
(when (string-match (concat "^\\([^:]+\\):\\([0-9]+\\):.+\\("
|
||||||
x)
|
(string-join (mapcar #'car +ivy-task-tags) "\\|")
|
||||||
(let ((file (match-string 1 x))
|
"\\):?\\s-*\\(.+\\)")
|
||||||
(line (match-string 2 x))
|
x)
|
||||||
(type (match-string 3 x))
|
`((type . ,(match-string 3 x))
|
||||||
(desc (match-string 4 x)))
|
(desc . ,(match-string 4 x))
|
||||||
(list type desc file line))))
|
(file . ,(match-string 1 x))
|
||||||
(split-string
|
(line . ,(match-string 2 x))))))
|
||||||
(shell-command-to-string
|
(let ((command (or (let ((bin (executable-find "rg")))
|
||||||
(format "rg -H -S --no-heading --line-number %s %s"
|
(and bin (concat bin " --line-number")))
|
||||||
(concat " -- "
|
(let ((bin (executable-find "ag")))
|
||||||
(shell-quote-argument
|
(and bin (concat bin " --numbers")))
|
||||||
(concat "\\s("
|
(error "Neither ripgrep or the_silver_searcher is available")))
|
||||||
(string-join (mapcar #'car +ivy-task-tags) "|")
|
(args (concat " -- "
|
||||||
")([\\s:]|\\([^)]+\\):?)")))
|
(shell-quote-argument
|
||||||
target))
|
(concat "\\s("
|
||||||
"\n" t))))
|
(string-join (mapcar #'car +ivy-task-tags) "|")
|
||||||
|
")([\\s:]|\\([^)]+\\):?)")))))
|
||||||
|
(when-let (out (shell-command-to-string
|
||||||
|
(format "%s -H -S --no-heading %s %s"
|
||||||
|
command args target)))
|
||||||
|
(split-string out "\n" t)))))))
|
||||||
|
|
||||||
(defun +ivy--tasks-open-action (x)
|
(defun +ivy--tasks-open-action (x)
|
||||||
"Jump to the file and line of the current task."
|
"Jump to the file and line of the current task."
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue