From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.help Subject: Re: Coding system to encode arguments to groff? Date: Sun, 03 Oct 2021 18:14:00 +0300 Message-ID: <83fsti87k7.fsf@gnu.org> References: <87v92jyfnb.fsf@vagabond.tim-landscheidt.de> <83o88bio7g.fsf@gnu.org> <87bl469roj.fsf@vagabond.tim-landscheidt.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7584"; mail-complaints-to="usenet@ciao.gmane.io" To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sun Oct 03 17:14:41 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mX3CL-0001mV-1e for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 03 Oct 2021 17:14:41 +0200 Original-Received: from localhost ([::1]:47810 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mX3CI-0001cB-RF for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 03 Oct 2021 11:14:38 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:33012) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mX3Bu-0001Zx-L6 for help-gnu-emacs@gnu.org; Sun, 03 Oct 2021 11:14:14 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:50396) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mX3Bu-0003fT-Df for help-gnu-emacs@gnu.org; Sun, 03 Oct 2021 11:14:14 -0400 Original-Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:1585 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mX3Bu-0008LU-1H for help-gnu-emacs@gnu.org; Sun, 03 Oct 2021 11:14:14 -0400 In-Reply-To: <87bl469roj.fsf@vagabond.tim-landscheidt.de> (message from Tim Landscheidt on Sun, 03 Oct 2021 13:14:04 +0000) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:133524 Archived-At: > From: Tim Landscheidt > 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.