The function mac-string-to-utxt (inside term/mac-win.el) is used to
encode text which is then placed onto the system clipboard, It
currently uses the encodings utf-16be-mac and/or utf-16le-mac which
replace all \n characters with \r (0x0A with 0x0D), You can add the
following to .emacs to fix this and preserve the correct newlines
in the buffer/file:
(defun mac-string-to-utxt (string &optional coding-system)
(or coding-system (setq coding-system mac-system-coding-system))
(let (data encoding)
(when (and (fboundp 'mac-code-convert-string)
(memq (coding-system-base coding-system)
(find-coding-systems-string string)))
(setq coding-system
(coding-system-change-eol-conversion coding-system 'unix))
(let ((str string))
(when (and (eq system-type 'darwin)
(eq coding-system 'japanese-shift-jis-mac))
(setq encoding mac-text-encoding-mac-japanese-basic-variant)
(setq str (subst-char-in-string ?\\ ?\x80 str))
(subst-char-in-string ?\\ ?\x5c str t)
;; ASCII-only?
(if (string-match "\\`[\x00-\x7f]*\\'" str)
(setq str nil)))
(and str
(setq data (mac-code-convert-string
(encode-coding-string str coding-system)
(or encoding coding-system) nil)))))
(or data (encode-coding-string string (if (eq (byteorder) ?B)
'utf-16be
'utf-16le)))))
The only change is in the last two lines, removal of -mac in each.