all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [dev] Implement "ref" link types
@ 2012-02-19 18:08 Nicolas Goaziou
  2012-02-19 19:28 ` Christian Moe
                   ` (2 more replies)
  0 siblings, 3 replies; 19+ messages in thread
From: Nicolas Goaziou @ 2012-02-19 18:08 UTC (permalink / raw)
  To: Org Mode List

[-- Attachment #1: Type: text/plain, Size: 1383 bytes --]

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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch for ref links --]
[-- Type: text/x-patch, Size: 1263 bytes --]

From f92e12a9482613d4b1d27090fac8d2667b094fdb Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <n.goaziou@gmail.com>
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


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

end of thread, other threads:[~2012-03-05  9:37 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-19 18:08 [dev] Implement "ref" link types Nicolas Goaziou
2012-02-19 19:28 ` Christian Moe
2012-02-19 19:41   ` Nicolas Goaziou
2012-02-19 20:11     ` Toby Cubitt
2012-02-19 20:20     ` Christian Moe
2012-02-19 19:41 ` Samuel Wales
2012-02-19 20:02   ` Nicolas Goaziou
2012-02-19 20:48     ` Samuel Wales
2012-02-19 20:10 ` Carsten Dominik
2012-02-20  0:51   ` Nicolas Goaziou
2012-02-20  7:09     ` Carsten Dominik
2012-02-20 10:59       ` Nicolas Goaziou
2012-02-20 22:06         ` Nicolas Goaziou
2012-02-21  1:26           ` Thomas S. Dye
2012-02-21  5:14           ` David Maus
2012-02-21  9:18             ` Nicolas Goaziou
2012-02-27 19:38               ` Nicolas Goaziou
2012-02-27 20:38               ` David Maus
2012-03-05  9:37         ` Jambunathan K

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.