emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Samuel Loury <konubinix@gmail.com>
To: OrgMode ML <emacs-orgmode@gnu.org>
Subject: Re: [PATCH] Fix uncaught error when trying to open a link at point
Date: Fri, 04 Jan 2013 14:17:42 +0100	[thread overview]
Message-ID: <87pq1lrssp.fsf@konixwork.incubateur.ens-lyon.fr> (raw)
In-Reply-To: <87wqvtrxcp.fsf@konixwork.incubateur.ens-lyon.fr>


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

In attachment is a patch making tests of the previous mail
(id:"87wqvtrxcp.fsf@konixwork.incubateur.ens-lyon.fr") pass.

It adjusts org-open-at-point to have plain links handled the same way
bracket links are. It allows plain links to be followed if the cursor is
before the link while still on the same line.

I also got rid of dangling parenthesis as suggested by
Nicolas. Personally, I think it is easier to read with dangling
parens. Could you explain what is wrong with them?

Thanks for your attention.
-- 
Konubinix
GPG Key    : 7439106A
Fingerprint: 5993 BE7A DA65 E2D9 06CE  5C36 75D2 3CED 7439 106A

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: patch --]
[-- Type: text/x-diff, Size: 2289 bytes --]

From cd52bef7715ed551972ad5331fce50260cfcda50 Mon Sep 17 00:00:00 2001
From: Samuel Loury <konubinixweb@gmail.com>
Date: Fri, 4 Jan 2013 14:01:43 +0100
Subject: [PATCH] Make org-open-at-point behave the same with plain links and
 with bracket links.

    * lisp/org.el (org-open-at-point): make org-open-at-point handle a plain link
      even if the cursor is before it

TINYCHANGE
---
 lisp/org.el |   36 ++++++++++++++++++++++++++++++------
 1 file changed, 30 insertions(+), 6 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index b0fcb58..5d75055 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -9911,12 +9911,36 @@ application the system uses for this file type."
 	    (throw 'match t))
 
 	  (save-excursion
-	    (let ((plinkpos (org-in-regexp org-plain-link-re)))
-	      (when (or (org-in-regexp org-angle-link-re)
-			(and plinkpos (goto-char (car plinkpos))
-			     (save-match-data (not (looking-back "\\[\\[")))))
-		(setq type (match-string 1)
-		      path (org-link-unescape (match-string 2)))
+	    (when (or (org-in-regexp org-angle-link-re)
+		      (let ((match (org-in-regexp org-plain-link-re)))
+			(and
+			 ;; link at point is a plain link
+			 match
+			 ;; check that it is not of the form
+			 ;; [[http://orgmode.org][Org]]Mode. in that
+			 ;; case, if the cursor is on "Mode", then the
+			 ;; string "http://orgmode.org][Org]]Mode" is
+			 ;; recognized as a plain link while it should
+			 ;; not be
+			 (save-excursion
+			  (progn
+			    ;; go to the begining of the match, If we
+			    ;; were in the special case, we should now
+			    ;; be in a org-bracket-link-regexp
+			    (goto-char (car match))
+			    (not
+			     (org-in-regexp org-bracket-link-regexp))))))
+		      (let ((line_ending (save-excursion (end-of-line)
+							 (point))))
+			;; if in a line before a plain link or a
+			;; bracket link
+			(or
+			 (re-search-forward org-plain-link-re
+					    line_ending t)
+			 (re-search-forward org-bracket-link-regexp
+					    line_ending t))))
+	      (setq type (match-string 1)
+		    path (org-link-unescape (match-string 2)))
 		(throw 'match t))))
 	  (save-excursion
 	    (when (org-in-regexp (org-re "\\(:[[:alnum:]_@#%:]+\\):[ \t]*$"))
-- 
1.7.10.4


[-- Attachment #2: Type: application/pgp-signature, Size: 489 bytes --]

  reply	other threads:[~2013-01-04 13:19 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-22  8:42 [PATCH] Fix uncaught error when trying to open a link at point Samuel Loury
2012-11-28 12:53 ` Nicolas Goaziou
2012-12-20  8:41 ` Bastien
2013-01-04 11:39   ` Samuel Loury
2013-01-04 13:17     ` Samuel Loury [this message]
2013-01-04 16:18       ` Bastien
2013-01-14 10:35         ` Samuel Loury
2013-02-13 15:25       ` Bastien
2013-02-13 16:39         ` Samuel Loury
2013-02-13 16:49           ` Bastien
2013-03-16 19:22             ` Samuel Loury
2013-03-16 19:32               ` Bastien

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87pq1lrssp.fsf@konixwork.incubateur.ens-lyon.fr \
    --to=konubinix@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).