emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Alexey Lebedeff <binarin@gmail.com>
To: emacs-orgmode@gnu.org
Subject: [PATCH] `org-return' in 8.3 no longer follows links in headings
Date: Wed, 12 Aug 2015 23:49:13 +0300	[thread overview]
Message-ID: <CADOt_n8JE=mSf0wY10vHQscfsAMtQzu7f5dkKCZDbWNdH1u6Lw@mail.gmail.com> (raw)


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

Hi all,

After switching to 8.3 I discovered that `org-return' no longer follows
links in headings, even if `org-return-follows-link' is non-nil. Instead it
started inserting newlines in the middle of link. This change of behavior
was introduced by a7e62499f2fe5c313567212ee90ff743c5e734a8

In the attached patch I just shuffled parts of `org-return' around. Maybe
it is better to move tag-preserving newline code to some helper function,
but I'm not sure how to do it properly.


Best,
Alexey

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

[-- Attachment #2: 0001-Make-org-return-follow-links-in-headings-again.patch --]
[-- Type: text/x-patch, Size: 4942 bytes --]

From d30093d4019d445b6b8d176837601bc3f712b190 Mon Sep 17 00:00:00 2001
From: Alexey Lebedeff <binarin@gmail.com>
Date: Wed, 12 Aug 2015 23:02:49 +0300
Subject: [PATCH] Make `org-return' follow links in headings again

* org.el (org-return): Check for links first when
  `org-return-follows-link' is non-nil, before inserting any newlines.

This patch restores order in which `org-return' perform actions (which
was changed in a7e62499f2fe5c313567212ee90ff743c5e734a8).  It is
TINYCHANGE, because patch mostly consists of moving existing code
around.
---
 lisp/org.el              | 63 ++++++++++++++++++++++++------------------------
 testing/lisp/test-org.el |  6 +++++
 2 files changed, 38 insertions(+), 31 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index e8643e1..d7ecf85 100755
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -21287,7 +21287,28 @@ will not happen if point is in a table or on a \"dead\"
 object (e.g., within a comment).  In these case, you need to use
 `org-open-at-point' directly."
   (interactive)
-  (if (and (not (bolp))
+  (let* ((context (if org-return-follows-link (org-element-context)
+		    (org-element-at-point)))
+	 (type (org-element-type context)))
+    (cond
+     ;; In a table, call `org-table-next-row'.
+     ((or (and (eq type 'table)
+	       (>= (point) (org-element-property :contents-begin context))
+	       (< (point) (org-element-property :contents-end context)))
+	  (org-element-lineage context '(table-row table-cell) t))
+      (org-table-justify-field-maybe)
+      (call-interactively #'org-table-next-row))
+     ;; On a link or a timestamp but not on white spaces after it,
+     ;; call `org-open-line' if `org-return-follows-link' allows it.
+     ((and org-return-follows-link
+	   (memq type '(link timestamp))
+	   (< (point)
+	      (save-excursion (goto-char (org-element-property :end context))
+			      (skip-chars-backward " \t")
+			      (point))))
+      (call-interactively #'org-open-at-point))
+     ;; Insert newline in heading, but preserve tags.
+     ((and (not (bolp))
 	   (save-excursion (beginning-of-line)
 			   (looking-at org-complex-heading-regexp)))
       ;; At headline.
@@ -21317,36 +21338,16 @@ object (e.g., within a comment).  In these case, you need to use
 	(end-of-line)
 	(org-show-entry)
 	(if indent (newline-and-indent) (newline))
-	(and string (save-excursion (insert (org-trim string)))))
-    (let* ((context (if org-return-follows-link (org-element-context)
-		      (org-element-at-point)))
-	   (type (org-element-type context)))
-      (cond
-       ;; In a table, call `org-table-next-row'.
-       ((or (and (eq type 'table)
-		 (>= (point) (org-element-property :contents-begin context))
-		 (< (point) (org-element-property :contents-end context)))
-	    (org-element-lineage context '(table-row table-cell) t))
-	(org-table-justify-field-maybe)
-	(call-interactively #'org-table-next-row))
-       ;; On a link or a timestamp but not on white spaces after it,
-       ;; call `org-open-line' if `org-return-follows-link' allows it.
-       ((and org-return-follows-link
-	     (memq type '(link timestamp))
-	     (< (point)
-		(save-excursion (goto-char (org-element-property :end context))
-				(skip-chars-backward " \t")
-				(point))))
-	(call-interactively #'org-open-at-point))
-       ;; In a list, make sure indenting keeps trailing text within.
-       ((and indent
-	     (not (eolp))
-	     (org-element-lineage context '(item)))
-	(let ((trailing-data
-	       (delete-and-extract-region (point) (line-end-position))))
-	  (newline-and-indent)
-	  (save-excursion (insert trailing-data))))
-       (t (if indent (newline-and-indent) (newline)))))))
+	(and string (save-excursion (insert (org-trim string))))))
+     ;; In a list, make sure indenting keeps trailing text within.
+     ((and indent
+	   (not (eolp))
+	   (org-element-lineage context '(item)))
+      (let ((trailing-data
+	     (delete-and-extract-region (point) (line-end-position))))
+	(newline-and-indent)
+	(save-excursion (insert trailing-data))))
+     (t (if indent (newline-and-indent) (newline))))))
 
 (defun org-return-indent ()
   "Goto next table row or insert a newline and indent.
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index 3a156b8..9fee787 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -893,6 +893,12 @@
    (org-test-with-temp-text "Link [[target<point>]] <<target>>"
      (let ((org-return-follows-link nil)) (org-return))
      (org-looking-at-p "<<target>>")))
+  ;; Link in heading should also be opened when `org-return-follows-link` is non-nil.
+  (should
+   (org-test-with-temp-text "* [[b][a<point>]]\n* b"
+     (let ((org-return-follows-link t))
+       (org-return))
+     (org-looking-at-p "* b")))
   ;; However, do not open link when point is in a table.
   (should
    (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
-- 
2.1.4


             reply	other threads:[~2015-08-12 20:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-12 20:49 Alexey Lebedeff [this message]
2015-08-13  0:46 ` [PATCH] `org-return' in 8.3 no longer follows links in headings Nicolas Goaziou

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='CADOt_n8JE=mSf0wY10vHQscfsAMtQzu7f5dkKCZDbWNdH1u6Lw@mail.gmail.com' \
    --to=binarin@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).