Refactor +ivy/tasks

Just realized ivy passes the candidate in its original data structure to
its handlers.
This commit is contained in:
Henrik Lissner 2019-05-19 02:14:06 -04:00
parent 39d4fa2256
commit d3cb394ce4
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -153,19 +153,19 @@ If ARG (universal argument), open selection in other-window."
(cl-loop for task in +ivy-task-tags maximize (length (car task)))) (cl-loop for task in +ivy-task-tags maximize (length (car task))))
(max-desc-width (max-desc-width
(cl-loop for task in tasks maximize (length (cl-cdadr task)))) (cl-loop for task in tasks maximize (length (cl-cdadr task))))
(max-width (max (- (frame-width) (1+ max-type-width) max-desc-width) (max-width (max (+ max-desc-width 3)
25))) 25)))
(cl-loop (cl-loop
with fmt = (format "%%-%ds %%-%ds%%s%%s:%%s" max-type-width max-width) with fmt = (format "%%-%ds %%-%ds%%s:%%s" max-type-width max-width)
for alist in tasks for alist in tasks
collect collect
(let-alist alist (let-alist alist
(format fmt (list (format fmt
(propertize .type 'face (cdr (assoc .type +ivy-task-tags))) (propertize .type 'face (cdr (assoc .type +ivy-task-tags)))
(substring .desc 0 (min max-desc-width (length .desc))) (substring .desc 0 (min max-desc-width (length .desc)))
(propertize " | " 'face 'font-lock-comment-face) (propertize (abbreviate-file-name .file) 'face 'font-lock-keyword-face)
(propertize (abbreviate-file-name .file) 'face 'font-lock-keyword-face) (propertize .line 'face 'font-lock-constant-face))
(propertize .line 'face 'font-lock-constant-face)))))) .type .file .line)))))
(defun +ivy--tasks (target) (defun +ivy--tasks (target)
(let* (case-fold-search (let* (case-fold-search
@ -203,16 +203,14 @@ If ARG (universal argument), open selection in other-window."
(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."
(let ((location (cadr (split-string x " | "))) (cl-destructuring-bind (label type file line) x
(type (car (split-string x " ")))) (with-ivy-window
(cl-destructuring-bind (file line) (split-string location ":") (find-file (expand-file-name file (doom-project-root)))
(with-ivy-window (goto-char (point-min))
(find-file (expand-file-name file (doom-project-root))) (forward-line (1- (string-to-number line)))
(goto-char (point-min)) (when (search-forward type (line-end-position) t)
(forward-line (1- (string-to-number line))) (backward-char (length type)))
(search-forward type (line-end-position) t) (recenter))))
(backward-char (length type))
(recenter)))))
;;;###autoload ;;;###autoload
(defun +ivy/tasks (&optional arg) (defun +ivy/tasks (&optional arg)