From mboxrd@z Thu Jan 1 00:00:00 1970 From: Viktor Rosenfeld Subject: Re: [PATCH][ox-koma-letter]: sender, email and cleanup (was: [PATCH] ox-koma-letter.el: Reintroduce variables removed in commit 832c6fd with proper defaults) Date: Sun, 26 May 2013 12:54:00 +0200 Message-ID: <20130526105400.GA716@kenny.local> References: <87hahrmabq.fsf@pank.eu> <20130525170322.GA734@kenny.local> <87bo7zlzln.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]:49050) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UgYad-0000tG-4A for emacs-orgmode@gnu.org; Sun, 26 May 2013 06:54:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UgYaV-000691-JE for emacs-orgmode@gnu.org; Sun, 26 May 2013 06:54:15 -0400 Received: from mail-bk0-x229.google.com ([2a00:1450:4008:c01::229]:43680) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UgYaV-00068b-4c for emacs-orgmode@gnu.org; Sun, 26 May 2013 06:54:07 -0400 Received: by mail-bk0-f41.google.com with SMTP id jc10so3214393bkc.28 for ; Sun, 26 May 2013 03:54:05 -0700 (PDT) Content-Disposition: inline In-Reply-To: <87bo7zlzln.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: alan.schmitt@polytechnique.org, emacs-orgmode@gnu.org Hi Rasmus, Rasmus wrote: > Attached are three patches that goes on top of Viktor's latest patch > (I've also attached it here since I rebased stuff and might have > changed it by accident). > > 1. Viktor's latest patch. > 2. The patch describe above that gets user name and email and works > on my system. . . Your code works for me. From my point of view, the pros are that per default `org-koma-letter-{author,sender}' pick up the values of `user-full-name' and `user-mail-address' whenever they are changed. That's very nice! The cons are that IHMO it's quite complicated for setting something as simple as author and email and you mentioned a possible crash which I did not test further. Could this be tested using `functionp'? Still, I think we should stick with it for now. > 3. Cleaning up special-tags functions introduced in > ec108f4c3507ed546a564a48b7379355a65aa9f4. It works a lot better > now and some of the mess in the template is moved to other > functions. I could not apply this. > 4. Sets defcustom org-koma-letter-signature nil since that > corresponds to default scrlttr2 behavior anyway (p. 183 in the > manual). Works for me. As a side note, I had quite a few problems working with your patches. None of them applied against master, or against my latest patch as you claimed. I had to merge in some of the changes of 0002 by hand. I suggest that we nail down the workings of AUTHOR and EMAIL first (should be done now) and then start with clean separate branches branched from master for your subject and heading code. We could even use github for this, what do you think? Cheers, Viktor > Re 4.: I'd like to do something similar to > org-koma-letter-subject-format. But I'm not sure how, at the moment > (perhaps make t the default and associate it with the current default > list). > > –Rasmus > > -- > This is the kind of tedious nonsense up with which I will not put > > >From bbaf9a6ddd75368b2143e6b8fb50be64bd66b50d Mon Sep 17 00:00:00 2001 > From: Viktor Rosenfeld > Date: Thu, 23 May 2013 00:00:38 +0200 > Subject: [PATCH 1/4] ox-koma-letter.el: Reintroduce variables removed in > commit 832c6fd with proper defaults. > > * ox-koma-letter.el (org-koma-letter-author): Dedicated > variable to set the KOMA variable fromname; initialized to > `user-full-name' using `after-init-hook' if not set > explicitly. > (org-koma-letter-email): Dedicated variable to set the KOMA > variable fromemail; initialized to `user-mail-address' using > `after-init-hook' if not set explicitly. > (koma-letter): Use dedicated variables for AUTHOR and EMAIL. > (org-koma-letter-template): Variable name change. > > Setting the variables `org-koma-letter-author' and `org-koma-letter-email' to the values of `user-full-name' and `user-mail-address' respectively, allows the user to skip =#+AUTHOR:= and =#+EMAIL:= lines when configuring a letter. However, if the user wishes to set this information in LCO files, these variables need to be set to nil. > --- > contrib/lisp/ox-koma-letter.el | 37 +++++++++++++++++++++++++++++++------ > 1 file changed, 31 insertions(+), 6 deletions(-) > > diff --git a/contrib/lisp/ox-koma-letter.el b/contrib/lisp/ox-koma-letter.el > index 92cf13a..24c1ac5 100644 > --- a/contrib/lisp/ox-koma-letter.el > +++ b/contrib/lisp/ox-koma-letter.el > @@ -82,6 +82,32 @@ > :group 'org-export-koma-letter > :type 'string) > > +(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)))) > + > +(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-from-address nil > "Sender's address, as a string." > @@ -93,7 +119,6 @@ > :group 'org-export-koma-letter > :type 'string) > > - > (defcustom org-koma-letter-place nil > "Place from which the letter is sent." > :group 'org-export-koma-letter > @@ -207,10 +232,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 org-koma-letter-author) > + (:author "AUTHOR" nil org-koma-letter-author t) > (:from-address "FROM_ADDRESS" nil org-koma-letter-from-address newline) > (:phone-number "PHONE_NUMBER" nil org-koma-letter-phone-number) > - (:email "EMAIL" nil org-koma-letter-email) > + (:email "EMAIL" nil org-koma-letter-email t) > (:to-address "TO_ADDRESS" nil nil newline) > (:place "PLACE" nil org-koma-letter-place) > (:opening "OPENING" nil org-koma-letter-opening) > @@ -343,7 +368,7 @@ holding export options." > (plist-get info :latex-header-extra)))) > info))))) > (let ((lco (plist-get info :lco)) > - (sender (plist-get info :sender)) > + (author (plist-get info :author)) > (from-address (plist-get info :from-address)) > (phone-number (plist-get info :phone-number)) > (email (plist-get info :email)) > @@ -357,8 +382,8 @@ holding export options." > (setq lco-def (format "%s\\LoadLetterOption{%s}\n" lco-def lco-file))) > lco-def)) > ;; Define "From" data. > - (when sender (format "\\setkomavar{fromname}{%s}\n" > - (org-export-data sender info))) > + (when author (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)) > -- > 1.8.2.3 > > >From 3df51bf5a57eb9d3a96fc4742a1b4b16998d701d Mon Sep 17 00:00:00 2001 > From: "rasmus.pank" > Date: Sat, 25 May 2013 15:31:45 +0200 > Subject: [PATCH 2/4] Trying to get good default for email and author. > > * ox-koma-letter.el (org-koma-letter-author): defaults to a function > that returns =`user-full-name'= > * ox-koma-letter.el (org-koma-letter-email): defaults to a function > that returns =`user-mail-address'= > > With the old after-init-hook method my user name was always set to "". > Now org-koma-letter will (i) allow for default nil values (good if you > use LCO files); (ii) default to =`user-full-name'= and > =`user-mail-address'= like =ox-latex.el=. These values are obtained > on-the-fly. > > The two variables in question can also be strings or functions > returning strings. > --- > contrib/lisp/ox-koma-letter.el | 58 ++++++++++++++++++++++-------------------- > 1 file changed, 30 insertions(+), 28 deletions(-) > > diff --git a/contrib/lisp/ox-koma-letter.el b/contrib/lisp/ox-koma-letter.el > index 24c1ac5..c8be5ab 100644 > --- a/contrib/lisp/ox-koma-letter.el > +++ b/contrib/lisp/ox-koma-letter.el > @@ -82,32 +82,30 @@ > :group 'org-export-koma-letter > :type 'string) > > -(defcustom org-koma-letter-author (if (boundp 'org-koma-letter-author) > - user-full-name > - ;; Empty string means "not set yet." > - "") > +(defcustom org-koma-letter-author 'user-full-name > "The sender's name. > > -This variable defaults to the value of `user-full-name'." > +This variable defaults to calling the function `user-full-name' > +which just returns the current `user-full-name'. Alternatively a > +string, nil or a function may be given. Functions must return a > +string." > :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)))) > + :type '(radio (function-item user-full-name) > + (string) > + (function) > + (const nil))) > > -(defcustom org-koma-letter-email user-mail-address > +(defcustom org-koma-letter-email 'org-koma-letter-email > "The sender's email address. > > -This variable defaults to the value of `user-mail-address'." > +This variable defaults to the value `org-koma-letter-email' which > +returns `user-mail-address'. Alternatively a string, nil or a > +function may be given. Functions must return a string." > :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)))) > + :type '(radio (function-item org-koma-letter-email) > + (string) > + (function) > + (const nil))) > > (defcustom org-koma-letter-from-address nil > "Sender's address, as a string." > @@ -134,12 +132,6 @@ This variable defaults to the value of `user-mail-address'." > :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 > @@ -232,17 +224,16 @@ content temporarily.") > (org-export-define-derived-backend 'koma-letter 'latex > :options-alist > '((:lco "LCO" nil org-koma-letter-class-option-file) > - (:author "AUTHOR" nil org-koma-letter-author t) > + (:author "AUTHOR" nil (org-koma-letter--get-custom org-koma-letter-author) t) > (:from-address "FROM_ADDRESS" nil org-koma-letter-from-address newline) > (:phone-number "PHONE_NUMBER" nil org-koma-letter-phone-number) > - (:email "EMAIL" nil org-koma-letter-email t) > + (:email "EMAIL" nil (org-koma-letter--get-custom org-koma-letter-email) t) > (:to-address "TO_ADDRESS" nil nil newline) > (:place "PLACE" nil org-koma-letter-place) > (:opening "OPENING" nil org-koma-letter-opening) > (:closing "CLOSING" nil org-koma-letter-closing) > (:signature "SIGNATURE" nil org-koma-letter-signature newline) > (:ps-prefix nil "ps-prefix" org-koma-letter-ps-prefix) > - > (:with-backaddress nil "backaddress" org-koma-letter-use-backaddress) > (:with-foldmarks nil "foldmarks" org-koma-letter-use-foldmarks) > (:with-phone nil "phone" org-koma-letter-use-phone) > @@ -266,6 +257,17 @@ content temporarily.") > (org-open-file (org-koma-letter-export-to-pdf nil s v b)))))))) > > > +;;; Helper functions > + > +(defun org-koma-letter-email () > + "Return the current `user-mail-address'" > + user-mail-address) > + > +(defun org-koma-letter--get-custom (value) > + (when value > + (cond ((stringp value) value) > + ((symbolp value) (funcall value))))) > + > ;;; Transcode Functions > > ;;;; Export Block > -- > 1.8.2.3 > > >From 173826ce58954f24b268f09f45e07ac877d751de Mon Sep 17 00:00:00 2001 > From: "rasmus.pank" > Date: Sat, 25 May 2013 19:08:37 +0200 > Subject: [PATCH 3/4] bug-fix for special headers. > > * ox-koma-letter.el(org-koma-letter-ps-prefix): removed > * ox-koma-letter.el(org-koma-letter-special-tags-after-closing): > downcased to correspond to actual LaTeX-functions > * ox-koma-letter.el(org-koma-letter-special-tags-after-letter): > list of headings to be inserted after =\end{letter}= > * ox-koma-letter.el(org-koma-letter-special-tags): > removed. generated on the go. > * ox-koma-letter.el(org-koma-letter-special-contents): special > headings are controlled via =:with-after-closing= and > =:with-after-letter=. These can also be used for reordering the > way headers are inserted. > * ox-koma-letter.el: some cleaning up. > * ox-koma-letter.el(org-koma-letter--prepare-special-contents-as-macro): > new function for inserting macros based on list of special > tags. > --- > contrib/lisp/ox-koma-letter.el | 111 +++++++++++++++++++++++------------------ > 1 file changed, 62 insertions(+), 49 deletions(-) > > diff --git a/contrib/lisp/ox-koma-letter.el b/contrib/lisp/ox-koma-letter.el > index c8be5ab..bbfe168 100644 > --- a/contrib/lisp/ox-koma-letter.el > +++ b/contrib/lisp/ox-koma-letter.el > @@ -196,23 +196,13 @@ Use `foldmarks:true' to activate default fold marks or > :group 'org-export-koma-letter > :type 'boolean) > > -(defcustom org-koma-letter-ps-prefix "\\textsc{ps}: " > - "The prefix of PS. Used to construct PS as \"PS-SUFFIX PS\"" > - :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") > - > -(defconst org-koma-letter-special-tags-other > - '("FROM" "AFTER_LETTER") > - "Headers tags to be inserted after closing") > + '("ps" "encl" "cc") > + "Header tags to be inserted after closing") > > -(defconst org-koma-letter-special-tags > - (append org-koma-letter-special-tags-other > - org-koma-letter-special-tags-after-closing) > - "Header tags with special meaning") > +(defconst org-koma-letter-special-tags-after-letter > + '("after_letter") > + "Header tags to be inserted after closing") > > (defvar org-koma-letter-special-contents nil "holds special > content temporarily.") > @@ -233,13 +223,15 @@ content temporarily.") > (:opening "OPENING" nil org-koma-letter-opening) > (:closing "CLOSING" nil org-koma-letter-closing) > (:signature "SIGNATURE" nil org-koma-letter-signature newline) > - (:ps-prefix nil "ps-prefix" org-koma-letter-ps-prefix) > + (:with-after-closing nil "after-closing-order" > + 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-foldmarks nil "foldmarks" org-koma-letter-use-foldmarks) > (: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-after-closing nil "after-closing-order" org-koma-letter-special-tags-after-closing) > (:with-subject nil "subject" org-koma-letter-subject-format)) > :translate-alist '((export-block . org-koma-letter-export-block) > (export-snippet . org-koma-letter-export-snippet) > @@ -263,11 +255,47 @@ content temporarily.") > "Return the current `user-mail-address'" > user-mail-address) > > +;; The following is taken from/inspired by ox-grof.el > +;; Thanks, Luis! > + > +(defun org-koma-letter--get-tagged-contents (tag) > + "Get tagged content from `org-koma-letter-special-contents'" > + (cdr (assoc tag org-koma-letter-special-contents))) > + > (defun org-koma-letter--get-custom (value) > + "Determines whether a value is nil, a string or a > +function (a symobl). If it is a function it it evaluates it." > (when value > (cond ((stringp value) value) > ((symbolp value) (funcall value))))) > > + > +(defun org-koma-letter--prepare-special-contents-as-macro (a-list &optional keep-newlines no-tag) > + "Finds all the components of `org-koma-letter-special-contents' > +corresponding to members of the `a-list' and return them as a > +string to be formatted. The function is used for inserting > +content of speciall headings such as PS. > + > +If keep-newlines is t newlines will not be removed. If no-tag is > +is t the content in `org-koma-letter-special-contents' will not > +be wrapped in a macro named whatever the members of a-list are called. > +" > + (let (output) > + (dolist (ac a-list output) > + (let > + ((x (org-koma-letter--get-tagged-contents ac)) > + (regexp (if keep-newlines "" "\\`\n+\\|\n*\\'"))) > + (when x > + (setq output > + (concat > + output "\n" > + ;; sometimes LaTeX complains about newlines > + ;; at the end or beginning of macros. Remove them. > + (unless no-tag (format "\\%s{" ac)) > + (format "%s" (replace-regexp-in-string regexp "" x)) > + (unless no-tag "}") > + ))))))) > + > ;;; Transcode Functions > > ;;;; Export Block > @@ -302,17 +330,12 @@ channel." > (org-export-with-backend 'latex keyword contents info)))) > > > -;; The following is taken from/inspired by ox-grof.el > -;; Thanks, Luis! > - > -(defun org-koma-letter--get-tagged-content (tag info) > - (cdr (assoc tag org-koma-letter-special-contents))) > - > +;; Headline > > (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 > +holding contextual information. > > Note that if a headline is tagged with a tag from > `org-koma-letter-special-tags' it will not be exported, but > @@ -320,16 +343,14 @@ 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 (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)) > + (org-export-get-tags headline info))) > + (tag (downcase (car tags)))) > + (if (member tag > + (append (plist-get info :with-after-letter) > + (plist-get info :with-after-closing))) > (progn > - (push (cons (upcase (car tags)) contents) > - org-koma-letter-special-contents) > + (push (cons tag contents) > + org-koma-letter-special-contents) > nil) > contents))) > > @@ -441,23 +462,15 @@ holding export options." > ;; Letter body. > contents > ;; Closing. > - (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 (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 "\n\\closing{%s}\n" (plist-get info :closing)) > + (org-koma-letter--prepare-special-contents-as-macro > + (plist-get info :with-after-closing)) > ;; Letter end. > - "\\end{letter}\n" > - (let ((x (org-koma-letter--get-tagged-content "AFTER_LETTER" info))) > - (when x (format x))) > + "\n\\end{letter}\n" > + (org-koma-letter--prepare-special-contents-as-macro > + (plist-get info :with-after-letter) t t) > ;; Document end. > - "\\end{document}" > + "\n\\end{document}" > )) > > > @@ -487,7 +500,7 @@ contents of hidden elements. > When optional argument BODY-ONLY is non-nil, only write code > between \"\\begin{letter}\" and \"\\end{letter}\". > > -EXT-PLIST, when provided, is a property list with external > +EXT-PLIST, when provided, is a proeprty list with external > parameters overriding Org default settings, but still inferior to > file-local settings. > > -- > 1.8.2.3 > > >From 05c5371628af21e5f2a2a10404c4cfc354486ec6 Mon Sep 17 00:00:00 2001 > From: "rasmus.pank" > Date: Sat, 25 May 2013 19:35:10 +0200 > Subject: [PATCH 4/4] change default of org-koma-letter-signature to nil > > * ox-koma-letter.el(org-koma-letter-signature): set to nil > > The previoues value corresponds to the default value cf. the the koma > manual pp. 183. > --- > contrib/lisp/ox-koma-letter.el | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/contrib/lisp/ox-koma-letter.el b/contrib/lisp/ox-koma-letter.el > index bbfe168..4cb402e 100644 > --- a/contrib/lisp/ox-koma-letter.el > +++ b/contrib/lisp/ox-koma-letter.el > @@ -132,7 +132,7 @@ function may be given. Functions must return a string." > :group 'org-export-koma-letter > :type 'string) > > -(defcustom org-koma-letter-signature "\\usekomavar{fromname}" > +(defcustom org-koma-letter-signature nil > "String used as the signature." > :group 'org-export-koma-letter > :type 'string) > -- > 1.8.2.3 >