[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Coding system to encode arguments to groff?
From: |
Eli Zaretskii |
Subject: |
Re: Coding system to encode arguments to groff? |
Date: |
Sun, 03 Oct 2021 18:14:00 +0300 |
> From: Tim Landscheidt <tim@tim-landscheidt.de>
> Cc: help-gnu-emacs@gnu.org
> Date: Sun, 03 Oct 2021 13:14:04 +0000
>
> | (let
> | ((temp-ps-buffer (generate-new-buffer "*test ps*"))
> | (test-arg "a-o"))
> | (with-temp-buffer
> | (insert ".fam H\n\\*[test-arg]\n")
> | (call-process-region
> | (point-min)
> | (point-max)
> | "groff"
> | nil
> | temp-ps-buffer
> | nil
> | "-Tps"
> | "-d" (concat "test-arg=" test-arg)))
> | (switch-to-buffer temp-ps-buffer)
> | (ps-mode)
> | (doc-view-mode))
>
> produces a PostScript buffer with the text "a-o".
>
> With test-arg = "ä-ö" (ä minus ö), it produces gibberish mi-
> nus gibberish.
>
> With test-arg = (encode-coding-string "ä-ö" 'iso-latin-1) (ä
> minus ö), it produces the text "ä-ö".
>
> With test-arg = (encode-coding-string "ä–ö" 'iso-latin-1) (ä
> endash ö), it produces the text "ä[white space]ö".
>
> With test-arg = (shell-command-to-string (concat "preconv -r
> <(echo " (shell-quote-argument "ä–ö") ")")) (ä endash ö), it
> produces the intended text "ä–ö".
So the problem is that troff doesn't accept non-ASCII command-line
arguments, and so you want to convert non-ASCII characters into a
series of characters encoded in the [\uNNNN] form, is that right?
Then I guess mapconcat is your friend, something like
(mapconcat (lambda (ch)
(format "[\\u%4.4X]" ch))
"ä–ö" "")
There's no need to use preconv at all, as Emacs can do that by itself.
And this isn't an encoding, because codepoints are not encoded in any
sense of that word.