From mboxrd@z Thu Jan 1 00:00:00 1970 From: Not To Miss Subject: Re: anyway to create link to a line number in a file Date: Tue, 21 Feb 2012 12:16:51 -0500 Message-ID: References: <9088.1329586287@alphaville> <4472.1329602285@alphaville> <8630.1329717509@alphaville> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=f46d043bdfb80950d104b97c96d9 Return-path: Received: from eggs.gnu.org ([140.186.70.92]:40829) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RztLP-0006Aw-9D for emacs-orgmode@gnu.org; Tue, 21 Feb 2012 12:17:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RztLI-0005jP-9G for emacs-orgmode@gnu.org; Tue, 21 Feb 2012 12:17:39 -0500 Received: from mail-vw0-f41.google.com ([209.85.212.41]:40240) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RztLI-0005j3-2t for emacs-orgmode@gnu.org; Tue, 21 Feb 2012 12:17:32 -0500 Received: by vbip1 with SMTP id p1so5498601vbi.0 for ; Tue, 21 Feb 2012 09:17:31 -0800 (PST) In-Reply-To: <8630.1329717509@alphaville> 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: nicholas.dokos@hp.com Cc: emacs-orgmode@gnu.org --f46d043bdfb80950d104b97c96d9 Content-Type: text/plain; charset=ISO-8859-1 On Mon, Feb 20, 2012 at 12:58 AM, Nick Dokos wrote: > Not To Miss wrote: > > > Thanks, Nick! It works, though it works only to the specified file(s) > > by overruling the original org-store-link-functions. > > Yes, org marches down the link handlers and takes the first positive > response as the answer. You can make the function arbitrarily complicated > of course, if you don't like the behavior, but in any case, it will have > to say "yes" (and provide the link in some format) or "no" - in the latter > case, org will continue on with the rest of the functions in the list (and > fall back to its default if *no* function says "yes"). > > > Ideally, it would > > be great if in the normal stored org link, line number could be > > included in the link and would be ripped off from the text to search > > the linked file. > > > > I'm confused - what exactly are you asking for here? If you don't use > the line number for searching, why would you want to store it? > Because I think sometimes the line number gives valuable information in addition to the text. I meant to create a link like [[file:foo.txt::123 whatever_text]], when users open the link, org-mode searches "whatever_text"; if it doesn't find anything, jump to the line 123. The idea behind that is that it is possible the line is changed and is unsearchable but still remains in the same line number. This, however, is probably an issue of built-in org-mode design, beyond the scope of user customization. Anyway, thanks for your help. > > Nick > > > On Sat, Feb 18, 2012 at 4:58 PM, Nick Dokos > wrote: > > > Nick Dokos wrote: > > > > > >> Not To Miss wrote: > > >> > > >> > I looked that section carefully and the whole manual briefly. I > > >> > haven't found anything yet. That's why I am asking on the mailing > list > > >> > to see if anyone has some workaround. > > >> > > > >> > On Sat, Feb 18, 2012 at 9:03 AM, Sean O'Halpin < > sean.ohalpin@gmail.com> wrote: > > >> > > On Fri, Feb 17, 2012 at 4:54 PM, Not To Miss < > not.to.miss@gmail.com> wrote: > > >> > >> Hi all, > > >> > >> > > >> > >> I am reading a long text file and want to write down my notes > with > > >> > >> org-mode. I extremely would like to put the line numbers down > along > > >> > >> with my notes. Although there is a way to store a link for text > search > > >> > >> for the current line, I haven't found a way to create a link to > a line > > >> > >> number in the current buffer. Is there anyway to do that? Thanks > > >> > > > > >> > > Take a look at org-capture: > http://orgmode.org/manual/Capture.html > > >> > > > > > >> The problem is to make sure org-store-link will actually store the > line > > >> number (along with everything else) so that then org-insert-link can > > >> insert the link in the proper format. I don't think there is a > function > > >> to do that out of the box for line numbers, but you can easily (for > some > > >> value of "easily") write your own. Look in > > >> > > >> (info "(org)Adding hyperlink types") > > >> > > >> for some hints. Briefly, you write a function that checks whether it > > >> wants to deal with the link or not, and you add it to > > >> org-store-link-functions. I don't have the time to try it out right > now, > > >> but I believe this should work for what you want. > > >> > > > > > > Following up on this, the following seems to work, although you > probably > > > want to tweak the criterion of when you want *this* function to take > > > care of links - this particular implementation only applies the line > > > number treatment to links generated in the file named > > > "/path/to/the.file.txt" and only that file: > > > > > > --8<---------------cut here---------------start------------->8--- > > > (defun org-file-lineno-store-link() > > > (when (string-equal (buffer-file-name) "/path/to/the.file.txt") > > > (let* ((link (format "file:%s::%d" (buffer-file-name) > (line-number-at-pos)))) > > > (org-store-link-props > > > :type "file" > > > :link link)))) > > > > > > (add-hook 'org-store-link-functions 'org-file-lineno-store-link) > > > --8<---------------cut here---------------end--------------->8--- > > > > > > Nick > > > > > > > > > > > -- > > Best, > > Zhenjiang > > > -- Best, Zhenjiang --f46d043bdfb80950d104b97c96d9 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

