emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Kyle Meyer <kyle@kyleam.com>
To: Daniele Nicolodi <daniele@grinta.net>
Cc: emacs-orgmode@gnu.org
Subject: Re: Link to source file location with content preview
Date: Thu, 02 Jul 2020 18:19:53 -0400	[thread overview]
Message-ID: <87o8oxv9ti.fsf@kyleam.com> (raw)
In-Reply-To: <8d7d36e4-86c0-06d0-d7e0-e33ff509f7e7@grinta.net>

Daniele Nicolodi writes:

> A related question: does anyone have some elisp code that turns a Grep
> buffer (the results of running "M-x grep") into org-mode links to the
> locations?

I have something like that.  I haven't used it in a while, but a quick
tests suggests it still works.  If you keep it around/modify it, you'll
want to update the obsolete org-make-link-string to
org-link-make-string.

-- >8 --
(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))))))


      reply	other threads:[~2020-07-02 22:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-02 20:09 Link to source file location with content preview Daniele Nicolodi
2020-07-02 22:19 ` Kyle Meyer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87o8oxv9ti.fsf@kyleam.com \
    --to=kyle@kyleam.com \
    --cc=daniele@grinta.net \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).