emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Alan Schmitt <alan.schmitt@polytechnique.org>
To: Rasmus <rasmus@gmx.us>
Cc: Org Mode <emacs-orgmode@gnu.org>
Subject: Re: koma letter exporter: changing the priority of options
Date: Tue, 27 Aug 2013 10:02:22 +0200	[thread overview]
Message-ID: <m2r4dfy31t.fsf@polytechnique.org> (raw)
In-Reply-To: <87vc34dvyo.fsf@gmx.us>

[-- Attachment #1: Type: text/plain, Size: 3769 bytes --]

Hello Rasmus,

Sorry for the delay, I was in vacations with tethering-only internet
access.

rasmus@gmx.us writes:

> The following message is a courtesy copy of an article
> that has been posted to gmane.emacs.orgmode as well.
>
> Rasmus <rasmus@gmx.us> writes:
>
>> Alan,
>>
>>> alan.schmitt@polytechnique.org writes:
>>>
>>>> Yes, this is not satisfactory (and the email and author is also
>>>> problematic in this regard). We need to know whether an option was set
>>>> in the file, independently of its default value. Is there a way to do
>>>> this?
>>>
>>> Thanks to Nicolas, I've been able to create a cleaner solution: we track
>>> some of the variables (ones for which we currently output something by
>>> default, typically because they are set or because we choose to always
>>> output something, like from-phone), and we only output the code if the
>>> variable was set in the file. Thus if nothing is set, the lco file
>>> wins. Note that with this approach, one can have a default in the lco
>>> that is overridden by the file, for instance for foldmarks or to display
>>> phone numbers.
>>>
>>> Regarding the name and email, we output it before the lco if they are
>>> not specified in the file, and after if they are.
>>>
>>> What do you think of this approach? Are there other variables we should
>>> track?
>
> I spoke too early.  For example this letter no longer works as usual:
>
> #+TITLE: test
> #+OPTIONS: foldmarks:nil
> * Letter
>   my letter
> ** TO	 :TO:
>    someone
>    somewhere
>
> But this is because nil has a "new" meaning of "not set" as opposed to
> "false".  Is this OK?  On one hand nil usually means False in ox, I
> think (e.g. inline:nil → inline comments not posted), but on the other
> hand nil often means not set in Emacs. . .  It is nice to having to
> look at the extra setkomavariable, but I'm not sure whether it's
> right.

I tried to fix it in the updated attached patch. I set a default value
of "foldmarks-not-set" to the predicate that detects if it is set in the
file, then I compare its contents. This assumes that the user will not
give this literal value to the option.

> I also find something like this ghastly:
>
>       (unless author-set
> 	(when author (format "\\setkomavar{fromname}{%s}\n"
> 			     (org-export-data author info))))
>       (unless email-set
> 	(when email (format "\\setkomavar{fromemail}{%s}\n" email)))
>       ^^^^^^^^^^^^^^^^^^^^^^
>       ;; Letter Class Option File
>       (when lco
>       [...]
>       ))
>       ;; Define "From" data.
>       (when (and author author-set) (format "\\setkomavar{fromname}{%s}\n"
> 					    (org-export-data author info)))
>       (when from-address (format "\\setkomavar{fromaddress}{%s}\n" from-address))
>       (when phone-number
> 	(format "\\setkomavar{fromphone}{%s}\n" phone-number))
>       (when (and email email-set) (format "\\setkomavar{fromemail}{%s}\n" email))
>       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
> But perhaps it is the only way to get what you want.

I could not find a way to do it another way, but I'll gladly take any
suggestion. What we want is:
- if email is set in the file, use it;
- otherwise, use the one from the lco;
- otherwise, use the default one.

> Also, with the current setup, I can only set email before or after.
> Why?  What if I want to let PLACE be dependent on my LCO file versus
> my org file?

I think you can do it: if you don't give the option in the file, the one
from the LCO will be used, otherwise the one in the file will override
it. The main thing with author and email is that they almost always have
non-nil default values, whereas place's default value is nil. If this is
not correct, we can extend the approach for author and email to places
or other options.

Best,

Alan


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Koma-exporter-Ensure-customization-to-LCO-files-are-.patch --]
[-- Type: text/x-patch, Size: 6474 bytes --]

From 1299e543992d00f98d52a967c5a802213ce09799 Mon Sep 17 00:00:00 2001
From: Alan Schmitt <alan.schmitt@polytechnique.org>
Date: Mon, 22 Jul 2013 16:46:02 +0200
Subject: [PATCH] Koma exporter: Ensure customization to LCO files are taken
 into account

