Hi Carsten

On Thu, Aug 8, 2013 at 8:43 AM, Carsten Dominik
<carsten.domi...@gmail.com> wrote:
> I have rewritten org-insert-heading, because it had become an unmaintainable 
> beast.
> Please follow up in this thread if you find problems with the new 
> implementation.
> Very likely there will be bugs, but now I am at least confident they can be 
> fixed.

On the way of rewiring my muscle memory from C-RET to M-RET for some
cases, I stumbled across this:

#+DRAWERS: MyStructuredDrawer
:MyStructuredDrawer:
- a
:END:

To insert a new item I once changed to use C-RET also on items. How is
one supposed to do this now within a drawer? M-RET just inserts an
empty line. I would like to suggest the attached patches with an ERT.
They change (fix?) org-meta-return to insert a new item in this case.

About the following different issue I don't care as much and only
wanted to report: C-RET before any headline when within a drawer, or
generally before any headline(?), could bark instead of changing to a
headline leading to invalid Org syntax within a drawer.

Michael
From 6bc4c15c4a76a98c841e8a200c75f5a0737ffece Mon Sep 17 00:00:00 2001
From: Michael Brand <michael.ch.br...@gmail.com>
Date: Mon, 9 Sep 2013 18:38:58 +0200
Subject: [PATCH 1/2] Add ERTs for org-meta-return

* testing/lisp/test-org-list.el (test-org-list/insert-item): Adapt
docstring.
* (test-org-list/meta-return): New `ert-deftest' to test
`org-meta-return'.
---
 testing/lisp/test-org-list.el | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/testing/lisp/test-org-list.el b/testing/lisp/test-org-list.el
index ac81d4d..ea19606 100644
--- a/testing/lisp/test-org-list.el
+++ b/testing/lisp/test-org-list.el
@@ -627,7 +627,7 @@
     (should (org-invisible-p2))))
 
 (ert-deftest test-org-list/insert-item ()
-  "Test item insertion."
+  "Test item insertion with `org-insert-item'."
   ;; Blank lines specifications.
   ;;
   ;; Non-nil `org-blank-before-new-entry': insert a blank line, unless
@@ -713,6 +713,22 @@
        (forward-line -1)
        (looking-at "$")))))
 
+(ert-deftest test-org-list/meta-return ()
+  "Test item insertion with `org-meta-return'."
+  (should
+   (org-test-with-temp-text "- a"
+     (org-meta-return)
+     (beginning-of-line)
+     (looking-at "- $")))
+  ;; TODO Insert an item also in a drawer.
+  (should
+   (let ((org-drawers '("MYDRAWER")))
+     (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
+       (forward-line)
+       (org-meta-return)
+       (forward-line -1)
+       (looking-at "$")))))
+
 (ert-deftest test-org-list/repair ()
   "Test `org-list-repair' specifications."
   ;; Repair indentation.
-- 
1.7.12.4 (Apple Git-37)

From 9896499fb7f497a13857b5b86f33cfbf1b918029 Mon Sep 17 00:00:00 2001
From: Michael Brand <michael.ch.br...@gmail.com>
Date: Mon, 9 Sep 2013 18:40:07 +0200
Subject: [PATCH 2/2] org-meta-return: Insert an item also in a drawer

* lisp/org.el (org-meta-return): Exclude item from cond for drawer.
* testing/lisp/test-org-list.el (test-org-list/meta-return): On an
item in a drawer expect an item to be inserted.
---
 lisp/org.el                   | 3 ++-
 testing/lisp/test-org-list.el | 6 +++---
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 59a22a2..edc8725 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -20698,7 +20698,8 @@ See the individual commands for more information."
   (org-check-before-invisible-edit 'insert)
   (cond
    ((run-hook-with-args-until-success 'org-metareturn-hook))
-   ((or (org-at-drawer-p) (org-in-drawer-p) (org-at-property-p))
+   ((and (or (org-at-drawer-p) (org-in-drawer-p) (org-at-property-p))
+        (not (org-in-item-p)))
     (newline-and-indent))
    ((org-at-table-p)
     (call-interactively 'org-table-wrap-region))
diff --git a/testing/lisp/test-org-list.el b/testing/lisp/test-org-list.el
index ea19606..f3ced15 100644
--- a/testing/lisp/test-org-list.el
+++ b/testing/lisp/test-org-list.el
@@ -720,14 +720,14 @@
      (org-meta-return)
      (beginning-of-line)
      (looking-at "- $")))
-  ;; TODO Insert an item also in a drawer.
+  ;; Insert an item also in a drawer.
   (should
    (let ((org-drawers '("MYDRAWER")))
      (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
        (forward-line)
        (org-meta-return)
-       (forward-line -1)
-       (looking-at "$")))))
+       (beginning-of-line)
+       (looking-at "- $")))))
 
 (ert-deftest test-org-list/repair ()
   "Test `org-list-repair' specifications."
-- 
1.7.12.4 (Apple Git-37)

Reply via email to