summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2016-10-28 19:48:47 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2016-12-10 00:32:15 +0100
commitc8da8529f5b9e063238ce79d07a17ba16ebf6ccb (patch)
tree56b0b6bf2a7435a8554f63933d6085cf7bfc8e63
parent68d8f860cd0b898a02f60ec3b4781f4ddf7d2627 (diff)
downloadorg-mode-c8da8529f5b9e063238ce79d07a17ba16ebf6ccb.tar.gz
`org-insert-heading' doesn't create items anymore
* lisp/org.el (org-insert-heading): Specialize function for headlines, not items. (org-meta-return): Update according to new specifications above. * lisp/org-list.el (org-insert-item): Add interactive spec. * doc/org.texi (Structure editing): Update documentation. * testing/lisp/test-org.el (test-org/insert-heading): Remove tests. * testing/lisp/test-org-list.el (test-org-list/insert-item): Add test.
-rw-r--r--doc/org.texi4
-rw-r--r--lisp/org-list.el1
-rw-r--r--lisp/org.el39
-rw-r--r--testing/lisp/test-org-list.el14
-rw-r--r--testing/lisp/test-org.el34
5 files changed, 34 insertions, 58 deletions
diff --git a/doc/org.texi b/doc/org.texi
index f7d289b..0de790e 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -1415,9 +1415,9 @@ See also the option @code{org-goto-interface}.
@cindex subtrees, cut and paste
@table @asis
-@orgcmd{M-@key{RET},org-insert-heading}
+@orgcmd{M-@key{RET},org-meta-return}
@vindex org-M-RET-may-split-line
-Insert a new heading/item with the same level as the one at point.
+Insert a new heading, item or row.
If the command is used at the @emph{beginning} of a line, and if there is
a heading or a plain list item (@pxref{Plain lists}) at point, the new
diff --git a/lisp/org-list.el b/lisp/org-list.el
index bb39b6e..e3a51d0 100644
--- a/lisp/org-list.el
+++ b/lisp/org-list.el
@@ -2242,6 +2242,7 @@ If CHECKBOX is non-nil, add a checkbox next to the bullet.
Return t when things worked, nil when we are not in an item, or
item is invisible."
+ (interactive "P")
(let ((itemp (org-in-item-p))
(pos (point)))
;; If cursor isn't is a list or if list is invisible, return nil.
diff --git a/lisp/org.el b/lisp/org.el
index 386e641..f642000 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -7940,12 +7940,12 @@ headline instead of current one."
(defun org-insert-heading (&optional arg invisible-ok top)
"Insert a new heading or an item with the same depth at point.
-If point is at the beginning of a heading or a list item, insert
-a new heading or a new item above the current one. When at the
-beginning of a regular line of text, turn it into a heading.
+If point is at the beginning of a heading, insert a new heading
+or a new headline above the current one. When at the beginning
+of a regular line of text, turn it into a heading.
If point is in the middle of a line, split it and create a new
-headline/item with the text in the current line after point (see
+headline with the text in the current line after point (see
`org-M-RET-may-split-line' on how to modify this behavior). As
a special case, on a headline, splitting can only happen on the
title itself. E.g., this excludes breaking stars or tags.
@@ -7991,8 +7991,7 @@ unconditionally."
(unless (and blank? (org-previous-line-empty-p))
(org-N-empty-lines-before-current (if blank? 1 0)))
(insert (make-string (if (and level (not top)) level 1) ?*) " \n")
- (forward-char -1)
- (run-hooks 'org-insert-heading-hook)))
+ (forward-char -1)))
;; At a headline...
((org-at-heading-p)
(let ((level (if top 1 (org-current-level))))
@@ -8022,24 +8021,20 @@ unconditionally."
(end-of-line)
(when blank? (insert "\n"))
(insert "\n" (make-string level ?*) " \n")
- (forward-char -1)))
- (run-hooks 'org-insert-heading-hook)))
- ;; Within a plain list, call `org-insert-item'.
- ((and (not top) (org-in-item-p)) (org-insert-item))
+ (forward-char -1)))))
;; On regular text, turn line into a headline or split, if
;; appropriate.
((bolp)
(insert "* ")
(unless (and blank? (org-previous-line-empty-p))
- (org-N-empty-lines-before-current (if blank? 1 0)))
- (run-hooks 'org-insert-heading-hook))
+ (org-N-empty-lines-before-current (if blank? 1 0))))
(t
(unless (org-get-alist-option org-M-RET-may-split-line 'headline)
(end-of-line))
(insert "\n* ")
(unless (and blank? (org-previous-line-empty-p))
- (org-N-empty-lines-before-current (if blank? 1 0)))
- (run-hooks 'org-insert-heading-hook)))))
+ (org-N-empty-lines-before-current (if blank? 1 0))))))
+ (run-hooks 'org-insert-heading-hook))
(defun org-N-empty-lines-before-current (N)
"Make the number of empty lines before current exactly N.
@@ -19916,7 +19911,6 @@ boundaries."
(org-defkey org-mode-map "\C-c/" 'org-sparse-tree) ; Minor-mode reserved
(org-defkey org-mode-map "\C-c\\" 'org-match-sparse-tree) ; Minor-mode res.
(org-defkey org-mode-map "\C-c\C-m" 'org-ctrl-c-ret)
-(org-defkey org-mode-map "\M-\C-m" 'org-insert-heading)
(org-defkey org-mode-map "\C-c\C-xc" 'org-clone-subtree-with-time-shift)
(org-defkey org-mode-map "\C-c\C-xv" 'org-copy-visible)
(org-defkey org-mode-map [(control return)] 'org-insert-heading-respect-content)
@@ -21521,15 +21515,18 @@ number of stars to add."
(forward-line)))))))
(unless toggled (message "Cannot toggle heading from here"))))
-(defun org-meta-return (&optional _arg)
+(defun org-meta-return (&optional arg)
"Insert a new heading or wrap a region in a table.
-Calls `org-insert-heading' or `org-table-wrap-region', depending
-on context. See the individual commands for more information."
- (interactive)
+Calls `org-insert-heading', `org-insert-item' or
+`org-table-wrap-region', depending on context. When called with
+an argument, unconditionally call `org-insert-heading'."
+ (interactive "P")
(org-check-before-invisible-edit 'insert)
(or (run-hook-with-args-until-success 'org-metareturn-hook)
- (call-interactively (if (org-at-table-p) #'org-table-wrap-region
- #'org-insert-heading))))
+ (call-interactively (cond (arg #'org-insert-heading)
+ ((org-at-table-p) #'org-table-wrap-region)
+ ((org-in-item-p) #'org-insert-item)
+ (t #'org-insert-heading)))))
;;; Menu entries
diff --git a/testing/lisp/test-org-list.el b/testing/lisp/test-org-list.el
index 1fc1b4d..1ddbaa5 100644
--- a/testing/lisp/test-org-list.el
+++ b/testing/lisp/test-org-list.el
@@ -735,7 +735,19 @@
(org-test-with-temp-text "- it<point>em"
(let ((org-M-RET-may-split-line '((default . nil))))
(org-insert-item))
- (buffer-string)))))
+ (buffer-string))))
+ ;; Preserve list visibility when inserting an item.
+ (should
+ (equal
+ '(outline outline)
+ (org-test-with-temp-text "- A\n - B\n- C\n - D"
+ (let ((org-cycle-include-plain-lists t))
+ (org-cycle)
+ (forward-line 2)
+ (org-cycle)
+ (org-insert-item)
+ (list (get-char-property (line-beginning-position 0) 'invisible)
+ (get-char-property (line-end-position 2) 'invisible)))))))
(ert-deftest test-org-list/repair ()
"Test `org-list-repair' specifications."
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index 5aa4460..5e850bf 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -1213,40 +1213,6 @@
(let ((org-M-RET-may-split-line '((headline . t))))
(org-insert-heading))
(buffer-string))))
- ;; When on a list, insert an item instead, unless called with an
- ;; universal argument or if list is invisible. In this case, create
- ;; a new headline after contents.
- (should
- (equal "* H\n- item\n- "
- (org-test-with-temp-text "* H\n- item<point>"
- (let ((org-insert-heading-respect-content nil))
- (org-insert-heading))
- (buffer-string))))
- (should
- (equal "* H\n- item\n- item 2\n* \n"
- (org-test-with-temp-text "* H\n- item<point>\n- item 2"
- (let ((org-insert-heading-respect-content nil))
- (org-insert-heading '(4)))
- (buffer-string))))
- (should
- (equal "* H\n- item\n* \n"
- (org-test-with-temp-text "* H\n- item"
- (org-cycle)
- (goto-char (point-max))
- (let ((org-insert-heading-respect-content nil)) (org-insert-heading))
- (buffer-string))))
- ;; Preserve list visibility when inserting an item.
- (should
- (equal
- '(outline outline)
- (org-test-with-temp-text "- A\n - B\n- C\n - D"
- (let ((org-cycle-include-plain-lists t))
- (org-cycle)
- (forward-line 2)
- (org-cycle)
- (let ((org-insert-heading-respect-content nil)) (org-insert-heading))
- (list (get-char-property (line-beginning-position 0) 'invisible)
- (get-char-property (line-end-position 2) 'invisible))))))
;; When called with one universal argument, insert a new headline at
;; the end of the current subtree, independently on the position of
;; point.