From: Rasmus <rasmus@gmx.us>
To: emacs-orgmode@gnu.org
Subject: Re: [patch, koma-letter] Change of subject behavior
Date: Thu, 19 Mar 2015 12:35:58 +0100 [thread overview]
Message-ID: <87twxh9q3l.fsf@gmx.us> (raw)
In-Reply-To: 873852125y.fsf@nicolasgoaziou.fr
[-- Attachment #1: Type: text/plain, Size: 860 bytes --]
Hi Nicolas,
Excellent comments. Thanks a lot!
Nicolas Goaziou <mail@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!
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0003-ox-koma-letter-Interpret-SUBJECT.patch --]
[-- Type: text/x-diff, Size: 1108 bytes --]
From 5f6832704d011b4b966b52c0dc1f6076f7af6ea7 Mon Sep 17 00:00:00 2001
From: Rasmus <rasmus@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
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-ox-koma-letter-Stricter-subject-inference.patch --]
[-- Type: text/x-diff, Size: 3410 bytes --]
From 6f042fd397e7f3f5b4844921800a68b3ba91c403 Mon Sep 17 00:00:00 2001
From: Rasmus <rasmus@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 (org-string-nw-p (plist-get info :opening))
+ (when (plist-get info :with-headline-opening)
+ (org-element-map (plist-get info :parse-tree) 'headline
+ (lambda (head)
+ (unless (org-koma-letter--special-tag head info)
+ (org-element-property :title head)))
+ info t))
+ "")
+ info))
;; Letter body.
contents
;; Closing.
--
2.3.3
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0001-ox-koma-letter-Tiny-refactor.patch --]
[-- Type: text/x-diff, Size: 1040 bytes --]
From 1b74dac088535fc123005242236ea82417604b34 Mon Sep 17 00:00:00 2001
From: Rasmus <rasmus@gmx.us>
Date: Thu, 19 Mar 2015 12:10:08 +0100
Subject: [PATCH 1/3] ox-koma-letter: Tiny refactor
ox-koma-letter.el (org-koma-letter--get-tagged-contents): Use
assoc-string.
---
contrib/lisp/ox-koma-letter.el | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/contrib/lisp/ox-koma-letter.el b/contrib/lisp/ox-koma-letter.el
index 1b5dd17..23da930 100644
--- a/contrib/lisp/ox-koma-letter.el
+++ b/contrib/lisp/ox-koma-letter.el
@@ -453,8 +453,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.
--
2.3.3
next prev parent reply other threads:[~2015-03-19 11:36 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-17 17:37 [patch, koma-letter] Change of subject behavior Rasmus
2015-03-17 21:00 ` Nicolas Goaziou
2015-03-17 22:48 ` Rasmus
2015-03-17 23:08 ` Nicolas Goaziou
2015-03-17 23:41 ` Rasmus
2015-03-18 11:41 ` Nicolas Goaziou
2015-03-18 12:39 ` Rasmus
2015-03-18 20:27 ` Nicolas Goaziou
2015-03-19 11:35 ` Rasmus [this message]
2015-03-19 23:15 ` Nicolas Goaziou
2015-03-20 20:22 ` Rasmus
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87twxh9q3l.fsf@gmx.us \
--to=rasmus@gmx.us \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.