From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: [dev] Implement "ref" link types Date: Sun, 19 Feb 2012 19:08:16 +0100 Message-ID: <87vcn2vgq7.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([140.186.70.92]:36807) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RzBCh-0006RN-KR for emacs-orgmode@gnu.org; Sun, 19 Feb 2012 13:09:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RzBCf-0006PF-JV for emacs-orgmode@gnu.org; Sun, 19 Feb 2012 13:09:43 -0500 Received: from mail-we0-f169.google.com ([74.125.82.169]:63208) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RzBCf-0006P3-D5 for emacs-orgmode@gnu.org; Sun, 19 Feb 2012 13:09:41 -0500 Received: by wera13 with SMTP id a13so3598346wer.0 for ; Sun, 19 Feb 2012 10:09:40 -0800 (PST) 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: Org Mode List --=-=-= Content-Type: text/plain Hello, I'd like to introduce a new type of internal links, namely "ref" links. Since any element can now have a "#+name: something" affiliated keyword, it would be practical to have a way to go straight to that name, from anywhere in the buffer. The following patch implements a [[ref:something]] syntax, or even [[ref:something][text]] to do so. The problem that I see here is that is breaks a bit syntax for internal links ("protocol:path" is usually for external links). Another solution would be to make them more hermetic: [[!something]]. On the export side, a "ref" link should be replaced by its description, if it has any, or by the sequence number of the matching element among elements of the same type. With the new exporter and the following buffer: #+begin_src org #+name: tab:letters #+caption: Letters | a | b | | c | d | #+name: tab:numbers #+caption: Numbers | 1 | | 2 | In tableau [[ref:tab:numbers]] we can see... Yet, in [[ref:tab:numbers][the same table]], ... #+end_src the last sentence, in ascii, becomes: In tableau 2 we can see... Yet, in the same table, ... Even if it's not a perfect replacement for "\ref{something}" commands, it should be sufficient for all major back-ends to provide an approximate functionality. And we gain interactivity in the Org buffer. What do you think? Regards, -- Nicolas Goaziou --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Implement-ref-internal-link-type-in-Org-buffers.patch Content-Description: patch for ref links >From f92e12a9482613d4b1d27090fac8d2667b094fdb Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sun, 19 Feb 2012 18:48:41 +0100 Subject: [PATCH] Implement "ref" internal link type in Org buffers * lisp/org.el (org-link-search): Handle "ref" internal link types. A [[ref:some-name]] link points to a "#+name: some-name" in the same buffer. --- lisp/org.el | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index a81f7fc..ea06863 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -9875,6 +9875,16 @@ visibility around point, thus ignoring ;; First check if there are any special search functions ((run-hook-with-args-until-success 'org-execute-file-search-functions s)) ;; Now try the builtin stuff + ;; Ref internal link. + ((and (string-match "^ref:\\(.*\\)" s0) + (let ((name (org-trim (match-string 1 s0)))) + (save-excursion + (goto-char (point-min)) + (and (re-search-forward + (format "^[ \t]*#\\+name: %s" name) nil t) + (setq type 'dedicated pos (match-beginning 0)))))) + (goto-char pos)) + ;; Custom-id ((and (equal (string-to-char s0) ?#) (> (length s0) 1) (save-excursion -- 1.7.9.1 --=-=-=--