From mboxrd@z Thu Jan 1 00:00:00 1970 From: Carsten Dominik Subject: Re: Line numbers with org-store-link? Date: Tue, 6 May 2008 09:20:57 +0200 Message-ID: <1965C49B-BDF1-451C-A84B-1E48AE5C5488@science.uva.nl> References: Mime-Version: 1.0 (Apple Message framework v919.2) Content-Type: multipart/mixed; boundary="===============0345593529==" Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JtHU1-0002WS-Uv for emacs-orgmode@gnu.org; Tue, 06 May 2008 03:21:06 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JtHU1-0002Vt-21 for emacs-orgmode@gnu.org; Tue, 06 May 2008 03:21:05 -0400 Received: from [199.232.76.173] (port=48516 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JtHU0-0002Vn-RW for emacs-orgmode@gnu.org; Tue, 06 May 2008 03:21:04 -0400 Received: from mx20.gnu.org ([199.232.41.8]) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1JtHU0-0005ou-Hu for emacs-orgmode@gnu.org; Tue, 06 May 2008 03:21:04 -0400 Received: from korteweg.uva.nl ([146.50.98.70]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1JtHTx-0004vR-GC for emacs-orgmode@gnu.org; Tue, 06 May 2008 03:21:01 -0400 In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Bart Parliman Cc: emacs-orgmode@gnu.org --===============0345593529== Content-Type: multipart/alternative; boundary=Apple-Mail-9--176976498 --Apple-Mail-9--176976498 Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit 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 --Apple-Mail-9--176976498 Content-Type: text/html; charset=US-ASCII Content-Transfer-Encoding: quoted-printable
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)

<= /div>
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

= --Apple-Mail-9--176976498-- --===============0345593529== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ 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 --===============0345593529==--