all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* small koma bug
@ 2014-03-10  8:44 Alan Schmitt
  2014-03-10 13:24 ` Rasmus
  0 siblings, 1 reply; 3+ messages in thread
From: Alan Schmitt @ 2014-03-10  8:44 UTC (permalink / raw)
  To: rasmus; +Cc: emacs-orgmode

Hello Rasmus and all,

I think I have found a small bug in ox-koma-letter, but to fix it I
would like your input.

The bug: if "from-address" is not specified in the file, then it will be
set unconditionally to the empty string, even if it is specified in an
lco file.

The reason of the bug is as follows.

To set up the from address, we call this:

#+begin_src emacs-lisp
   (let ((from-address (org-koma-letter--determine-to-and-from info 'from)))
     (and from-address (format "\\setkomavar{fromaddress}{%s}\n" from-address)))
#+end_src

This uses this function:
#+begin_src emacs-lisp
(defun org-koma-letter--determine-to-and-from (info key)
  "Given INFO determine KEY for the letter.
KEY should be `to' or `from'.

`ox-koma-letter' allows two ways to specify TO and FROM.  If both
are present return the preferred one as determined by
`org-koma-letter-prefer-special-headings'."
  (let ((option (plist-get info (if (eq key 'to) :to-address :from-address)))
	(headline (org-koma-letter--get-tagged-contents key)))
    (replace-regexp-in-string
     "\n" "\\\\\\\\\n"
     (org-trim
      (or (if (plist-get info :special-headings) (or headline option)
	    (or option headline))
	  ;; Fallback values.
	  (if (eq key 'to) "\\mbox{}" org-koma-letter-from-address))))))
#+end_src

Note that in the default case we return "org-koma-letter-from-address",
which is set to the empty string by default:
#+begin_src emacs-lisp
(defcustom org-koma-letter-from-address ""
  "Sender's address, as a string.
This option can also be set with one or more FROM_ADDRESS
keywords."
  :group 'org-export-koma-letter
  :type 'string)
#+end_src

As the empty string is considered as "true", we apply the format
function in the first code block.

I would suggest to have "org-koma-letter-from-address" begin "nil" as
default. My question is: is it an allowed value for a string?

Thanks,

Alan

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: small koma bug
  2014-03-10  8:44 small koma bug Alan Schmitt
@ 2014-03-10 13:24 ` Rasmus
  2014-03-10 13:50   ` Alan Schmitt
  0 siblings, 1 reply; 3+ messages in thread
From: Rasmus @ 2014-03-10 13:24 UTC (permalink / raw)
  To: alan.schmitt; +Cc: emacs-orgmode

Hi Alan,

Alan Schmitt <alan.schmitt@polytechnique.org> writes:

> I think I have found a small bug in ox-koma-letter, but to fix it I
> would like your input.
>
> The bug: if "from-address" is not specified in the file, then it will be
> set unconditionally to the empty string, even if it is specified in an
> lco file.

OK.  AFAIK it's OK to leave out the fromaddress and fromname.

> The reason of the bug is as follows.
>
> To set up the from address, we call this:
>
> #+begin_src emacs-lisp
>    (let ((from-address (org-koma-letter--determine-to-and-from info 'from)))
>      (and from-address (format "\\setkomavar{fromaddress}{%s}\n" from-address)))
> #+end_src

How about:

   (let ((from-address (org-koma-letter--determine-to-and-from info 'from)))
     (and (org-string-nw-p from-address) (format "\\setkomavar{fromaddress}{%s}\n" from-address)))

Or more explicitly

   (let ((from-address (org-koma-letter--determine-to-and-from info 'from)))
     (when (org-string-nw-p from-address) (format "\\setkomavar{fromaddress}{%s}\n" from-address)))

> This uses this function:
> #+begin_src emacs-lisp
> (defun org-koma-letter--determine-to-and-from (info key)
>   "Given INFO determine KEY for the letter.
> KEY should be `to' or `from'.
>
> `ox-koma-letter' allows two ways to specify TO and FROM.  If both
> are present return the preferred one as determined by
> `org-koma-letter-prefer-special-headings'."
>   (let ((option (plist-get info (if (eq key 'to) :to-address :from-address)))
> 	(headline (org-koma-letter--get-tagged-contents key)))
>     (replace-regexp-in-string
>      "\n" "\\\\\\\\\n"
>      (org-trim
>       (or (if (plist-get info :special-headings) (or headline option)
> 	    (or option headline))
> 	  ;; Fallback values.
> 	  (if (eq key 'to) "\\mbox{}" org-koma-letter-from-address))))))
> #+end_src

I guess org-koma-letter-from-address can be left empty, but for
instance 'to must have a value different from the empty string to not
create a LaTeX error.  As I said above, quick testing suggest this is
not necessary for fromaddress.

> As the empty string is considered as "true", we apply the format
> function in the first code block.

See below.

> I would suggest to have "org-koma-letter-from-address" begin "nil" as
> default. My question is: is it an allowed value for a string?

You can use org-string-nw-p to test is S is only white-space.  When
Nicolas cleaned the file he made all (or most?) defaults into strings,
so let's stick with that.

Let me know if your happy with this.

—Rasmus

-- 
Summon the Mothership!

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: small koma bug
  2014-03-10 13:24 ` Rasmus
@ 2014-03-10 13:50   ` Alan Schmitt
  0 siblings, 0 replies; 3+ messages in thread
From: Alan Schmitt @ 2014-03-10 13:50 UTC (permalink / raw)
  To: Rasmus; +Cc: emacs-orgmode

Rasmus <rasmus@gmx.us> writes:

> How about:
>
>    (let ((from-address (org-koma-letter--determine-to-and-from info 'from)))
>      (and (org-string-nw-p from-address) (format "\\setkomavar{fromaddress}{%s}\n" from-address)))
>
> Or more explicitly
>
>    (let ((from-address (org-koma-letter--determine-to-and-from info 'from)))
>      (when (org-string-nw-p from-address) (format "\\setkomavar{fromaddress}{%s}\n" from-address)))

It sounds good. I'll commit this change.

Thanks,

Alan

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-03-10 14:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-10  8:44 small koma bug Alan Schmitt
2014-03-10 13:24 ` Rasmus
2014-03-10 13:50   ` Alan Schmitt

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.