From mboxrd@z Thu Jan 1 00:00:00 1970 From: Viktor Rosenfeld Subject: Re: [patch] ox-koma-letter.el: clean-up/semantic bug [4/4] Date: Wed, 22 May 2013 16:39:23 +0200 Message-ID: <20130522143923.GA61443@kenny.local> References: <87wqqusder.fsf@pank.eu> <87ehd2sc6t.fsf@pank.eu> <87wqqsd7p8.fsf@pank.eu> <874ndwcyjx.fsf@pank.eu> <20130521170259.GB56408@client199-78.wlan.hu-berlin.de> <87ehd09p6r.fsf@pank.eu> <20130521195413.GA58739@kenny.local> <87vc6b9atm.fsf@pank.eu> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([208.118.235.92]:44229) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UfACW-0006E9-Ig for emacs-orgmode@gnu.org; Wed, 22 May 2013 10:39:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UfACR-0003QP-2D for emacs-orgmode@gnu.org; Wed, 22 May 2013 10:39:36 -0400 Received: from mail-bk0-x232.google.com ([2a00:1450:4008:c01::232]:54087) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UfACQ-0003QH-Nn for emacs-orgmode@gnu.org; Wed, 22 May 2013 10:39:30 -0400 Received: by mail-bk0-f50.google.com with SMTP id ik8so191537bkc.9 for ; Wed, 22 May 2013 07:39:29 -0700 (PDT) Content-Disposition: inline In-Reply-To: <87vc6b9atm.fsf@pank.eu> 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: Rasmus Cc: emacs-orgmode@gnu.org Hi Rasmus, Rasmus wrote: > Viktor Rosenfeld writes: > > > Or 5, keep the change from SENDER to AUTHOR but revert the default > > values to `org-koma-letter-*' variables. (Right now the AUTHOR and EMAIL > > lines could be removed because they duplicate the derived latex > > backend.) > > I once had a teacher who talked about the optimal degree of > conservatism (as well speaking positively about being in the infamoues > ivory tower). 5. is fine with me. So I guess the deal is > 1. default value is the same as in ox-latex. > 2. . . . but it's kept in a seperete variable ox-kl variable. > > > I think that switching from SENDER to AUTHOR, keeping the > > `org-koma-letter-{author,email}' variables in the KOMA backend, but > > setting them per default to `user-full-name' and `user-mail-address', > > would solve both your problems and let me keep LCO files. I would then > > simply set these `org-koma-letter-*' variables to `nil' and document > > this setup in the docstring. I'll see tomorrow if this is feasable. > > Does the attached patch work for you (also with ps tags?) It works, but I noticed the following problem: According to the Emacs documentation `user-mail-address' is only set by Emacs after the initialization process has completed and if it is not explicitly set during initialization [1]. So, the defcustom of org-koma-letter-email does not work as expected if the user has not set `user-mail-address' before. Instead it is set to the empty string, which according to the code setting `user-mail-address' means "not set yet." This can be taking care of by using `after-init-hook' as in the example below. It has the added advantage that the value of `user-mail-address' will be picked up regardless of whether it is set before or after require'ing ox-koma-letter. Note that this creates a slight inconsistency with regard to `user-full-name' which is only picked up correctly if it is set before require'ing ox-koma-letter. I've fixed this by a slightly complicated defcustom definition of `org-koma-letter-author' and another after-init-hook. I've also changed the docstring to indicate what are the default values and added the :group and :type flags again. #+BEGIN_SRC (defcustom org-koma-letter-email user-mail-address "The sender's email address. This variable defaults to the value of `user-mail-address'." :group 'org-export-koma-letter :type 'string) (add-hook 'after-init-hook (lambda () (if (string= org-koma-letter-email "") (setq org-koma-letter-email user-mail-address)))) (defcustom org-koma-letter-author (if (boundp 'org-koma-letter-author) user-full-name ;; Empty string means "not set yet." "") "The sender's name. This variable defaults to the value of `user-full-name'." :group 'org-export-koma-letter :type 'string) (add-hook 'after-init-hook (lambda () (if (string= org-koma-letter-author "") (setq org-koma-letter-author user-full-name)))) #+END_SRC Cheers, Viktor [1] http://www.gnu.org/software/emacs/manual/html_node/elisp/User-Identification.html#User-Identification > > –Rasmus > > -- > Dung makes an excellent fertilizer > >From 92b07bac2d707f01e48796778453b67a9ecd1daa Mon Sep 17 00:00:00 2001 > From: "rasmus.pank" > Date: Wed, 22 May 2013 01:16:54 +0200 > Subject: [PATCH 5/5] Variables for author and email for ox-koma-letter and a > bug fix. > > * ox-koma-letter.el (koma-letter): reintroduced koma-letter > specif author and email. > * ox-koma-letter.el (koma-letter): set > org-koma-special-content to nil when exporting > > The former is needed so that author/email can be set in a LCO file. > > TINYCHANGE > --- > contrib/lisp/ox-koma-letter.el | 49 +++++++++++++++++++++++------------------- > 1 file changed, 27 insertions(+), 22 deletions(-) > > diff --git a/contrib/lisp/ox-koma-letter.el b/contrib/lisp/ox-koma-letter.el > index 020df52..92cf13a 100644 > --- a/contrib/lisp/ox-koma-letter.el > +++ b/contrib/lisp/ox-koma-letter.el > @@ -109,6 +109,12 @@ > :group 'org-export-koma-letter > :type 'string) > > +(defcustom org-koma-letter-email user-mail-address > + "The default email address stored in the letter." ) > + > +(defcustom org-koma-letter-author user-full-name > + "The default name of the sender." ) > + > (defcustom org-koma-letter-signature "\\usekomavar{fromname}" > "String used as the signature." > :group 'org-export-koma-letter > @@ -143,7 +149,6 @@ English manual of 2012-07-22)" > :group 'org-export-koma-letter) > > > - > (defcustom org-koma-letter-use-backaddress t > "Print return address in small line above to address." > :group 'org-export-koma-letter > @@ -179,7 +184,6 @@ Use `foldmarks:true' to activate default fold marks or > :group 'org-export-koma-letter > :type 'string) > > - > (defconst org-koma-letter-special-tags-after-closing > '("PS" "ENCL" "CC") > "Headers tags to be inserted after closing") > @@ -193,7 +197,7 @@ Use `foldmarks:true' to activate default fold marks or > org-koma-letter-special-tags-after-closing) > "Header tags with special meaning") > > -(defvar org-koma-letter-special-content nil "holds special > +(defvar org-koma-letter-special-contents nil "holds special > content temporarily.") > > > @@ -203,10 +207,10 @@ content temporarily.") > (org-export-define-derived-backend 'koma-letter 'latex > :options-alist > '((:lco "LCO" nil org-koma-letter-class-option-file) > - (:sender "AUTHOR" nil user-full-name t) > + (:sender "AUTHOR" nil org-koma-letter-author) > (:from-address "FROM_ADDRESS" nil org-koma-letter-from-address newline) > (:phone-number "PHONE_NUMBER" nil org-koma-letter-phone-number) > - (:email "EMAIL" nil user-mail-address t) > + (:email "EMAIL" nil org-koma-letter-email) > (:to-address "TO_ADDRESS" nil nil newline) > (:place "PLACE" nil org-koma-letter-place) > (:opening "OPENING" nil org-koma-letter-opening) > @@ -275,29 +279,31 @@ channel." > ;; Thanks, Luis! > > (defun org-koma-letter--get-tagged-content (tag info) > - (cdr (assoc tag org-koma-letter-special-content))) > + (cdr (assoc tag org-koma-letter-special-contents))) > > > -(defun org-koma-letter-headline (headline conents info) > +(defun org-koma-letter-headline (headline contents info) > "Transcode a HEADLINE element from Org to LaTeX. > CONTENTS holds the contents of the headline. INFO is a plist > holding contextual informatio.n > > 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-content' and included at the > +stored in `org-koma-letter-special-contents' and included at the > appropriate place." > (let* > ((tags (and (plist-get info :with-tags) > (org-export-get-tags headline info)))) > - (if (member (car tags) org-koma-letter-special-tags) > - (cond ((member (car tags) '("PS" "ps")) > - (progn > - (push (cons (car tags) (concat (plist-get info :ps-prefix) contents)) > - org-koma-letter-special-content) nil)) > - (t (progn > - (push (cons (car tags) contents) > - org-koma-letter-special-content) nil))) > + (if (member (upcase (car tags)) > + org-koma-letter-special-tags) > + ;; (cond ((member (car tags) '("PS" "ps")) > + ;; (progn > + ;; (push (cons (car tags) (concat (plist-get info :ps-prefix) contents)) > + ;; org-koma-letter-special-contents) nil)) > + (progn > + (push (cons (upcase (car tags)) contents) > + org-koma-letter-special-contents) > + nil) > contents))) > > > @@ -307,10 +313,9 @@ appropriate place." > "Return complete document string after KOMA Scrlttr2 conversion. > CONTENTS is the transcoded contents string. INFO is a plist > holding export options." > - ;; FIXME: instead of setq'ing org-koma-letter-special-content and > + ;; 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 > ;; as in org-groff... > - (setq org-koma-letter-special-content nil) > (concat > ;; Time-stamp. > (and (plist-get info :time-stamp-file) > @@ -412,15 +417,14 @@ holding export options." > (format "\n\\closing{%s}\n\n" (plist-get info :closing)) > (let (after-closing) > (dolist (ac org-koma-letter-special-tags-after-closing after-closing) > - (let ((x (org-koma-letter--get-tagged-content ac info))) > + (let ((x (org-koma-letter--get-tagged-content (upcase ac) info))) > (when x (setq after-closing > (concat after-closing > ;; sometimes LaTeX complains about newlines > ;; at the end of macros. Remove them. > (replace-regexp-in-string > "\n+$" "" > - (format "\\%s{%s}" (downcase ac) x))))) > - ))) > + (format "\\%s{%s}" (downcase ac) x)))))))) > ;; Letter end. > "\\end{letter}\n" > (let ((x (org-koma-letter--get-tagged-content "AFTER_LETTER" info))) > @@ -464,6 +468,7 @@ Export is done in a buffer named \"*Org KOMA-LETTER Export*\". It > will be displayed if `org-export-show-temporary-export-buffer' is > non-nil." > (interactive) > + (let (org-koma-letter-special-contents) > (if async > (org-export-async-start > (lambda (output) > @@ -480,7 +485,7 @@ non-nil." > subtreep visible-only body-only ext-plist))) > (with-current-buffer outbuf (LaTeX-mode)) > (when org-export-show-temporary-export-buffer > - (switch-to-buffer-other-window outbuf))))) > + (switch-to-buffer-other-window outbuf)))))) > > ;;;###autoload > (defun org-koma-letter-export-to-latex > -- > 1.8.2.3 >