summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2016-04-25 00:38:27 -0400
committerKyle Meyer <kyle@kyleam.com>2016-04-25 00:38:27 -0400
commite7da7f59f6cb942feda98b873f5588a625dd73e1 (patch)
tree98f1a8566de41caa4b6567fc87eb2c40063bc5d4 /lisp
parent40b97d223a868f627bfb5489d389e9716d443394 (diff)
downloademacs.d-e7da7f59f6cb942feda98b873f5588a625dd73e1.tar.gz
Add org-grep-buffer-to-list command
Diffstat (limited to 'lisp')
-rw-r--r--lisp/km-org.el44
1 files changed, 44 insertions, 0 deletions
diff --git a/lisp/km-org.el b/lisp/km-org.el
index a778502..6522a99 100644
--- a/lisp/km-org.el
+++ b/lisp/km-org.el
@@ -313,6 +313,50 @@ the buffer widened."
(when (and beg (<= beg (point) end))
(narrow-to-region beg end)))))
+(defun km/org-grep-buffer-to-list ()
+ "Convert `grep-mode' buffer to Org mode list."
+ (interactive)
+ (let ((result-re (rx line-start
+ (group (one-or-more (not (any ":"))))
+ ":"
+ (group (one-or-more digit))
+ ":"
+ (group (one-or-more not-newline))
+ line-end))
+ (dir default-directory)
+ results
+ cmd)
+ (save-excursion
+ (goto-char (point-min))
+ (forward-line 3)
+ (setq cmd (buffer-substring-no-properties (line-beginning-position)
+ (line-end-position)))
+ (forward-line 1)
+ (while (and (not (looking-at-p "\n\\s-*$"))
+ (re-search-forward result-re nil t))
+ (push (list (match-string-no-properties 1)
+ (match-string-no-properties 2)
+ (match-string-no-properties 3))
+ results))
+ (with-current-buffer (get-buffer-create "*Org grep results*")
+ (setq default-directory dir)
+ (erase-buffer)
+ (insert "\n* Results [/]\n\n")
+ (insert (format "Call: %s\n\n" cmd))
+ (pcase-dolist (`(,file ,_ ,text) (nreverse results))
+ (insert (format "- [ ] %s\n"
+ (org-make-link-string
+ (concat "file:" file "::" text)
+ (let ((desc (concat file ":" text)))
+ (if (> (length desc) 72)
+ (substring desc 0 72)
+ desc))))))
+ (org-mode)
+ (org-back-to-heading)
+ (org-update-checkbox-count)
+ (org-show-entry)
+ (pop-to-buffer (current-buffer))))))
+
;;; Agenda