[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] anyway to create link to a line number in a file
From: |
Not To Miss |
Subject: |
Re: [O] anyway to create link to a line number in a file |
Date: |
Sun, 19 Feb 2012 23:43:02 -0500 |
Thanks, Nick! It works, though it works only to the specified file(s)
by overruling the original org-store-link-functions. 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.
On Sat, Feb 18, 2012 at 4:58 PM, Nick Dokos <address@hidden> wrote:
> Nick Dokos <address@hidden> wrote:
>
>> Not To Miss <address@hidden> 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 <address@hidden> wrote:
>> > > On Fri, Feb 17, 2012 at 4:54 PM, Not To Miss <address@hidden> 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
- [O] anyway to create link to a line number in a file, Not To Miss, 2012/02/17
- Re: [O] anyway to create link to a line number in a file, Sean O'Halpin, 2012/02/18
- Re: [O] anyway to create link to a line number in a file, Not To Miss, 2012/02/18
- Re: [O] anyway to create link to a line number in a file, Nick Dokos, 2012/02/18
- Re: [O] anyway to create link to a line number in a file, Nick Dokos, 2012/02/18
- Re: [O] anyway to create link to a line number in a file,
Not To Miss <=
- Re: [O] anyway to create link to a line number in a file, Nick Dokos, 2012/02/20
- Re: [O] anyway to create link to a line number in a file, Not To Miss, 2012/02/21
- Re: [O] anyway to create link to a line number in a file, Nick Dokos, 2012/02/21