From mboxrd@z Thu Jan 1 00:00:00 1970 From: Leo Alekseyev Subject: Re: Is it possible to create links to M-x occur results? Date: Thu, 2 May 2013 10:25:29 -0700 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=047d7b3a843657610904dbbf8582 Return-path: Received: from eggs.gnu.org ([208.118.235.92]:55904) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UXxG8-0006tH-9N for emacs-orgmode@gnu.org; Thu, 02 May 2013 13:25:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UXxG6-0007tz-GF for emacs-orgmode@gnu.org; Thu, 02 May 2013 13:25:32 -0400 Received: from mail-lb0-f178.google.com ([209.85.217.178]:38800) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UXxG6-0007to-9h for emacs-orgmode@gnu.org; Thu, 02 May 2013 13:25:30 -0400 Received: by mail-lb0-f178.google.com with SMTP id x10so775425lbi.37 for ; Thu, 02 May 2013 10:25:29 -0700 (PDT) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-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: Rick Frankel Cc: Emacs orgmode --047d7b3a843657610904dbbf8582 Content-Type: text/plain; charset=ISO-8859-1 Nice! Short and sweet, and works great. It should go on orgmode.orgsomewhere in the cool hacks section. On Thu, May 2, 2013 at 7:07 AM, Rick Frankel wrote: > On 01.05.2013 18:41, Leo Alekseyev wrote: > >> Howdy Org-folks, >> >> 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! >> > > That seems like a fun exercise. so: > > #+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 > > and you can use a link like: > > occur:m/file.txt#regex > > rick > --047d7b3a843657610904dbbf8582 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Nice!=A0 Short and sweet, and works great.=A0 It should go= on orgmode.org somewhere in the cool ha= cks section.


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,

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
M-x occur results given some search term for that file.=A0 That way I
could link to an overview of a file's class/function definitions, or config stanzas, or other useful things.=A0 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!

That seems like a fun exercise. so:

#+BEGIN_SRC elisp
=A0 (defun org-occur-open (uri)
=A0 =A0 "Visit the file specified by URI, and run `occur' on the f= ragment
=A0 \(anything after '#') in the uri."
=A0 =A0 (let ((list (split-string uri "#")))
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(org-open-file (car list) t)
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(occur (mapconcat 'identity (cdr list) &= quot;#"))))
=A0 (org-add-link-type "occur" 'org-occur-open)
#+END_SRC

and you can use a link like:

occur:m/file.txt#regex

rick

--047d7b3a843657610904dbbf8582--