3

I'm using some VBA scripts which copy Text in MS Outlook from an e-mail message and send it to the clipboard.

If I then paste the clipboard content with Ctrl-Y in Emacs 24.5.1 in Windows 7, the linebreaks are missing and I see a red ^M instead in my emacs buffer.

What can I do to directly insert linebreaks or convert the text in emacs to the "normal" encoding?

My current settings in my .emacs file are

;; file encoding utf-8 preferred
(prefer-coding-system 'utf-8)
(setq coding-system-for-read 'utf-8)
(setq coding-system-for-write 'utf-8)

However: If I copy a text from an e-Mail in MS Outlook to the Clipboard with Ctrl-C and paste it in an emacs-buffer with Ctrl-Y, the linebreaks are ok.

2 Answers 2

4

The linebreaks are missing because there is a conflict between your coding system on the desktop and your emacs setup. Emacs can be configured to have different coding systems for the terminal, keyboard and clipboard.

Try to set your clipboard coding system and selection coding system to utf-16-le, i.e.,:

(if (eq system-type 'windows-nt)
    (progn
      (set-clipboard-coding-system 'utf-16-le)
      (set-selection-coding-system 'utf-16-le))
  (set-selection-coding-system 'utf-8))
(setq locale-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(prefer-coding-system 'utf-8)
3
  • 1
    unfortunately, this does not help but makes things even worse, as Umlauts are now also pasted as \xxx code (like \344 instead of ä).
    – p.m
    Jun 3, 2016 at 11:11
  • 1
    Try setting (setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING))
    – aagaard
    Jun 3, 2016 at 11:27
  • unfortunately, this does not help either. :( Any other suggestion?
    – p.m
    Sep 30, 2016 at 12:13
1

Combined with @aagaard 's solution. This worked for me:

(if (eq system-type 'windows-nt)
    (progn
      (set-clipboard-coding-system 'utf-16-le)
      (set-selection-coding-system 'utf-16-le))
  (set-selection-coding-system 'utf-8))
(prefer-coding-system 'utf-8-unix)
(set-language-environment "UTF-8")
(set-default-coding-systems 'utf-8-unix)
(set-terminal-coding-system 'utf-8-unix)
(set-keyboard-coding-system 'utf-8-unix)
(setq locale-coding-system 'utf-8-unix)
;; Treat clipboard input as UTF-8 string first; compound text next, etc.
(when (display-graphic-p)
  (setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING)))

Full can be found here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.