anhinga_anhinga (anhinga_anhinga) wrote,
anhinga_anhinga
anhinga_anhinga

Russian in Emacs (Linux, UTF-8)

I finally learned how to edit Russian texts in Emacs (Linux, UTF-8). Since I was not able to find this technique on the net, I'd like to share it here. This, in particular, allows to include Russian substrings into the command line using M-x shell command, for example:

echo "Привет"

(Thanks to my colleague for showing me this and for allowing to share the code snippets. I tested this on one Debian and on one Red Hat configuration, in both cases there was no need to install extra packages.)

1. Displaying UTF-8

Put the following into the .emacs file:

(prefer-coding-system 'utf-8) 

;; Change encoding, make sure multibyte support turned on, and reload file
(defun set-encoding-and-reload (arg)
  "Make sure multibyte support is on, change the buffer file encoding to ARG
and then revert the file."
  (interactive "z Coding system for visited file (default, nil): ")
  (toggle-enable-multibyte-characters 1) ;; make sure mb turned on
  (setq buffer-file-coding-system arg) ;; doesn't mark file modified
  (set-terminal-coding-system arg) ;; so will work if displaying in an xterm
  (revert-buffer)) ;; leave query on


Sometimes the first command will do the trick, if not, then set utf-8 by running M-x set-encoding-and-reload

This only works if you are running emacs inside a utf-8 capable terminal window, and the encoding in the terminal window is set to be utf-8 (tested in Gnome "terminal" under Debian, and in "putty" under Windows XP). It does not work if you allow emacs to open its own window (Gnome under Debian).

2. Inputting Russian from the keyboard

Use M-x set-input-method and set it to cyrillic-translit (or there might be a different keyboard layout you prefer).

Use M-x toggle-input-method to switch between it and English.


Update: grep is capable of searching for utf-8 strings from this shell.
Tags: software
Subscribe
  • Post a new comment

    Error

    default userpic

    Your reply will be screened

  • 6 comments