jwiegley / emacs-async

Simple library for asynchronous processing in Emacs
GNU General Public License v3.0
828 stars 68 forks source link

Choose coding system based on environment #94

Closed astahlman closed 6 years ago

astahlman commented 6 years ago

Before this change, the coding system was hardcoded to utf-8-unix. This change sets the coding system to utf-8-auto, which can handle Windows-style newlines (i.e., \r\n).

Example:

#+BEGIN_SRC emacs-lisp :results output
  (defun test-decoding (coding-system)
    (let ((sexp (decode-coding-string (base64-decode-string
                                       (base64-encode-string "line
1\r\nline 2")) coding-system))
          (coding-system-for-write coding-system))
      (print (format "With coding system `%s`: {{{%s}}}" coding-system
(pp-to-string sexp)))))

  (test-decoding 'utf-8-unix) ;; treats \r as a separate newline
  (test-decoding 'utf-8-dos)  ;; treats \r\n as a single newline
  (test-decoding 'utf-8-auto) ;; treats \r\n as a single newline
#+END_SRC

#+RESULTS:
:
: "With coding system `utf-8-unix`: {{{\"line 1
\\nline 2\"}}}"
:
: "With coding system `utf-8-dos`: {{{\"line 1\\nline 2\"}}}"
:
: "With coding system `utf-8-auto`: {{{\"line 1\\nline 2\"}}}"

See https://github.com/jwiegley/emacs-async/issues/93 for more context.