On Mon, Feb 20, 2012 at 12:58 AM, Nick D= okos <nicholas.dokos@hp.com> wrote:
Not To Miss <not.to.miss@gmail.com> wrote:

> Thanks, Nick! It works, though it works only to the specifi= ed file(s)
> by overruling the original org-store-link-functions.

Yes, org marches down the link handlers and takes the first positive<= br> response as the answer. You can make the function arbitrarily complicated of course, if you don't like the behavior, but in any case, it will hav= e
to say "yes" (and provide the link in some format) or "no&qu= ot; - in the latter
case, org will continue on with the rest of the functions in the list (and<= br> fall back to its default if *no* function says "yes").

> Ideally, it would
> be great if in the normal stored org link, line number could be
> included in the link and would be ripped off from the text to search > the linked file.
>

I'm confused - what exactly are you asking for here? If you don&#= 39;t use
the line number for searching, why would you want to store it?
Because I think sometimes the line number gives valuable informati= on in addition to the text. I meant to create a link like [[file:foo.txt::1= 23 whatever_text]], when users open the link, org-mode searches "whate= ver_text"; if it doesn't find anything, jump to the line 123. The = idea behind that is that it is possible the line is changed and is unsearch= able but still remains in the same line number. This, however, is probably = an issue of built-in org-mode design, beyond the scope of user customizatio= n.=A0

Anyway, thanks for your help.
=A0

Nick

> On Sat, Feb 18, 2012 at 4:58 PM, Nick Dokos <nicholas.dokos@hp.com> wrote: > > Nick Dokos <nicholas.dokos@hp.com> wrote:
> >
> >> Not To Miss <not.to.miss@gmail.com> wrote:
> >>
> >> > I looked that section carefully and the whole manual bri= efly. I
> >> > haven't found anything yet. That's why I am aski= ng on the mailing list
> >> > to see if anyone has some workaround.
> >> >
> >> > On Sat, Feb 18, 2012 at 9:03 AM, Sean O'Halpin <<= a href=3D"mailto:sean.ohalpin@gmail.com" target=3D"_blank">sean.ohalpin@gma= il.com> wrote:
> >> > > On Fri, Feb 17, 2012 at 4:54 PM, Not To Miss <not.to.miss@gmail.= com> wrote:
> >> > >> Hi all,
> >> > >>
> >> > >> I am reading a long text file and want to write= down my notes with
> >> > >> org-mode. I extremely would like to put the lin= e numbers down along
> >> > >> with my notes. Although there is a way to store= a link for text search
> >> > >> for the current line, I haven't found a way= to create a link to a line
> >> > >> number in the current buffer. Is there anyway t= o do that? Thanks
> >> > >
> >> > > Take a look at org-capture: http://orgmode.org/manual/Cap= ture.html
> >>
> >
> >> The problem is to make sure org-store-link will actually stor= e the line
> >> number (along with everything else) so that then org-insert-l= ink can
> >> insert the link in the proper format. I don't think there= is a function
> >> to do that out of the box for line numbers, but you can easil= y (for some
> >> value of "easily") write your own. Look in
> >>
> >> (info "(org)Adding hyperlink types")
> >>
> >> for some hints. Briefly, you write a function that checks whe= ther it
> >> wants to deal with the link or not, and you add it to
> >> org-store-link-functions. I don't have the time to try it= out right now,
> >> but I believe this should work for what you want.
> >>
> >
> > Following up on this, the following seems to work, although you p= robably
> > want to tweak the criterion of when you want *this* function to t= ake
> > care of links - this particular implementation only applies the l= ine
> > number treatment to links generated in the file named
> > "/path/to/the.file.txt" and only that file:
> >
> > --8<---------------cut here---------------start-------------&g= t;8---
> > (defun org-file-lineno-store-link()
> > =A0(when (string-equal (buffer-file-name) "/path/to/the.file= .txt")
> > =A0 =A0(let* ((link (format "file:%s::%d" (buffer-file-= name) (line-number-at-pos))))
> > =A0 =A0 =A0(org-store-link-props
> > =A0 =A0 =A0 :type "file"
> > =A0 =A0 =A0 :link link))))
> >
> > (add-hook 'org-store-link-functions 'org-file-lineno-stor= e-link)
> > --8<---------------cut here---------------end---------------&g= t;8---
> >
> > Nick
> >
>
>
>
> --
> Best,
> Zhenjiang
>



--
= Best,
Zhenjiang
--f46d043bdfb80950d104b97c96d9--