From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rasmus Subject: [PATCH][ox-koma-letter] changed-in-buffer, subject, minor fixes Date: Mon, 25 Nov 2013 01:15:52 +0100 Message-ID: <87txf1xrnr.fsf@gmx.us> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:44779) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vkjnk-0004lb-CV for emacs-orgmode@gnu.org; Sun, 24 Nov 2013 19:13:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vkjne-00031k-4c for emacs-orgmode@gnu.org; Sun, 24 Nov 2013 19:13:20 -0500 Received: from plane.gmane.org ([80.91.229.3]:54194) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vkjnd-00031R-G8 for emacs-orgmode@gnu.org; Sun, 24 Nov 2013 19:13:14 -0500 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1Vkjna-0002HN-VH for emacs-orgmode@gnu.org; Mon, 25 Nov 2013 01:13:10 +0100 Received: from dynamic-adsl-94-39-217-142.clienti.tiscali.it ([94.39.217.142]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 25 Nov 2013 01:13:10 +0100 Received: from rasmus by dynamic-adsl-94-39-217-142.clienti.tiscali.it with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 25 Nov 2013 01:13:10 +0100 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Cc: jamshark70@gmail.com --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Hi all, Attached are a couple of changes to ox-koma-letter following a recent bug report by James. 1. Minor fixes around. The way subject-format was handled before was ugly. Updated some docstrings etc. 2. better test of whether values have changed in the buffer. I think Alan added this first, but the previous implementation. I think it's more robust now, and it hopefully addresses James' problems (please test). Basically and x-aux variable is added for all variables x in :option-alist with a default value "unset". The value can then be tested. I'm still concerned about this whole in-buffer voodoo. Not only do we test :email twice (sorry for keep bringing this up), but e.g. backaddress can only be set in buffer now: (when with-backaddress-set (format "\\KOMAoption{backaddress}{%s}\n" (if with-backaddress "true" "false"))) Perhaps this is OK, but one might have to rely on LCO files rather than lisp to change defaults (which I don't like). 3. When studying the KOMA manual to answer James' second question I came across the komavar title which is currently not supported. I have added support for a separate SUBJECT keyword. The heuristic is something like this (i) if title and subject are be truthful to the name no matter what, (ii) if only title or subject is said let title be subject if org-koma-letter-title-is-subject-maybe is t otherwise be truthful to name. I have of course tested the patches here, but I would appreciate feedback before they are applied. There's also a number of TODOs in the code that I would appreciate feedback on. In 3. I would personally like to set org-koma-letter-title-is-subject-maybe to nil by defaults, but this would break backwards comparability for title keywords. –Rasmus PS: We should add a banner to the Worg tutorial that not all info is up-to-date and that people one should as a minimum supplement it with reading the commentary section of the file (I'm not sure whether people do this). -- Enough with the bla bla! --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Minor-fixes-for-ox-koma-script.el.patch >From f6767ff0900fa65096ca4591b71a60516c4e71c6 Mon Sep 17 00:00:00 2001 From: Rasmus Date: Sun, 24 Nov 2013 17:57:37 +0100 Subject: [PATCH 1/3] Minor fixes for ox-koma-script.el * ox-koma-letter.el (org-koma-letter-headline): Correct docstring. (org-koma-letter-template): Insert subject before document start. (org-koma-letter-headline): Fix spelling. (org-koma-letter-template): Better subject handling. --- contrib/lisp/ox-koma-letter.el | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/contrib/lisp/ox-koma-letter.el b/contrib/lisp/ox-koma-letter.el index 240de29..e4d6f7a 100644 --- a/contrib/lisp/ox-koma-letter.el +++ b/contrib/lisp/ox-koma-letter.el @@ -111,11 +111,15 @@ ;; \[EXTRA]")) ;; ;; Then, in your Org document, be sure to require the proper class -;; with : +;; with: ;; ;; #+LATEX_CLASS: my-letter ;; ;; Or by setting `org-koma-letter-default-class'. +;; You may possibly have to load (LaTeX) Babel as well e.g. by adding +;; it to `org-latex-packages-alist', +;; +;; (add-to-list 'org-latex-packages-alist '("AUTO" "babel" nil)) ;;; Code: @@ -211,7 +215,6 @@ At this time the following values are allowed: - titled: add title/description to subject. - underlined: set subject underlined. - untitled: do not add title/description to subject. - - No-export: do no insert a subject even if present. Please refer to the KOMA-script manual (Table 4.16. in the English manual of 2012-07-22)." @@ -516,7 +519,7 @@ appropriate place." CONTENTS is the transcoded contents string. INFO is a plist holding export options." ;; FIXME: instead of setq'ing org-koma-letter-special-contents and - ;; callying varioues stuff it might be nice to put a big let* around the templace + ;; callying varioues stuff it might be nice to put a big let* around the template ;; as in org-groff... (concat ;; Time-stamp. @@ -585,7 +588,7 @@ holding export 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 + (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)) @@ -601,28 +604,25 @@ holding export options." (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 (let* ((with-subject (plist-get info :with-subject)) - (subject-format (cond ((member with-subject '("true" "t" t)) nil) - ((stringp with-subject) (list with-subject)) - ((symbolp with-subject) - (list (symbol-name with-subject))) - (t with-subject))) - (subject (org-export-data (plist-get info :title) info)) - (l (length subject-format)) - (y "")) + ;; TODO: this is a bit ugly and assumes that with-subject is + ;; (a list of) symbol(s) or string(s)... + (subject-format (mapcar + (lambda (elt) (if (and elt (symbolp elt)) (symbol-name elt) elt)) + (cond ((member with-subject '("true" "t" t)) nil) + ((listp with-subject) with-subject) + (t (list with-subject))))) + (subject (org-export-data (plist-get info :title) info))) (concat (when (and with-subject subject-format) (concat "\\KOMAoption{subject}{" - (apply 'format - (dotimes (x l y) - (setq y (concat (if (> x 0) "%s," "%s") y))) - subject-format) "}\n")) + (mapconcat 'identity subject-format ",") "}\n" )) (when (and subject with-subject) (format "\\setkomavar{subject}{%s}\n\n" subject)))) + ;; Document start + "\\begin{document}\n\n" ;; Letter start (format "\\begin{letter}{%%\n%s}\n\n" (org-koma-letter--determine-to-and-from info 'to)) -- 1.8.4.2 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0002-ox-koma-letter-test-with-auxiliary-variables.patch >From 92d716b5e2adeaa01b8206c59b263512232119ba Mon Sep 17 00:00:00 2001 From: Rasmus Date: Sun, 24 Nov 2013 19:23:02 +0100 Subject: [PATCH 2/3] ox-koma-letter: test with auxiliary variables * ox-koma-letter.el (org-koma-letter-aux-suffix): New variable (org-koma-letter-unset-string): New variable. (koma-letter-option-alist): Removed x-changed-in-buffer-p variables. (org-koma-letter--make-aux-variables): Function to add aux variables. (org-koma-letter--aux-name): Function returns an aux name. (org-koma-letter--set-in-buffer): Function returns t if variable is changed in buffer. (org-koma-letter-template): Use new test for changed in buffer. An aux variable is used to test wheter a variable has been changed in buffer. This commits makes this work consistently. --- contrib/lisp/ox-koma-letter.el | 76 +++++++++++++++++++++++++++++++++--------- 1 file changed, 60 insertions(+), 16 deletions(-) diff --git a/contrib/lisp/ox-koma-letter.el b/contrib/lisp/ox-koma-letter.el index e4d6f7a..2705d86 100644 --- a/contrib/lisp/ox-koma-letter.el +++ b/contrib/lisp/ox-koma-letter.el @@ -66,6 +66,10 @@ ;; - after-letter-order, as above, but after the end of the letter ;; (see `org-koma-letter-special-tags-after-letter'). ;; +;; Note, some formatting depends on whether the variables has been set +;; in the buffer. For instance, the email is inserted after LCO +;; files, if changed in the letter. +;; ;; The following variables works differently from the main LaTeX class ;; - "AUTHOR": default to user-full-name but may be disabled. (see org-koma-letter-author), ;; - "EMAIL": same as AUTHOR, (see org-koma-letter-email), @@ -93,7 +97,7 @@ ;; ;; to your init file. This will add a sparse scrlttr2 class and ;; set it as the default `org-koma-latex-default-class'. You can also -;; add you own letter class. For instace: +;; add you own letter class. For instance: ;; ;; (add-to-list 'org-latex-classes ;; '("my-letter" @@ -179,6 +183,8 @@ function may be given. Functions must return a string." :type 'string) (defcustom org-koma-letter-opening nil + ;; TODO: We should probably get rid of requirement (1) and just + ;; check if the value is set in the buffer. "Letter's opening, as a string. If (1) this value is nil; (2) the letter is started with a @@ -291,6 +297,11 @@ A headline is only used if #+OPENING is not set. See also (defvar org-koma-letter-special-contents nil "Holds special content temporarily.") +(defconst org-koma-letter-unset-string "unset" + "Value for unset auxiliary variables in :option-alist.") + +(defconst org-koma-letter-aux-suffix "-aux" + "Suffix for auxiliary variables used to test whether a variable has been set.") ;;; Define Back-End @@ -302,11 +313,9 @@ A headline is only used if #+OPENING is not set. See also org-koma-letter-default-class org-latex-default-class) t) (:author "AUTHOR" nil (org-koma-letter--get-value 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-value 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) @@ -322,14 +331,10 @@ A headline is only used if #+OPENING is not set. See also org-koma-letter-special-tags-after-closing) (: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-backaddress nil "backaddress" org-koma-letter-use-backaddress ) (: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) @@ -347,6 +352,10 @@ A headline is only used if #+OPENING is not set. See also (if a (org-koma-letter-export-to-pdf t s v b) (org-open-file (org-koma-letter-export-to-pdf nil s v b)))))))) + +;; Make auxiliary values to check whether variables have been set +(org-koma-letter--make-aux-variables 'koma-letter) + ;;; Initialize class function @@ -362,6 +371,23 @@ A headline is only used if #+OPENING is not set. See also ;;; Helper functions +(defun org-koma-letter--make-aux-variables (class) + "Append the option list of CLASS with aux values that test + whether they have been set in buffer." + ;; TODO: Is this the proper way to archive this? + (let* ((options (org-export-backend-options (org-export-get-backend class))) + (defined (mapcar 'first options)) + (aux (mapcar (lambda (l) + (let ((name (first l)) + (r1 (subseq l 1 3))) + (unless (member (org-koma-letter--aux-name name) defined) + (append (list (org-koma-letter--aux-name name)) r1 + (list 'org-koma-letter-unset-string t))))) + options))) + (setf (org-export-backend-options (org-export-get-backend class)) + (append options (delq nil aux))))) + + (defun org-koma-letter-email () "Return the current `user-mail-address'." user-mail-address) @@ -448,6 +474,21 @@ are present return the preferred one as determined by "\n" "\\\\\\\\\n" (org-koma-letter--normalize-string adr))))) +(defun org-koma-letter--aux-name (option) + "Return the auxiliary name of OPTION" + (let ((aux org-koma-letter-aux-suffix)) + (intern (concat (replace-regexp-in-string aux "" (symbol-name option)) "-aux")))) + +(defun org-koma-letter--set-in-buffer (info option) + "Test whether an :option-alist value is set. Return t or nil + +Values are \"primary\" values such as :email." + (let* ((opt (org-koma-letter--aux-name option)) + (value (if (plist-member info opt) (plist-get info opt) + (warn (format "Checked whether %s was set. But no auxiliary value exists. Returning nil" + option))))) + (not (equal (org-export-data value info) org-koma-letter-unset-string)))) + ;;; Transcode Functions ;;;; Export Block @@ -549,11 +590,11 @@ 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)) + (author-set (org-koma-letter--set-in-buffer info :author)) (from-address (org-koma-letter--determine-to-and-from info 'from)) (phone-number (plist-get info :phone-number)) (email (plist-get info :email)) - (email-set (plist-get info :email-changed-in-buffer-p)) + (email-set (org-koma-letter--set-in-buffer info :email)) (signature (plist-get info :signature))) (concat ;; author or email not set in file: may be overridden by lco @@ -586,16 +627,19 @@ 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-backaddress-set (org-koma-letter--set-in-buffer info :with-backaddress)) (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-foldmarks-set (org-koma-letter--set-in-buffer info :with-foldmarks)) (with-phone (plist-get info :with-phone)) - (with-phone-set (plist-get info :with-phone-changed-in-buffer-p)) + (with-phone-set (org-koma-letter--set-in-buffer info :with-phone)) + ;; TODO: email can now be set in two different places. This + ;; is handled in an inelegant manner. (with-email (plist-get info :with-email)) - (with-email-set (plist-get info :with-email-changed-in-buffer-p))) + (with-email-set (org-koma-letter--set-in-buffer info :with-email))) (concat + ;; TODO: with the (with . .)-clauses the default values are + ;; basically obsolete as these variables are only set when + ;; changed in buffer... (when with-backaddress-set (format "\\KOMAoption{backaddress}{%s}\n" (if with-backaddress "true" "false"))) (when with-foldmarks-set -- 1.8.4.2 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0003-Allow-separate-subject-and-title-in-ox-koma-letter.patch >From d743e01fe6cd8a17f40140b0f33e8550c37740a4 Mon Sep 17 00:00:00 2001 From: Rasmus Date: Mon, 25 Nov 2013 00:23:09 +0100 Subject: [PATCH 3/3] Allow separate subject and title in ox-koma-letter * ox-koma-letter.el (org-koma-letter-use-title): New variable. (org-koma-letter-title-is-subject-maybe): New variable. (koma-letter-template): Allow seperate subject and title. (org-koma-letter-template): Allow seperate subject and title. Depending on the variable `org-koma-letter-title-is-subject-maybe' the komavar "subject" may be set either with the TITLE keyword or with the SUBJECT keyword. It is now possible to typeset komavar title. --- contrib/lisp/ox-koma-letter.el | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/contrib/lisp/ox-koma-letter.el b/contrib/lisp/ox-koma-letter.el index 2705d86..d6a037b 100644 --- a/contrib/lisp/ox-koma-letter.el +++ b/contrib/lisp/ox-koma-letter.el @@ -36,12 +36,13 @@ ;; keywords: ;; - "CLOSING" (see `org-koma-letter-closing'), ;; - "FROM_ADDRESS" (see `org-koma-letter-from-address'), +;; - "TO_ADDRESS". If unspecified this is set to "\mbox{}". ;; - "LCO" (see `org-koma-letter-class-option-file'), ;; - "OPENING" (see `org-koma-letter-opening'), ;; - "PHONE_NUMBER" (see `org-koma-letter-phone-number'), ;; - "SIGNATURE" (see `org-koma-letter-signature') ;; - "PLACE" (see `org-koma-letter-place') -;; - and "TO_ADDRESS". If unspecified this is set to "\mbox{}". +;; - "SUBJECT" (see `org-koma-letter-title-is-subject-maybe') ;; ;; TO_ADDRESS and FROM_ADDRESS can also be specified using heading ;; with the special tags specified in @@ -50,6 +51,9 @@ ;; both a headline and a keyword specify a to or from address the ;; value is determined in accordance with ;; `org-koma-letter-prefer-special-headings'. +;; If `org-koma-letter-title-is-subject-maybe' is t both SUBJECT and +;; TITLE can be used to set the subject. If both are set they take +;; the value as indicated by name. ;; ;; A number of OPTIONS settings can be set to change which contents is ;; exported. @@ -60,6 +64,7 @@ ;; - place (see `org-koma-letter-use-place') ;; - subject, a list of format options ;; (see `org-koma-letter-subject-format') +;; - title (see `org-koma-letter-use-title') ;; - after-closing-order, a list of the ordering of headings with ;; special tags after closing (see ;; `org-koma-letter-special-tags-after-closing') @@ -271,6 +276,13 @@ Use `foldmarks:true' to activate default fold marks or :group 'org-export-koma-letter :type 'boolean) +(defcustom org-koma-letter-use-title t + "Use a title in the letter. + +See also `org-koma-letter-title-is-subject-maybe'." + :group 'org-export-koma-letter + :type 'boolean) + (defcustom org-koma-letter-default-class nil "Default class for `org-koma-letter'. @@ -285,6 +297,12 @@ A headline is only used if #+OPENING is not set. See also :group 'org-export-koma-letter :type 'boolean) +(defcustom org-koma-letter-title-is-subject-maybe t + "Whether the TITLE keyword should be interpreted as subject +when no subject is present." + :group 'org-export-koma-letter + :type 'boolean) + (defconst org-koma-letter-special-tags-in-letter '(to from) "Header tags related to the letter itself.") @@ -313,6 +331,7 @@ A headline is only used if #+OPENING is not set. See also org-koma-letter-default-class org-latex-default-class) t) (:author "AUTHOR" nil (org-koma-letter--get-value org-koma-letter-author) t) + (:subject "SUBJECT" nil nil space) (:from-address "FROM_ADDRESS" nil nil newline) (:phone-number "PHONE_NUMBER" nil org-koma-letter-phone-number) (:email "EMAIL" nil (org-koma-letter--get-value org-koma-letter-email) t) @@ -336,7 +355,9 @@ A headline is only used if #+OPENING is not set. See also (:with-phone nil "phone" org-koma-letter-use-phone) (:with-email nil "email" org-koma-letter-use-email) (:with-place nil "place" org-koma-letter-use-place) - (:with-subject nil "subject" org-koma-letter-subject-format)) + (:with-subject nil "subject" org-koma-letter-subject-format) + (:with-title nil "title" org-koma-letter-use-title) + ) :translate-alist '((export-block . org-koma-letter-export-block) (export-snippet . org-koma-letter-export-snippet) (headline . org-koma-letter-headline) @@ -657,14 +678,20 @@ holding export options." (cond ((member with-subject '("true" "t" t)) nil) ((listp with-subject) with-subject) (t (list with-subject))))) - (subject (org-export-data (plist-get info :title) info))) + (prefer-subject org-koma-letter-title-is-subject-maybe) + (subject* (org-export-data (plist-get info :subject) info)) + (title* (org-export-data (plist-get info :title) info)) + (subject (if prefer-subject (or subject* title*) subject*)) + (title (if prefer-subject (and subject* title*) title*)) + ) (concat (when (and with-subject subject-format) (concat "\\KOMAoption{subject}{" (mapconcat 'identity subject-format ",") "}\n" )) (when (and subject with-subject) - (format "\\setkomavar{subject}{%s}\n\n" subject)))) + (format "\\setkomavar{subject}{%s}\n\n" subject)) + (when title (format "\\setkomavar{title}{%s}\n\n" title)))) ;; Document start "\\begin{document}\n\n" ;; Letter start -- 1.8.4.2 --=-=-=--