all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Joe Riel <joer@san.rr.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Replacement for string-as-unibyte-function
Date: Mon, 01 Feb 2021 10:01:22 -0500	[thread overview]
Message-ID: <jwv8s87n8fv.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <20210131215555.547fb92e@gauss> (Joe Riel's message of "Sun, 31 Jan 2021 21:55:55 -0800")

>> So make sure the buffer in which the process writes is unibyte with
>> 
>>     (set-buffer-multibyte nil)
>> 
>> and make sure Emacs doesn't try to decode the process's output:
>> 
>>     (set-process-coding-system <proc> 'binary)
>> 
>> (which you can also set directly when you launch the process, but how
>> you do it depends on the function you use to create the process).
>
> I'm actually using make-network-process (to communicate via tls).  

Then use something like

    (make-network-process ... :coding 'binary ...)
or
    (make-network-process ... :coding '(binary . utf-8) ...)

> The filter function inserts the string into a buffer.  

Emacs receives the data from the process as a sequence of *bytes* (after
all, that's the only thing available in POSIX communication).  So in
order to pass a sequence of *chars* (aka "a multibyte string") to the
process filter, Emacs's internal C code has to do the equivalent of

    (*de*code-coding-string "thedatareceived" '<somecodingsystem>)

where <somecodingsystem> is the coding system that
`make-network-process` decided to use for that process.
And then you come along and want to call `encode-coding-string` on the
result: better use `:coding` as I suggested above in order to cut the
middle man.


        Stefan




  parent reply	other threads:[~2021-02-01 15:01 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-31 23:01 Replacement for string-as-unibyte-function Joe Riel
2021-02-01  3:03 ` Stefan Monnier
2021-02-01  5:55   ` Joe Riel
2021-02-01 14:53     ` Eli Zaretskii
2021-02-01 16:33       ` Joe Riel
2021-02-01 17:05         ` Eli Zaretskii
2021-02-01 23:43           ` Joe Riel
2021-02-02  3:30             ` Eli Zaretskii
2021-02-02  3:51               ` Joe Riel
2021-02-02 14:58                 ` Eli Zaretskii
2021-02-01 15:01     ` Stefan Monnier [this message]
2021-02-01 16:05       ` <somecodingsystem> (was: Re: Replacement for string-as-unibyte-function) moasenwood--- via Users list for the GNU Emacs text editor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwv8s87n8fv.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=help-gnu-emacs@gnu.org \
    --cc=joer@san.rr.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.