emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Line numbers with org-store-link?
@ 2008-05-05 21:40 Bart Parliman
  2008-05-06  7:20 ` Carsten Dominik
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Parliman @ 2008-05-05 21:40 UTC (permalink / raw)
  To: emacs-orgmode

Is there a way to force org-store-link to store the current line 
number rather than a string to locate?

When preparing for code reviews I like to create notes with links 
to the exact source line.  FWIW, in these cases, I keep a static 
copy of the code so I know it isn't going to change.

Obviously none of those reviews involve lisp, since my first 
feeble attempt to add a hyperlink type never even came close to 
running. :-)

Thanks for any help,
Bart

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Line numbers with org-store-link?
  2008-05-05 21:40 Line numbers with org-store-link? Bart Parliman
@ 2008-05-06  7:20 ` Carsten Dominik
  2008-05-06 15:28   ` Bart Parliman
  0 siblings, 1 reply; 3+ messages in thread
From: Carsten Dominik @ 2008-05-06  7:20 UTC (permalink / raw)
  To: Bart Parliman; +Cc: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 1907 bytes --]

Hi Bart,

No, this does not exist, because normally line numbers are moving  
around and therefore are not very useful as long-term search targets.

You can pretty easily hack this, though:

Lets say you want to have line numbers for links to any files in c- 
mode (because this is the programming language you are talking  
about).  Limiting it to some special files makes sure that in other  
file types you will still get links based on (somewhat) more reliable  
text snippets.

Then you can write a small function and add it to the hook
org-create-file-search-functions:

   (defun my-link-to-line-number-in-c-mode ()
     "When in c-mode, use line number as search item."
     (when (eq major-mode 'c-mode)
       (number-to-string (org-current-line))))

   (add-hook 'org-create-file-search-functions
             'my-link-to-line-number-in-c-mode)

Normally you would also have to write a function to search for the  
custom link search text and add that function to `org-execute-file- 
search-functions'.  But you are lucky:  if the search item is an  
integer number, Org already interprets it as a line number.

Hope this helps.

- Carsten

On May 5, 2008, at 11:40 PM, Bart Parliman wrote:
> Is there a way to force org-store-link to store the current line  
> number rather than a string to locate?
>
> When preparing for code reviews I like to create notes with links to  
> the exact source line.  FWIW, in these cases, I keep a static copy  
> of the code so I know it isn't going to change.
>
> Obviously none of those reviews involve lisp, since my first feeble  
> attempt to add a hyperlink type never even came close to running. :-)
>
> Thanks for any help,
> Bart
>
>
>
> _______________________________________________
> Emacs-orgmode mailing list
> Remember: use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode


[-- Attachment #1.2: Type: text/html, Size: 2575 bytes --]

[-- Attachment #2: Type: text/plain, Size: 204 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Remember: use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Line numbers with org-store-link?
  2008-05-06  7:20 ` Carsten Dominik
@ 2008-05-06 15:28   ` Bart Parliman
  0 siblings, 0 replies; 3+ messages in thread
From: Bart Parliman @ 2008-05-06 15:28 UTC (permalink / raw)
  Cc: Bart Parliman, emacs-orgmode

Carsten,

This is exactly what I need.  Thanks.

Bart

On Tue, 6 May 2008, Carsten Dominik wrote:

> Hi Bart,
>
> No, this does not exist, because normally line numbers are moving around and 
> therefore are not very useful as long-term search targets.
>
> You can pretty easily hack this, though:
>
> Lets say you want to have line numbers for links to any files in c-mode 
> (because this is the programming language you are talking about).  Limiting 
> it to some special files makes sure that in other file types you will still 
> get links based on (somewhat) more reliable text snippets.
>
> Then you can write a small function and add it to the hook
> org-create-file-search-functions:
>
> (defun my-link-to-line-number-in-c-mode ()
>   "When in c-mode, use line number as search item."
>   (when (eq major-mode 'c-mode)
>     (number-to-string (org-current-line))))
>
> (add-hook 'org-create-file-search-functions
>           'my-link-to-line-number-in-c-mode)
>
> Normally you would also have to write a function to search for the custom 
> link search text and add that function to 
> `org-execute-file-search-functions'.  But you are lucky:  if the search item 
> is an integer number, Org already interprets it as a line number.
>
> Hope this helps.
>
> - Carsten
>
> On May 5, 2008, at 11:40 PM, Bart Parliman wrote:
>> Is there a way to force org-store-link to store the current line number 
>> rather than a string to locate?
>> 
>> When preparing for code reviews I like to create notes with links to the 
>> exact source line.  FWIW, in these cases, I keep a static copy of the code 
>> so I know it isn't going to change.
>> 
>> Obviously none of those reviews involve lisp, since my first feeble attempt 
>> to add a hyperlink type never even came close to running. :-)
>> 
>> Thanks for any help,
>> Bart
>> 
>> 
>> 
>> _______________________________________________
>> Emacs-orgmode mailing list
>> Remember: use `Reply All' to send replies to the list.
>> Emacs-orgmode@gnu.org
>> http://lists.gnu.org/mailman/listinfo/emacs-orgmode
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-05-06 15:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-05 21:40 Line numbers with org-store-link? Bart Parliman
2008-05-06  7:20 ` Carsten Dominik
2008-05-06 15:28   ` Bart Parliman

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).