Skip to content

Commit

Permalink
Fix UTF-8 encoding for strings passed to subordinate Emacs
Browse files Browse the repository at this point in the history
  • Loading branch information
jwiegley committed Jan 8, 2016
1 parent ed05631 commit d1cc5e0
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions async.el
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ as follows:

(defun async--receive-sexp (&optional stream)
(let ((sexp (decode-coding-string (base64-decode-string
(read stream)) 'utf-8-unix)))
(read stream)) 'utf-8-unix))
;; Parent expects UTF-8 encoded text.
(coding-system-for-write 'utf-8-unix))
(if async-debug
(message "Received sexp {{{%s}}}" (pp-to-string sexp)))
(setq sexp (read sexp))
Expand All @@ -130,7 +132,10 @@ as follows:
(eval sexp)))

(defun async--insert-sexp (sexp)
(let (print-level print-length)
(let (print-level
print-length
(print-escape-nonascii t)
(print-circle t))
(prin1 sexp (current-buffer))
;; Just in case the string we're sending might contain EOF
(encode-coding-region (point-min) (point-max) 'utf-8-unix)
Expand All @@ -147,18 +152,21 @@ as follows:

(defun async-batch-invoke ()
"Called from the child Emacs process' command-line."
(setq async-in-child-emacs t
debug-on-error async-debug)
(if debug-on-error
(prin1 (funcall
(async--receive-sexp (unless async-send-over-pipe
command-line-args-left))))
(condition-case err
(prin1 (funcall
(async--receive-sexp (unless async-send-over-pipe
command-line-args-left))))
(error
(prin1 (list 'async-signal err))))))
;; Make sure 'message' and 'prin1' encode stuff in UTF-8, as parent
;; process expects.
(let ((coding-system-for-write 'utf-8-unix))
(setq async-in-child-emacs t
debug-on-error async-debug)
(if debug-on-error
(prin1 (funcall
(async--receive-sexp (unless async-send-over-pipe
command-line-args-left))))
(condition-case err
(prin1 (funcall
(async--receive-sexp (unless async-send-over-pipe
command-line-args-left))))
(error
(prin1 (list 'async-signal err)))))))

(defun async-ready (future)
"Query a FUTURE to see if the ready is ready -- i.e., if no blocking
Expand Down Expand Up @@ -263,7 +271,9 @@ returned except that it yields no value (since the value is
passed to FINISH-FUNC). Call `async-get' on such a future always
returns nil. It can still be useful, however, as an argument to
`async-ready' or `async-wait'."
(let ((sexp start-func))
(let ((sexp start-func)
;; Subordinate Emacs will send text encoded in UTF-8.
(coding-system-for-read 'utf-8-unix))
(setq async--procvar
(async-start-process
"emacs" (file-truename
Expand Down

0 comments on commit d1cc5e0

Please sign in to comment.