I try to create an interaction between Emacs and other applications, e. g. Microsoft Office.

For example I have defined a VBA Macro in MS Outlook which starts a search in Emacs:

strEmacsclientPath = "C:\emacs\emacs-24.3\bin\emacsclient.exe"

strShellCommand = strEmacsclientPath & " -c --eval " & Chr(34) & "(org-search-view nil" & Chr(34) & Chr(34) & Chr(34) _
    & strSearchText _
    & Chr(34) & Chr(34) & Chr(34) & ")" & Chr(34)

Call Shell(strShellCommand, vbHide)

This works, but if the text to search (defined in variable strSearchText ) contains special characters like äöü, it fails, as e. g. with the search term "für", in Emacs I get

Search words: f\374r 

In consequence, it also does not find real occurrences of the search term "für".

How can I avoid that?

I've redefined the encoding settings, as I also had problems in the past:

(prefer-coding-system 'utf-8)
(setq coding-system-for-read 'utf-8)
(setq coding-system-for-write 'utf-8)

Here are the complete current encoding settings (obtained with C-h C RET)

Coding system for saving this buffer: U -- utf-8-dos (alias: mule-utf-8-dos)

Default coding system (for new files): U -- utf-8 (alias: mule-utf-8)

Coding system for keyboard input: 1 -- iso-latin-1-unix (alias: iso-8859-1-unix latin-1-unix)

Coding system for terminal output: * -- cp1252 (alias of windows-1252)

Coding system for inter-client cut and paste: U -- utf-16le-dos

Defaults for subprocess I/O: decoding: U -- utf-8-unix (alias: mule-utf-8-unix)

encoding: U -- utf-8-unix (alias: mule-utf-8-unix)

Priority order for recognizing coding systems when reading files: 1. utf-8 (alias: mule-utf-8)
2. iso-2022-7bit
3. iso-latin-1 (alias: iso-8859-1 latin-1)
4. iso-2022-7bit-lock (alias: iso-2022-int-1)
5. iso-2022-8bit-ss2
6. emacs-mule
7. raw-text
8. iso-2022-jp (alias: junet)
9. in-is13194-devanagari (alias: devanagari)
10. chinese-iso-8bit (alias: cn-gb-2312 euc-china euc-cn cn-gb gb2312)
11. utf-8-auto
12. utf-8-with-signature
13. utf-16
14. utf-16be-with-signature (alias: utf-16-be)
15. utf-16le-with-signature (alias: utf-16-le)
16. utf-16be
17. utf-16le
18. japanese-shift-jis (alias: shift_jis sjis)
19. chinese-big5 (alias: big5 cn-big5 cp950)
20. undecided

Other coding systems cannot be distinguished automatically from these, and therefore cannot be recognized automatically with the present coding system priorities.

Particular coding systems specified for certain file names:

--------- -------------- ----------------
File I/O "\.dz\'" (no-conversion . no-conversion) "\.xz\'" (no-conversion . no-conversion)
"\.lzma\'" (no-conversion . no-conversion)
"\.lz\'" (no-conversion . no-conversion)
"\.g?z\'" (no-conversion . no-conversion)
(no-conversion . no-conversion) "\.tbz2?\'" (no-conversion . no-conversion) "\.bz2\'" (no-conversion . no-conversion)
"\.Z\'" (no-conversion . no-conversion)
"\.elc\'" utf-8-emacs "\.utf\(-8\)?\'" utf-8
"\.xml\'" xml-find-file-coding-system
(raw-text . raw-text-unix) "\.tar\'" (no-conversion . no-conversion) "\.po[tx]?\'\|\.po\."
po-find-file-coding-system "\.\(tex\|ltx\|dtx\|drv\)\'" latexenc-find-file-coding-system "" find-buffer-file-type-coding-system Process I/O "[pP][lL][iI][nN][kK]" (undecided-dos . undecided-dos) "[cC][mM][dD][pP][rR][oO][xX][yY]" (undecided-dos . undecided-dos) Network I/O nothing specified

  • 2
    This is a problem with file encoding I think. \374 is an octal character. Emacs likes UTF-8 but Windows uses UTF-16. But by default on Windows Emacs should play nicely. What are your current encoding settings? Use C-h C RET to look at some of them. – nanny Nov 19 '14 at 13:50
  • My settings are a bit different. E.g., iso-latin-1-dos is my default. Are you modifying the settings in your init.el? – nanny Nov 19 '14 at 14:58
  • see my last edit. – MostlyHarmless Nov 19 '14 at 15:02
  • Yeah, I think those lines might be your problem. Have you tried Stefan's suggestion? I also had problems and tried to force Emacs to use utf-8, but I ending up taking out all my coding settings and just using the defaults and it's worked okay since. – nanny Nov 19 '14 at 15:06
  • if I go back to the standard encoding in emacs, what'll happen to my existing text files? Will they get messed up? – MostlyHarmless Nov 19 '14 at 15:10

As @nanny says, this is a problem of character encoding. I suggest you try something like (beware, I know nothing about VBA, so I'm just guessing at the syntax):

strShellCommand = strEmacsclientPath & " -c --eval " & Chr(34) _
    & "(org-search-view nil (decode-coding-string " & Chr(34) & Chr(34) & Chr(34) _
    & strSearchText _
    & Chr(34) & Chr(34) & Chr(34) & " locale-coding-system))" & Chr(34)
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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