* contrib/lisp/ox-koma-letter.el: Change default values to match the scrlttr2
default values.  Track which options are set in the file and only output the
corresponding options when they are changed.
---
 contrib/lisp/ox-koma-letter.el | 49 +++++++++++++++++++++++++++++++-----------
 1 file changed, 37 insertions(+), 12 deletions(-)

diff --git a/contrib/lisp/ox-koma-letter.el b/contrib/lisp/ox-koma-letter.el
index d149f9d..9ae4d32 100644
--- a/contrib/lisp/ox-koma-letter.el
+++ b/contrib/lisp/ox-koma-letter.el
@@ -228,7 +228,7 @@ English manual of 2012-07-22)"
 
 
 
-(defcustom org-koma-letter-use-backaddress t
+(defcustom org-koma-letter-use-backaddress nil
   "Print return address in small line above to address."
   :group 'org-export-koma-letter
   :type 'boolean)
@@ -243,12 +243,12 @@ Use `foldmarks:true' to activate default fold marks or
   :group 'org-export-koma-letter
   :type 'string)
 
-(defcustom org-koma-letter-use-phone t
+(defcustom org-koma-letter-use-phone nil
   "Print sender's phone number."
   :group 'org-export-koma-letter
   :type 'boolean)
 
-(defcustom org-koma-letter-use-email t
+(defcustom org-koma-letter-use-email nil
   "Print sender's email address."
   :group 'org-export-koma-letter
   :type 'boolean)
@@ -287,9 +287,11 @@ Use `foldmarks:true' to activate default fold marks or
 					org-koma-letter-default-class
 					org-latex-default-class) t)
     (:author "AUTHOR" nil (org-koma-letter--get-custom org-koma-letter-author) t)
+    (:author-changed-in-buffer-p "AUTHOR" nil nil t)
     (:from-address "FROM_ADDRESS" nil nil newline)
     (:phone-number "PHONE_NUMBER" nil org-koma-letter-phone-number)
     (:email "EMAIL" nil (org-koma-letter--get-custom org-koma-letter-email) t)
+    (:email-changed-in-buffer-p "EMAIL" nil nil t)
     (:to-address "TO_ADDRESS" nil nil newline)
     (:place "PLACE" nil org-koma-letter-place)
     (:opening "OPENING" nil org-koma-letter-opening)
