From mboxrd@z Thu Jan  1 00:00:00 1970
From: Carsten Dominik <carsten.dominik@gmail.com>
Subject: Re: Is it possible to create links to M-x occur results?
Date: Fri, 3 May 2013 09:14:43 +0200
Message-ID: <1770C68C-47FD-4E0A-89C1-79DFE3F9CE82@gmail.com>
References: <CADzxs1=qZcfhSudqZO9svaNbEdp9XDbQtg90vRmXHTcCkUOoxw@mail.gmail.com>
	<a93998d8051d9b6321785bd83529408e@mail.rickster.com>
	<CADzxs1m2NJ0J4Qe+bNs2r8hdiKef+5e5TP07ayOxAXQ2VesKRA@mail.gmail.com>
Mime-Version: 1.0 (Mac OS X Mail 6.3 \(1503\))
Content-Type: multipart/alternative;
	boundary="Apple-Mail=_2CEF970C-D95C-4A13-A2EE-398FD7EE62CA"
Return-path: <emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org>
Received: from eggs.gnu.org ([208.118.235.92]:35759)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <carsten.dominik@gmail.com>) id 1UYAJV-0005Bo-Bo
	for emacs-orgmode@gnu.org; Fri, 03 May 2013 03:21:54 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <carsten.dominik@gmail.com>) id 1UYAJQ-0008CR-Bm
	for emacs-orgmode@gnu.org; Fri, 03 May 2013 03:21:53 -0400
Received: from ezel.ic.uva.nl ([146.50.108.158]:44449)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <carsten.dominik@gmail.com>) id 1UYAJQ-0008Aw-2f
	for emacs-orgmode@gnu.org; Fri, 03 May 2013 03:21:48 -0400
In-Reply-To: <CADzxs1m2NJ0J4Qe+bNs2r8hdiKef+5e5TP07ayOxAXQ2VesKRA@mail.gmail.com>
List-Id: "General discussions about Org-mode." <emacs-orgmode.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/emacs-orgmode>,
	<mailto:emacs-orgmode-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/emacs-orgmode>
List-Post: <mailto:emacs-orgmode@gnu.org>
List-Help: <mailto:emacs-orgmode-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/emacs-orgmode>,
	<mailto:emacs-orgmode-request@gnu.org?subject=subscribe>
Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org
Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org
To: Leo Alekseyev <dnquark@gmail.com>
Cc: Rick Frankel <rick@rickster.com>, Emacs orgmode <emacs-orgmode@gnu.org>


--Apple-Mail=_2CEF970C-D95C-4A13-A2EE-398FD7EE62CA
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=iso-8859-1


On 2.5.2013, at 19:25, Leo Alekseyev <dnquark@gmail.com> wrote:

> Nice!  Short and sweet, and works great.  It should go on orgmode.org =
somewhere in the cool hacks section.

Make a patch if you don't have write access to worg...

- Carsten

>=20
>=20
> On Thu, May 2, 2013 at 7:07 AM, Rick Frankel <rick@rickster.com> =
wrote:
> On 01.05.2013 18:41, Leo Alekseyev wrote:
> Howdy Org-folks,
>=20
> Something that I've found myself wishing for time and time again is to
> be able to follow the link to a file and immediately pop into a set of
> M-x occur results given some search term for that file.  That way I
> could link to an overview of a file's class/function definitions, or
> config stanzas, or other useful things.  Given that we can create
> links to arbitrary elisp, I am sure that this can be done in
> principle, but if there's a quick recipe that someone has come up
> with, I'd love to hear about it!
>=20
> That seems like a fun exercise. so:
>=20
> #+BEGIN_SRC elisp
>   (defun org-occur-open (uri)
>     "Visit the file specified by URI, and run `occur' on the fragment
>   \(anything after '#') in the uri."
>     (let ((list (split-string uri "#")))
>                (org-open-file (car list) t)
>                (occur (mapconcat 'identity (cdr list) "#"))))
>   (org-add-link-type "occur" 'org-occur-open)
> #+END_SRC
>=20
> and you can use a link like:
>=20
> occur:m/file.txt#regex
>=20
> rick
>=20


--Apple-Mail=_2CEF970C-D95C-4A13-A2EE-398FD7EE62CA
Content-Transfer-Encoding: 7bit
Content-Type: text/html;
	charset=iso-8859-1

<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On 2.5.2013, at 19:25, Leo Alekseyev &lt;<a href="mailto:dnquark@gmail.com">dnquark@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr">Nice!&nbsp; Short and sweet, and works great.&nbsp; It should go on <a href="http://orgmode.org/">orgmode.org</a> somewhere in the cool hacks section.<br></div></blockquote><div><br></div><div>Make a patch if you don't have write access to worg...</div><div><br></div><div>- Carsten</div><br><blockquote type="cite"><div class="gmail_extra"><br><br><div class="gmail_quote">
On Thu, May 2, 2013 at 7:07 AM, Rick Frankel <span dir="ltr">&lt;<a href="mailto:rick@rickster.com" target="_blank">rick@rickster.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; position: static; z-index: auto; ">
<div class="HOEnZb"><div class="h5">On 01.05.2013 18:41, Leo Alekseyev wrote:<br>
<blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; position: static; z-index: auto; ">
Howdy Org-folks,<br>
<br>
Something that I've found myself wishing for time and time again is to<br>
be able to follow the link to a file and immediately pop into a set of<br>
M-x occur results given some search term for that file.&nbsp; That way I<br>
could link to an overview of a file's class/function definitions, or<br>
config stanzas, or other useful things.&nbsp; Given that we can create<br>
links to arbitrary elisp, I am sure that this can be done in<br>
principle, but if there's a quick recipe that someone has come up<br>
with, I'd love to hear about it!<br>
</blockquote>
<br></div></div>
That seems like a fun exercise. so:<br>
<br>
#+BEGIN_SRC elisp<br>
&nbsp; (defun org-occur-open (uri)<br>
&nbsp; &nbsp; "Visit the file specified by URI, and run `occur' on the fragment<br>
&nbsp; \(anything after '#') in the uri."<br>
&nbsp; &nbsp; (let ((list (split-string uri "#")))<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(org-open-file (car list) t)<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(occur (mapconcat 'identity (cdr list) "#"))))<br>
&nbsp; (org-add-link-type "occur" 'org-occur-open)<br>
#+END_SRC<br>
<br>
and you can use a link like:<br>
<br>
occur:m/file.txt#regex<span class="HOEnZb"><font color="#888888"><br>
<br>
rick<br>
</font></span></blockquote></div><br></div>
</blockquote></div><br></body></html>
--Apple-Mail=_2CEF970C-D95C-4A13-A2EE-398FD7EE62CA--