I would like to write a function that scrapes the current buffer for any comments with the word "TODO" and runs org-capture
, saving a link to that TODO comment in a file. The end goal would be sort of a one-stop location for TODO items like some modern IDEs have:
Ideally, I want the link to show the text of the todo comment. So the following buffer:
int main(/* TODO argc, argv */) {
// TODO Implement me
}
Would produce the following links in my org file (or something similar):
* TODO main.cpp:1: "argc, argv"
* TODO main.cpp:2: "Implement me"
I might be able to add a custom org-capture-template to handle this, something like:
(setq org-capture-templates
'(("t" "TODO" entry (file "~/notes/todo.org")
"* TODO [[%l][<text of link>]]"
:immediate-finish t)))
And my scraping function could look like:
(defun org-add-todos-list-from-buffer ()
"Look for TODO comments in current buffer, and add them to org"
(interactive)
(dolist (match (matches-in-buffer (format "%s *TODO.*%s?"
(comment-string-strip comment-start nil nil)
(comment-string-strip comment-end nil nil))))
(org-capture nil "t"))) ;; Somehow pass the desired description to the capture template here?
(matches-in-buffer
comes from https://emacs.stackexchange.com/a/7156/11719)
The problem is that I'm not sure how to get from org-capture
to my formatted link. I haven't found a template format option that does what I want (the closest thing I think would be to un-mangle the content of %l
). I could create the formatted text in my scrape function, but then I don't think I can pass that to the template (unless there is a way to programmatically fill in a prompt?). I suppose I could use something other than org-capture
but I don't want to reinvent the wheel. (Maybe there is already a package out there that does exactly what I want?)
Anyone have any tips?
M-x grep RET TODO *.el RET