Browse Source

`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.
Nicolas Goaziou 2 years ago
parent
commit
c8da8529f5
5 changed files with 34 additions and 58 deletions
  1. 2 2
      doc/org.texi
  2. 1 0
      lisp/org-list.el
  3. 18 21
      lisp/org.el
  4. 13 1
      testing/lisp/test-org-list.el
  5. 0 34
      testing/lisp/test-org.el

+ 2 - 2
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

+ 1 - 0
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.

+ 18 - 21
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
 

+ 13 - 1
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."

+ 0 - 34
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.