* Link to source file location with content preview
@ 2020-07-02 20:09 Daniele Nicolodi
2020-07-02 22:19 ` Kyle Meyer
0 siblings, 1 reply; 2+ messages in thread
From: Daniele Nicolodi @ 2020-07-02 20:09 UTC (permalink / raw)
To: emacs-orgmode
Hello,
I would like to create links from an org-mode file to source file
locations that display a preview of the link destination in the form of
a source code block or similar with a few lines of the file content.
Is this doable with org-store-link and org-insert-link?
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?
Thank you!
Cheers,
Dan
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Link to source file location with content preview
2020-07-02 20:09 Link to source file location with content preview Daniele Nicolodi
@ 2020-07-02 22:19 ` Kyle Meyer
0 siblings, 0 replies; 2+ messages in thread
From: Kyle Meyer @ 2020-07-02 22:19 UTC (permalink / raw)
To: Daniele Nicolodi; +Cc: emacs-orgmode
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))))))
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-07-02 22:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-07-02 20:09 Link to source file location with content preview Daniele Nicolodi
2020-07-02 22:19 ` Kyle Meyer
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.