anhinga_anhinga: (Default)
[personal profile] anhinga_anhinga
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.
This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

Profile

anhinga_anhinga: (Default)
anhinga_anhinga

July 2021

S M T W T F S
    123
45678910
11121314151617
18 192021222324
25262728293031

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jul. 22nd, 2025 08:23 pm
Powered by Dreamwidth Studios