Re: [O] [patch, koma-letter] Change of subject behavior

2015-03-20 Thread Rasmus
Nicolas Goaziou m...@nicolasgoaziou.fr writes:

 AFAIC, you can push the patches, when the above is fixed. Thank you.

Pushed:

304a5cb ox-koma-letter: Interpret #+SUBJECT.
a795d9e ox-koma-letter: Stricter subject inference
c4d4e5e ox-koma-letter: Tiny refactor

—Rasmus

-- 
Bang bang



Re: [O] [patch, koma-letter] Change of subject behavior

2015-03-19 Thread Rasmus
Hi Nicolas,

Excellent comments.  Thanks a lot!

Nicolas Goaziou m...@nicolasgoaziou.fr writes:

 In this case, I suggest to change `org-koma-letter--special-headline'
 into `org-koma-letter--special-tag'

I agree.

 Eventually, since you're only interested in the first special tag
 encountered, it may be cleaner to exit early, e.g.,

Good idea.  I did it slightly differently with a funcall, but perhaps it's
slower (I have no idea).

 +   (format \\opening{%s}\n\n
 +   (org-export-data
 +(or (org-string-nw-p (plist-get info :opening))
 +(when (plist-get info :with-headline-opening)
 +  (org-element-map (org-element-parse-buffer) 'headline
^
   (plist-get info :parse-tree)

Thanks.  I *knew* it was fishy.

—Rasmus

-- 
Hooray!
From 5f6832704d011b4b966b52c0dc1f6076f7af6ea7 Mon Sep 17 00:00:00 2001
From: Rasmus ras...@gmx.us
Date: Wed, 18 Mar 2015 13:33:42 +0100
Subject: [PATCH 3/3] ox-koma-letter: Interpret #+SUBJECT.

* ox-koma-letter.el (org-koma-letter-template): Interpret #+SUBJECT.
---
 contrib/lisp/ox-koma-letter.el | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/contrib/lisp/ox-koma-letter.el b/contrib/lisp/ox-koma-letter.el
index 33c8a1b..796b917 100644
--- a/contrib/lisp/ox-koma-letter.el
+++ b/contrib/lisp/ox-koma-letter.el
@@ -630,7 +630,11 @@ holding export options.
 		(mapconcat #'symbol-name with-subject ,
 	(let* ((title-as-subject (plist-get info :with-title-as-subject))
 	   (subject* (org-string-nw-p
-			  (org-export-data (plist-get info :subject) info)))
+			  (org-export-data
+			   (org-element-parse-secondary-string
+			(plist-get info :subject)
+			(org-element-restriction 'keyword))
+			   info)))
 	   (title* (and (plist-get info :with-title)
 			(org-string-nw-p
 			 (org-export-data (plist-get info :title) info
-- 
2.3.3

From 6f042fd397e7f3f5b4844921800a68b3ba91c403 Mon Sep 17 00:00:00 2001
From: Rasmus ras...@gmx.us
Date: Thu, 19 Mar 2015 12:10:30 +0100
Subject: [PATCH 2/3] ox-koma-letter: Stricter subject inference

* ox-koma-letter.el (org-koma-letter--special-tag): New function.
  (org-koma-letter-headline): Use org-koma-letter--special-tag
  and do not guess opening.
  (org-koma-letter-template): Directly infer subject from first
  non-special headline.
---
 contrib/lisp/ox-koma-letter.el | 41 +++--
 1 file changed, 27 insertions(+), 14 deletions(-)

diff --git a/contrib/lisp/ox-koma-letter.el b/contrib/lisp/ox-koma-letter.el
index 23da930..33c8a1b 100644
--- a/contrib/lisp/ox-koma-letter.el
+++ b/contrib/lisp/ox-koma-letter.el
@@ -412,6 +412,7 @@ was not present.
 (:with-place nil place org-koma-letter-use-place)
 (:with-subject nil subject org-koma-letter-subject-format)
 (:with-title-as-subject nil title-subject org-koma-letter-prefer-subject)
+(:with-headline-opening nil nil org-koma-letter-headline-is-opening-maybe)
 ;; Special properties non-nil when a setting happened in buffer.
 ;; They are used to prioritize in-buffer settings over lco
 ;; files.  See `org-koma-letter-template'.
@@ -553,19 +554,21 @@ Note that if a headline is tagged with a tag from
 `org-koma-letter-special-tags' it will not be exported, but
 stored in `org-koma-letter-special-contents' and included at the
 appropriate place.
-  (unless (let ((tag (car (org-export-get-tags headline info
-	(and tag
-		 (member-ignore-case
-		  tag (mapcar #'symbol-name (plist-get info :special-tags)))
-		 ;; Store association for later use and bail out.
-		 (push (cons tag contents) org-koma-letter-special-contents)))
-;; Opening is not defined yet: use headline's title.
-(when (and org-koma-letter-headline-is-opening-maybe
-	   (not (org-string-nw-p (plist-get info :opening
-  (plist-put info :opening
-		 (org-export-data (org-element-property :title headline) info)))
-;; In any case, insert contents in letter's body.
-contents))
+  (let ((special-tag (org-koma-letter--special-tag headline info)))
+(if (not special-tag)
+	contents
+  (push (cons special-tag contents) org-koma-letter-special-contents)
+  )))
+
+(defun org-koma-letter--special-tag (headline info)
+  Non-nil if HEADLINE is a special headline.
+INFO is a plist holding contextual information.  Returns first
+special tag headline.
+  (let ((special-tags (plist-get info :special-tags)))
+(catch 'exit
+  (dolist (tag (org-export-get-tags headline info))
+	(funcall (lambda (tag) (when tag (throw 'exit tag)))
+		 (assoc-string tag special-tags))
 
  Template
 
@@ -641,7 +644,17 @@ holding export options.
(format \\begin{letter}{%%\n%s}\n\n
 	   (org-koma-letter--determine-to-and-from info 'to))
;; Opening.
-   (format \\opening{%s}\n\n (plist-get info :opening))
+   (format \\opening{%s}\n\n
+	   (org-export-data
+	(or 

Re: [O] [patch, koma-letter] Change of subject behavior

2015-03-19 Thread Nicolas Goaziou
Rasmus ras...@gmx.us writes:

 +(defun org-koma-letter--special-tag (headline info)
 +  Non-nil if HEADLINE is a special headline.
 +INFO is a plist holding contextual information.  Returns first
^^^
Return, per (info (elisp)Documentation Tips)
   
 +special tag headline.
 +  (let ((special-tags (plist-get info :special-tags)))
 +(catch 'exit
 +  (dolist (tag (org-export-get-tags headline info))
 + (funcall (lambda (tag) (when tag (throw 'exit tag)))
 +  (assoc-string tag special-tags))

This is the usual definition for (let ...), i.e., you just wrote

  (let ((tag (assoc-string tag special-tags)))
(when tag (throw 'exit tag)))

Please just use `let', as it is much more readable.

AFAIC, you can push the patches, when the above is fixed. Thank you.


Regards,



Re: [O] [patch, koma-letter] Change of subject behavior

2015-03-18 Thread Nicolas Goaziou
Rasmus ras...@gmx.us writes:

 + (:with-headline-opening nil nil
 org-koma-letter-headline-is-opening-maybe)

 I don't think this line is required.

 It feels more consistent to provide the check through the definition, but
 I'm not willing to pick a fight over this so it's back to just checking
 the variable.

Of course, you're right. It is way better to add it as an option, since
you can override variable value during publishing. You can irrevocably
ignore my comment.

 I have only tested the patch briefly as I need to actually produce a
 letter.  But for the letter I'm writing export works fine.

You sent a wrong patch.


Regards,



Re: [O] [patch, koma-letter] Change of subject behavior

2015-03-18 Thread Rasmus
Nicolas Goaziou m...@nicolasgoaziou.fr writes:


 I have only tested the patch briefly as I need to actually produce a
 letter.  But for the letter I'm writing export works fine.

 You sent a wrong patch.

Ups.  Let's try again.

In the second patch I fix the no interpretation of #+SUBJECT.

—Rasmus

-- 
Lasciate ogni speranza, voi che leggete questo.
From 0d8e0f21f3c120afef3e08628962f7fa99337aef Mon Sep 17 00:00:00 2001
From: Rasmus ras...@gmx.us
Date: Wed, 18 Mar 2015 13:33:42 +0100
Subject: [PATCH 2/2] ox-koma-letter: Interpret #+SUBJECT.

* ox-koma-letter.el (org-koma-letter-template): Interpret #+SUBJECT.
---
 contrib/lisp/ox-koma-letter.el | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/contrib/lisp/ox-koma-letter.el b/contrib/lisp/ox-koma-letter.el
index d7572b5..e7be56a 100644
--- a/contrib/lisp/ox-koma-letter.el
+++ b/contrib/lisp/ox-koma-letter.el
@@ -626,7 +626,11 @@ holding export options.
 		(mapconcat #'symbol-name with-subject ,
 	(let* ((title-as-subject (plist-get info :with-title-as-subject))
 	   (subject* (org-string-nw-p
-			  (org-export-data (plist-get info :subject) info)))
+			  (org-export-data
+			   (org-element-parse-secondary-string
+			(plist-get info :subject)
+			(org-element-restriction 'keyword))
+			   info)))
 	   (title* (and (plist-get info :with-title)
 			(org-string-nw-p
 			 (org-export-data (plist-get info :title) info
-- 
2.3.3

From a7289286b0b02310b4e3f714fc7047f7af7a027c Mon Sep 17 00:00:00 2001
From: Rasmus ras...@gmx.us
Date: Tue, 17 Mar 2015 18:32:26 +0100
Subject: [PATCH 1/2] ox-koma-letter: Stricter subject inference

* ox-koma-letter.el (org-koma-letter--special-headline): New function.
  (org-koma-letter--get-tagged-contents): Refactor
  (org-koma-letter-headline): Use org-koma-letter--special-headline
  and do not guess opening.
  (org-koma-letter-template): Directly infer subject from first
  non-special headline.
---
 contrib/lisp/ox-koma-letter.el | 41 +
 1 file changed, 25 insertions(+), 16 deletions(-)

diff --git a/contrib/lisp/ox-koma-letter.el b/contrib/lisp/ox-koma-letter.el
index 1b5dd17..d7572b5 100644
--- a/contrib/lisp/ox-koma-letter.el
+++ b/contrib/lisp/ox-koma-letter.el
@@ -412,6 +412,7 @@ was not present.
 (:with-place nil place org-koma-letter-use-place)
 (:with-subject nil subject org-koma-letter-subject-format)
 (:with-title-as-subject nil title-subject org-koma-letter-prefer-subject)
+(:with-headline-opening nil nil org-koma-letter-headline-is-opening-maybe)
 ;; Special properties non-nil when a setting happened in buffer.
 ;; They are used to prioritize in-buffer settings over lco
 ;; files.  See `org-koma-letter-template'.
@@ -453,8 +454,8 @@ was not present.
 (defun org-koma-letter--get-tagged-contents (key)
   Get contents from a headline tagged with KEY.
 The contents is stored in `org-koma-letter-special-contents'.
-  (cdr (assoc (org-koma-letter--get-value key)
-	  org-koma-letter-special-contents)))
+  (cdr (assoc-string (org-koma-letter--get-value key)
+		 org-koma-letter-special-contents)))
 
 (defun org-koma-letter--get-value (value)
   Turn value into a string whenever possible.
@@ -553,19 +554,17 @@ Note that if a headline is tagged with a tag from
 `org-koma-letter-special-tags' it will not be exported, but
 stored in `org-koma-letter-special-contents' and included at the
 appropriate place.
-  (unless (let ((tag (car (org-export-get-tags headline info
-	(and tag
-		 (member-ignore-case
-		  tag (mapcar #'symbol-name (plist-get info :special-tags)))
-		 ;; Store association for later use and bail out.
-		 (push (cons tag contents) org-koma-letter-special-contents)))
-;; Opening is not defined yet: use headline's title.
-(when (and org-koma-letter-headline-is-opening-maybe
-	   (not (org-string-nw-p (plist-get info :opening
-  (plist-put info :opening
-		 (org-export-data (org-element-property :title headline) info)))
-;; In any case, insert contents in letter's body.
-contents))
+  (let ((special-tag (car (org-koma-letter--special-headline headline info
+(if special-tag
+	(progn (push (cons special-tag contents) org-koma-letter-special-contents)
+	   )
+  contents)))
+
+(defun org-koma-letter--special-headline (headline info)
+  Nonnil if HEADLINE is a special headline.
+  (let ((special-tags (plist-get info :special-tags)))
+(mapcar (lambda (tag) (assoc-string tag special-tags))
+	(org-export-get-tags headline info
 
  Template
 
@@ -641,7 +640,17 @@ holding export options.
(format \\begin{letter}{%%\n%s}\n\n
 	   (org-koma-letter--determine-to-and-from info 'to))
;; Opening.
-   (format \\opening{%s}\n\n (plist-get info :opening))
+   (format \\opening{%s}\n\n
+	   (org-export-data
+	(or (org-string-nw-p (plist-get info :opening))
+		(when (plist-get info :with-headline-opening)
+		  (org-element-map 

Re: [O] [patch, koma-letter] Change of subject behavior

2015-03-18 Thread Nicolas Goaziou
Rasmus ras...@gmx.us writes:

 -  (cdr (assoc (org-koma-letter--get-value key)
 -   org-koma-letter-special-contents)))
 +  (cdr (assoc-string (org-koma-letter--get-value key)
 +  org-koma-letter-special-contents)))

AFAIU, this is a bugfix, so it should go in a separate commit.

 +  (let ((special-tag (car (org-koma-letter--special-headline headline 
 info
 +(if special-tag
 + (progn (push (cons special-tag contents) 
 org-koma-letter-special-contents)
 +)
 +  contents)))

Nitpick:

  (if (not special-tag) contents
(push ...)
)

In this case, I suggest to change `org-koma-letter--special-headline'
into `org-koma-letter--special-tag', where the latter explicitly returns
special tag associated to the current headline, or nil (this skips the
`car' part).

 +(defun org-koma-letter--special-headline (headline info)
 +  Nonnil if HEADLINE is a special headline.
 +  (let ((special-tags (plist-get info :special-tags)))
 +(mapcar (lambda (tag) (assoc-string tag special-tags))
 + (org-export-get-tags headline info

Non-nil

Also, the docstring should document INFO. Moreover, it isn't really
a predicate anymore, since you're using the value returned. Thus, that
value should be explained.

Eventually, since you're only interested in the first special tag
encountered, it may be cleaner to exit early, e.g.,

  (defun org-koma-letter--special-tag (headline info)
Return special tag associated to HEADLINE, as a symbol, or nil.
  INFO is the current state of the export process, as a plist.
(let ((special-tags (plist-get info :special-tags)))
  (catch 'exit
(dolist (tag (org-export-get-tags headline info))
  (let ((special-match (assoc-string tag special-tags)))
(when special-match (throw 'exit (car special-match


 +   (format \\opening{%s}\n\n
 +(org-export-data
 + (or (org-string-nw-p (plist-get info :opening))
 + (when (plist-get info :with-headline-opening)
 +   (org-element-map (org-element-parse-buffer) 'headline
   ^
  (plist-get info :parse-tree)

Regards,



Re: [O] [patch, koma-letter] Change of subject behavior

2015-03-17 Thread Nicolas Goaziou
Hello,

Rasmus ras...@gmx.us writes:

 I want to change the subject inference in ox-koma-letter to only happen on
 top-level headlines.

 Thus, in the following example the opening would be opening and not h1
 as it is currently.

 * opening
 ** h1

 Typically, h1 is just there to help me organize the letter.

 Any objections?

This is a bug indeed.

However, I don't think :opening setting belongs to
`org-koma-letter-headline', as it means it is potentially set each time
a headline is being processed.

The (when ...) could be moved within `org-koma-letter-template', where
\opening{...} is filled and the first headline without a special tag
in the parse tree could be used (assuming there's no special
keyword...). That headline can be found using `org-element-map'.

Another (smallish) advantage is that the following case would be
allowed:

  * Dear myself,
  * Part 1

WDYT?

Regards,

-- 
Nicolas Goaziou



[O] [patch, koma-letter] Change of subject behavior

2015-03-17 Thread Rasmus
Hi,

I want to change the subject inference in ox-koma-letter to only happen on
top-level headlines.

Thus, in the following example the opening would be opening and not h1
as it is currently.

* opening
** h1

Typically, h1 is just there to help me organize the letter.

Any objections?

—Rasmus

-- 
Together we will make the possible totay impossible!
From 2ce18b7f061109f0006fb1b823029d35fee4f9a9 Mon Sep 17 00:00:00 2001
From: Rasmus ras...@gmx.us
Date: Tue, 17 Mar 2015 18:32:26 +0100
Subject: [PATCH] ox-koma-letter: Stricter subject inference

* ox-koma-letter.el (org-koma-letter-headline): Subject can
  only be inferred from top-level heading.
---
 contrib/lisp/ox-koma-letter.el | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/contrib/lisp/ox-koma-letter.el b/contrib/lisp/ox-koma-letter.el
index 1b5dd17..1e905a9 100644
--- a/contrib/lisp/ox-koma-letter.el
+++ b/contrib/lisp/ox-koma-letter.el
@@ -561,7 +561,8 @@ appropriate place.
 		 (push (cons tag contents) org-koma-letter-special-contents)))
 ;; Opening is not defined yet: use headline's title.
 (when (and org-koma-letter-headline-is-opening-maybe
-	   (not (org-string-nw-p (plist-get info :opening
+	   (not (org-string-nw-p (plist-get info :opening)))
+	   (eq 1 (org-export-get-relative-level headline info)))
   (plist-put info :opening
 		 (org-export-data (org-element-property :title headline) info)))
 ;; In any case, insert contents in letter's body.
-- 
2.3.3



Re: [O] [patch, koma-letter] Change of subject behavior

2015-03-17 Thread Nicolas Goaziou
Rasmus ras...@gmx.us writes:

 Nicolas Goaziou m...@nicolasgoaziou.fr writes:

 However, I don't think :opening setting belongs to
 `org-koma-letter-headline', as it means it is potentially set each time
 a headline is being processed.

 The property is at most set once cf. the second clause.

By potentially set, I meant the (trivial) check would be done
nonetheless, which is a waste.

 Another (smallish) advantage is that the following case would be
 allowed:

   * Dear myself,
   * Part 1

 Is the advantage that it won't fold?

No, since

  * Dear myself,
  * Part 1

won't fold either, but in ** Dear myself, stands out and doesn't
look like a standard container.

 I updated the patch.  Perhaps the loop determination shod be moved to a
 separate function to keep the template clean.

Yes, it needs to be factored out (maybe
`org-koma-letter--special-headline-p') since it is also used in
`org-koma-letter-headline'. What about

  (defun org-koma-letter--special-headline-p (h info)
(let ((special-tags (plist-get info :special-tags)))
  (org-some (lambda (tag) (assoc-string tag special-tags))
(org-export-get-tags h info

 I thinking this cause we (or at least I) sometimes point to
 ox-koma-letter as an example of a derived backend. WDTY on that?

What do you mean?

 +(:with-headline-opening nil nil 
 org-koma-letter-headline-is-opening-maybe)

I don't think this line is required.


Regards,



Re: [O] [patch, koma-letter] Change of subject behavior

2015-03-17 Thread Rasmus
Nicolas Goaziou m...@nicolasgoaziou.fr writes:


 However, I don't think :opening setting belongs to
 `org-koma-letter-headline', as it means it is potentially set each time
 a headline is being processed.

The property is at most set once cf. the second clause.

 The (when ...) could be moved within `org-koma-letter-template', where
 \opening{...} is filled and the first headline without a special tag
 in the parse tree could be used (assuming there's no special
 keyword...). That headline can be found using `org-element-map'.

Yes.  Less ugly.

 Another (smallish) advantage is that the following case would be
 allowed:

   * Dear myself,
   * Part 1

Is the advantage that it won't fold?

 WDYT?

The current stuff is ugly.  I didn't know much lisp when I worked on
ox-koma-letter.

I updated the patch.  Perhaps the loop determination shod be moved to a
separate function to keep the template clean.  I thinking this cause we
(or at least I) sometimes point to ox-koma-letter as an example of a
derived backend.  WDTY on that?

In the attached at least this work as expected.

*** ps :ps:
*** dear you,
* part 1

—Rasmus

-- 
Send from my Emacs
From dacee19cce07a75735298dcb3f3730d6220248c5 Mon Sep 17 00:00:00 2001
From: Rasmus ras...@gmx.us
Date: Tue, 17 Mar 2015 18:32:26 +0100
Subject: [PATCH] ox-koma-letter: Stricter subject inference

* ox-koma-letter.el (org-koma-letter-headline): Remove opening guessing.
  (org-koma-letter-template): Directly infer subject from first
  non-special headline.
---
 contrib/lisp/ox-koma-letter.el | 22 --
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/contrib/lisp/ox-koma-letter.el b/contrib/lisp/ox-koma-letter.el
index 1b5dd17..59616c7 100644
--- a/contrib/lisp/ox-koma-letter.el
+++ b/contrib/lisp/ox-koma-letter.el
@@ -412,6 +412,7 @@ was not present.
 (:with-place nil place org-koma-letter-use-place)
 (:with-subject nil subject org-koma-letter-subject-format)
 (:with-title-as-subject nil title-subject org-koma-letter-prefer-subject)
+(:with-headline-opening nil nil org-koma-letter-headline-is-opening-maybe)
 ;; Special properties non-nil when a setting happened in buffer.
 ;; They are used to prioritize in-buffer settings over lco
 ;; files.  See `org-koma-letter-template'.
@@ -559,11 +560,6 @@ appropriate place.
 		  tag (mapcar #'symbol-name (plist-get info :special-tags)))
 		 ;; Store association for later use and bail out.
 		 (push (cons tag contents) org-koma-letter-special-contents)))
-;; Opening is not defined yet: use headline's title.
-(when (and org-koma-letter-headline-is-opening-maybe
-	   (not (org-string-nw-p (plist-get info :opening
-  (plist-put info :opening
-		 (org-export-data (org-element-property :title headline) info)))
 ;; In any case, insert contents in letter's body.
 contents))
 
@@ -641,7 +637,21 @@ holding export options.
(format \\begin{letter}{%%\n%s}\n\n
 	   (org-koma-letter--determine-to-and-from info 'to))
;; Opening.
-   (format \\opening{%s}\n\n (plist-get info :opening))
+   (format \\opening{%s}\n\n
+	   (org-export-data
+	(or (org-string-nw-p (plist-get info :opening))
+		(if (plist-get info :with-headline-opening)
+		(let ((special-tags (plist-get info :special-tags)))
+			(org-element-map (org-element-parse-buffer) 'headline
+			  (lambda (head)
+			(unless
+(org-some 'identity
+	  (mapcar (lambda (tag) (memq (intern tag) special-tags))
+		  (org-element-property :tags head)))
+			  (org-element-property :title head)))
+			  info t)))
+		)
+	info))
;; Letter body.
contents
;; Closing.
-- 
2.3.3



Re: [O] [patch, koma-letter] Change of subject behavior

2015-03-17 Thread Rasmus
Nicolas Goaziou m...@nicolasgoaziou.fr writes:

 I updated the patch.  Perhaps the loop determination shod be moved to a
 separate function to keep the template clean.

 Yes, it needs to be factored out (maybe
 `org-koma-letter--special-headline-p') since it is also used in
 `org-koma-letter-headline'. What about

   (defun org-koma-letter--special-headline-p (h info)
 (let ((special-tags (plist-get info :special-tags)))
   (org-some (lambda (tag) (assoc-string tag special-tags))
 (org-export-get-tags h info


That's nice.  I had forgotten about org-export-get-tags.

 + (:with-headline-opening nil nil
 org-koma-letter-headline-is-opening-maybe)

 I don't think this line is required.

It feels more consistent to provide the check through the definition, but
I'm not willing to pick a fight over this so it's back to just checking
the variable.

I have only tested the patch briefly as I need to actually produce a
letter.  But for the letter I'm writing export works fine.

—Rasmus

-- 
To err is human. To screw up 10⁶ times per second, you need a computer
From ec5c3ed3f6e1e3cfec5f6264f7b30dbef745aeb4 Mon Sep 17 00:00:00 2001
From: rasmus ras...@gmx.us
Date: Wed, 19 Nov 2014 15:39:19 +0100
Subject: [PATCH] org.el: Add keyword-support to M-RET

* org.el (org-insert-keyword): New function.
(org-meta-return): May call `org-insert-keyword'.
---
 lisp/org.el | 30 --
 1 file changed, 24 insertions(+), 6 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index dbd2cb7..8862f16 100755
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -21286,6 +21286,23 @@ number of stars to add.
 	   (forward-line)))
 (unless toggled (message Cannot toggle heading from here
 
+(defun org-insert-keyword (optional arg)
+  Insert a new keyword at point.
+
+ARG may be used to specify a keyword.  Otherwise the keyword is determined from the context.
+
+Mainly used for `org-meta-return'.
+  ;; Roughly based on
+  ;; TODO: Respect `org-M-RET-may-split-line'.
+  ;; TODO: Behave differently based on whether at beginning or
+  ;;   end of line.  E.g. M-RET at pos 0 adds line ABOVE.
+
+  (interactive P)
+  (let* ((elm (org-element-at-point))
+	 (key (or arg (and (eq 'keyword (org-element-type elm))
+			   (org-element-property :key elm)
+(and key (insert (format \n#+%s:  key)
+
 (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
@@ -21298,12 +21315,13 @@ on context.  See the individual commands for more information.
 (when (eq type 'table-row)
   (setq element (org-element-property :parent element))
   (setq type 'table))
-(if (and (eq type 'table)
- (eq (org-element-property :type element) 'org)
- (= (point) (org-element-property :contents-begin element))
- ( (point) (org-element-property :contents-end element)))
-(call-interactively 'org-table-wrap-region)
-  (call-interactively 'org-insert-heading)
+(cond  ((and (eq type 'table)
+		  (eq (org-element-property :type element) 'org)
+		  (= (point) (org-element-property :contents-begin element))
+		  ( (point) (org-element-property :contents-end element)))
+		(call-interactively 'org-table-wrap-region))
+	   ((eq type 'keyword) (call-interactively 'org-insert-keyword))
+	   (t (call-interactively 'org-insert-heading))
 
 ;;; Menu entries
 
-- 
2.1.3