summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2016-09-18 17:22:48 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2016-09-18 17:22:48 +0200
commit149b8046ac585d14972679ecd21fd4de63d7c466 (patch)
treeb544032f55b85c162a2ae7cd9f535819e2a412fa
parenta1f51c8655e5e41f3be8eda58654ed6f8bcce799 (diff)
downloadorg-mode-149b8046ac585d14972679ecd21fd4de63d7c466.tar.gz
`org-open-line' ignores tables at the very beginning of the document
* lisp/org.el (org-open-line): Ignore tables at the very beginning of the document. * testing/lisp/test-org.el (test-org/open-line): New test.
-rw-r--r--etc/ORG-NEWS5
-rw-r--r--lisp/org.el14
-rw-r--r--testing/lisp/test-org.el29
3 files changed, 39 insertions, 9 deletions
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 6e003d2..9342cb2 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -518,7 +518,10 @@ to force opening it in either Emacs or with system application.
*** New defalias ~org-babel-execute:j~
Allows J source blocks be indicated by letter j. Previously the
indication letter was solely J.
-
+*** ~org-open-line~ ignores tables at the very beginning of the buffer
+When ~org-special-ctrl-o~ is non-nil, it is impractical to create
+a blank line above a table at the beginning of the document. Now, as
+a special case, ~org-open-line~ behaves normally in this situation.
* Version 8.3
** Incompatible changes
diff --git a/lisp/org.el b/lisp/org.el
index 5c9a07c..a8ede1d 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -21291,15 +21291,13 @@ With argument, join this line to following line."
(defun org-open-line (n)
"Insert a new row in tables, call `open-line' elsewhere.
-If `org-special-ctrl-o' is nil, just call `open-line' everywhere."
+If `org-special-ctrl-o' is nil, just call `open-line' everywhere.
+As a special case, when a document starts with a table, allow to
+call `open-line' on the very first character."
(interactive "*p")
- (cond
- ((not org-special-ctrl-o)
- (open-line n))
- ((org-at-table-p)
- (org-table-insert-row))
- (t
- (open-line n))))
+ (if (and org-special-ctrl-o (/= (point) 1) (org-at-table-p))
+ (org-table-insert-row)
+ (open-line n)))
(defun org-return (&optional indent)
"Goto next table row or insert a newline.
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index f1849e3..96f1ecd 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -2487,6 +2487,35 @@ http://article.gmane.org/gmane.emacs.orgmode/21459/"
(org-end-of-line)
(eobp)))))
+(ert-deftest test-org/open-line ()
+ "Test `org-open-line' specifications."
+ ;; Call `open-line' outside of tables.
+ (should
+ (equal "\nText"
+ (org-test-with-temp-text "Text"
+ (org-open-line 1)
+ (buffer-string))))
+ ;; At a table, create a row above.
+ (should
+ (equal "\n| |\n| a |"
+ (org-test-with-temp-text "\n<point>| a |"
+ (org-open-line 1)
+ (buffer-string))))
+ ;; At the very first character of the buffer, also call `open-line'.
+ (should
+ (equal "\n| a |"
+ (org-test-with-temp-text "| a |"
+ (org-open-line 1)
+ (buffer-string))))
+ ;; Narrowing does not count.
+ (should
+ (equal "Text\n| |\n| a |"
+ (org-test-with-temp-text "Text\n<point>| a |"
+ (narrow-to-region (point) (point-max))
+ (org-open-line 1)
+ (widen)
+ (buffer-string)))))
+
(ert-deftest test-org/forward-sentence ()
"Test `org-forward-sentence' specifications."
;; At the end of a table cell, move to the end of the next one.