diff options
author | Alexey Lebedeff <binarin@gmail.com> | 2015-08-12 23:02:49 +0300 |
---|---|---|
committer | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2015-08-13 02:25:17 +0200 |
commit | 997a9a45d96e8f464cde2665e6dc3d62b71efabb (patch) | |
tree | f626beda32b3d014a608ff14586a1e522337bc23 | |
parent | c8e3bc2bbcfbc40b978261f15dd0f53b7278718c (diff) | |
download | org-mode-997a9a45d96e8f464cde2665e6dc3d62b71efabb.tar.gz |
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.
* testing/lisp/test-org.el (test-org/return): Add test.
This patch restores order in which `org-return' perform actions (which
was changed in a7e62499f2fe5c313567212ee90ff743c5e734a8).
TINYCHANGE
-rwxr-xr-x | lisp/org.el | 63 | ||||
-rw-r--r-- | testing/lisp/test-org.el | 6 |
2 files changed, 38 insertions, 31 deletions
diff --git a/lisp/org.el b/lisp/org.el index 0232091..a8ee03e 100755 --- a/lisp/org.el +++ b/lisp/org.el @@ -21289,7 +21289,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. @@ -21319,36 +21340,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))))))) + (when 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..92be6f4 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>> |" |