From 149b8046ac585d14972679ecd21fd4de63d7c466 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sun, 18 Sep 2016 17:22:48 +0200 Subject: [PATCH] `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. --- etc/ORG-NEWS | 5 ++++- lisp/org.el | 14 ++++++-------- testing/lisp/test-org.el | 29 +++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 6e003d293..9342cb26f 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 5c9a07c1e..a8ede1dc4 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 f1849e31a..96f1ecd60 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| 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| 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.