@@ -306,9 +308,13 @@ Use `foldmarks:true' to activate default fold marks or
     (:with-after-letter nil "after-letter-order"
 			org-koma-letter-special-tags-after-letter)
     (:with-backaddress nil "backaddress" org-koma-letter-use-backaddress)
+    (:with-backaddress-changed-in-buffer-p nil "backaddress" nil)
     (:with-foldmarks nil "foldmarks" org-koma-letter-use-foldmarks)
+    (:with-foldmarks-changed-in-buffer-p nil "foldmarks" "foldmarks-not-set")
     (:with-phone nil "phone" org-koma-letter-use-phone)
+    (:with-phone-changed-in-buffer-p nil "phone" nil)
     (:with-email nil "email" org-koma-letter-use-email)
+    (:with-email-changed-in-buffer-p nil "email" nil)
     (:with-place nil "place" org-koma-letter-use-place)
     (:with-subject nil "subject" org-koma-letter-subject-format))
   :translate-alist '((export-block . org-koma-letter-export-block)
@@ -522,11 +528,19 @@ holding export options."
 	info)))
    (let ((lco (plist-get info :lco))
 	 (author (plist-get info :author))
+	 (author-set (plist-get info :author-changed-in-buffer-p))
 	 (from-address (org-koma-letter--determine-special-value info 'from))
 	 (phone-number (plist-get info :phone-number))
 	 (email (plist-get info :email))
+	 (email-set (plist-get info :email-changed-in-buffer-p))
 	 (signature (plist-get info :signature)))
      (concat
+      ;; author or email not set in file: may be overridden by lco
+      (unless author-set
+	(when author (format "\\setkomavar{fromname}{%s}\n"
+			     (org-export-data author info))))
+      (unless email-set
+	(when email (format "\\setkomavar{fromemail}{%s}\n" email)))
       ;; Letter Class Option File
       (when lco
 	(let ((lco-files (split-string lco " "))
@@ -535,11 +549,12 @@ holding export options."
 	    (setq lco-def (format "%s\\LoadLetterOption{%s}\n" lco-def lco-file)))
 	  lco-def))
       ;; Define "From" data.
-      (when author (format "\\setkomavar{fromname}{%s}\n"
-			   (org-export-data author info)))
+      (when (and author author-set) (format "\\setkomavar{fromname}{%s}\n"
+					    (org-export-data author info)))
       (when from-address (format "\\setkomavar{fromaddress}{%s}\n" from-address))
-      (when phone-number (format "\\setkomavar{fromphone}{%s}\n" phone-number))
-      (when email (format "\\setkomavar{fromemail}{%s}\n" email))
+      (when phone-number
+	(format "\\setkomavar{fromphone}{%s}\n" phone-number))
+      (when (and email email-set) (format "\\setkomavar{fromemail}{%s}\n" email))
       (when signature (format "\\setkomavar{signature}{%s}\n" signature))))
    ;; Date.
    (format "\\date{%s}\n" (org-export-data (org-export-get-date info) info))
@@ -550,14 +565,24 @@ holding export options."
        (format "\\setkomavar{place}{%s}\n" (if with-place place ""))))
    ;; KOMA options
    (let ((with-backaddress (plist-get info :with-backaddress))
+	 (with-backaddress-set (plist-get info :with-backaddress-changed-in-buffer-p))
 	 (with-foldmarks (plist-get info :with-foldmarks))
+	 (with-foldmarks-set 
+	  (not (string-equal (plist-get info :with-foldmarks-changed-in-buffer-p)
+			     "foldmarks-not-set")))
 	 (with-phone (plist-get info :with-phone))
-	 (with-email (plist-get info :with-email)))
+	 (with-phone-set (plist-get info :with-phone-changed-in-buffer-p))
+	 (with-email (plist-get info :with-email))
+	 (with-email-set (plist-get info :with-email-changed-in-buffer-p)))
      (concat
-      (format "\\KOMAoption{backaddress}{%s}\n" (if with-backaddress "true" "false"))
-      (format "\\KOMAoption{foldmarks}{%s}\n" (if with-foldmarks with-foldmarks "false"))
-      (format "\\KOMAoption{fromphone}{%s}\n" (if with-phone "true" "false"))
-      (format "\\KOMAoption{fromemail}{%s}\n" (if with-email "true" "false"))))
+      (when with-backaddress-set
+	(format "\\KOMAoption{backaddress}{%s}\n" (if with-backaddress "true" "false")))
+      (when with-foldmarks-set
+	(format "\\KOMAoption{foldmarks}{%s}\n" (if with-foldmarks with-foldmarks "false")))
+      (when with-phone-set
+	(format "\\KOMAoption{fromphone}{%s}\n" (if with-phone "true" "false")))
+      (when with-email-set
+	(format "\\KOMAoption{fromemail}{%s}\n" (if with-email "true" "false")))))
    ;; Document start
    "\\begin{document}\n\n"
    ;; Subject
-- 
1.8.2.1


  reply	other threads:[~2013-08-27  8:02 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-09 10:12 koma letter exporter: changing the priority of options Alan Schmitt
2013-06-09 18:00 ` Viktor Rosenfeld
2013-06-10  7:14   ` Alan Schmitt
2013-06-10  8:40   ` Rasmus
2013-07-19 13:01     ` Alan Schmitt
2013-07-19 18:57       ` Rasmus
2013-07-20 11:58         ` Viktor Rosenfeld
2013-07-20 12:59           ` Rasmus
2013-07-20 11:55       ` Viktor Rosenfeld
2013-07-22  7:14         ` Alan Schmitt
2013-07-22  7:50           ` Nicolas Goaziou
2013-07-22 12:42             ` Alan Schmitt
2013-07-22 13:17               ` Nicolas Goaziou
2013-07-22 13:45                 ` Alan Schmitt
2013-07-22 14:53           ` Alan Schmitt
2013-08-17 16:37             ` Rasmus
2013-08-17 18:16               ` Rasmus
2013-08-27  8:02                 ` Alan Schmitt [this message]
2013-08-27  8:29                   ` Alan Schmitt
2013-08-31 14:35                     ` Alan Schmitt
2013-08-31 16:05                       ` Rasmus
2013-08-28 11:26                   ` Rasmus
2013-08-28 11:43                     ` Alan Schmitt
2013-08-28 12:06                       ` Rasmus
2013-08-28 13:23                         ` Alan Schmitt

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

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2r4dfy31t.fsf@polytechnique.org \
    --to=alan.schmitt@polytechnique.org \
    --cc=emacs-orgmode@gnu.org \
    --cc=rasmus@gmx.us \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).