The standard Emacs way to do this is C-x 8 RET followed by either the Unicode code point (a natural number) or the Unicode name of the character. Completion is available for the name.
If you use library Icicles then you can complete the name using parts of it, with multiple patterns matching different parts, if you want. And you can see the characters ...
If you are familiar with TeX, you will find the TeX input method helpful. Just do
M-x set-input-method TeX
then type something like \alpha — it will be replaced with the corresponding Unicode character. You can switch the input method off by typing C-\.
You can find all the supported TeX commands with
So the requirement is: When I'm using the arabic input method, and I type a digit, I want Emacs to insert the Hindi character for that digit.
To do this, we can adapt your linked approach to extend an input-method like so:
'(let ((quail-current-package (assoc "arabic" quail-package-alist)))
For some reason, Emacs isn't recognizing the file as UTF-8.
You can force Emacs to reopen the file as UTF-8 by running the command C-x RET r (revert-buffer-with-coding-system) and entering utf-8.
The reason why Emacs didn't recognize this file as UTF-8 (but recognizes other) is likely that it contains some invalid UTF-8 sequence. This sequence will still ...
Depending on your preference, you can use the following line in your .emacs to set your default coding system to utf-8. That resolved the problem for me, and I haven't noticed any other negative side effects yet.
C-q 377 RET inserts the character with octal code 377 (aka LATIN SMALL LETTER Y WITH DIAERESIS). If you want to insert a byte instead of a character, you can do it with:
M-: (insert (unibyte-string #o377)) RET
As @legoscia mentioned, Emacs will probably ask you to use another coding system after inserting such a character, but you can choose utf-8 at that ...
In addition to C-x 8 RET, mentioned here that lets you insert any character by name, C-x 8 also has many shortcuts for inserting common characters. In this case, C-x 8 o inserts "°". See them all with C-x 8 C-h
The C-x 8 keymap is also a good place to define your own shortcuts to insert the characters you use most often. The Greek letters aren't bound to ...
One should use the command set-buffer-file-coding-system (C-x RET f), set the encoding, and then save the file.
Note that you may want to first revert-buffer-with-coding-system (C-x RET r) before performing the above step, if the file is opened with the wrong encoding in the first place.
There's a very underappreciated feature most libraries that handle fonts provide for us, automatic fallback to different fonts if the font one has specified does not have all glyphs necessary to display the requested text correctly.
urxvt however does intentionally not come with automatic font fallback, at least not if you're not using fonts with the xft: ...
1) How shall I avoid creating a text file with mixed encodings when copying its different parts from different sources into an editor such as emacs?
Irrespective of the source, you can always set the encoding of a buffer by setting the variable buffer-file-coding-system. An easy way to do this is via the keybinding C-x RET f which prompts you for a file ...
When I copy the text from the source to the emacs buffer ...
What you copy depends upon the application you are copying from. Some applications release UTF-8 encoded strings while others use different formats. Emacs uses the variable selection-coding-system to determine whether to decide the encoding from the data or presume a particular encoding. See the ...
There is a new feature in Emacs from version 24.4 for using Unicode strings to access filenames in Windows. This allows using filenames containing characters that are not in the locale's 8-bit character set, which was previously impossible.
Emacs on Windows 2000 and later can now access files and ...
This happened to me for a while also before I had an idea of what was going on - here's an example of how something like this can happen - (if it matters, I'm on Windows, in case it's something specific to this build) -
Let's say you have a file that's encoded in UTF-8, and you paste some text from a website that's encoded with the Latin-1 or Windows-1252 ...
From chapter "Choosing Coding Systems for Output" of emacs manual:
Once Emacs has chosen a coding system for a buffer, it stores that
coding system in ‘buffer-file-coding-system’. That makes it the default
for operations that write from this buffer into a file, such as
‘save-buffer’ and ‘write-region’. You can specify a different coding
This is the MacRoman encoding, a legacy encoding from the pre-OSX days of Mac OS. It is available in Emacs as mac-roman.
C-x RET r mac-roman RET yes RET
You may need to select mac-roman-mac, mac-roman-dos or mac-roman-unix explicitly if Emacs doesn't automatically detect the representation of line endings. The mac-roman part is for the encoding of non-...
After some trial and error, I managed to convert ÿ to the byte 377 using M-x recode-region, specifying that it was really in raw-text but was interpreted as latin-1.
When saving the file, Emacs didn't want to save it as UTF-8, offering to save it as raw-text instead, which seems to have had the desired effect.
Why not use the same mechanism that describe-char uses to identify whether a character is encodable using utf-8 i.e. use encode-coding-char. From the documentation
Encode CHAR by CODING-SYSTEM and return the resulting string. If
CODING-SYSTEM can't safely encode CHAR, return nil. The 3rd optional
argument CHARSET, if non-nil, is a charset preferred ...
IIUC the problem is that the string you insert is undecoded, i.e. it's a string of bytes you received over the network. So you need to find out what character encoding is used/assumed by the sender (typically utf-8 these days), then call decode-coding-string with this encoding, and then insert the string it returns (which will be a string of characters).
There's no general way to find out what input methods give access to a given set of characters. An input method is written in Emacs Lisp, and it can use any Emacs Lisp primitives to build characters. From a quick look under lisp/leim/quail, I see that the latin-4-postfix, latin-4-alt-postfix, and TeX input methods include vowels with macrons.
The whole ...
If you can edit the file, you can specify the pseudo-variable coding as a file-local variable.
e.g.: -*- coding: japanese-iso-8bit; -*-
If you can't (or don't want to) edit the file, but this is only needed for yourself, then the "Using Directory Local Variable classes for individual files" trick described on that same page would be an option; but using ...
global-set-key is just a thin wrapper around define-key, ignoring some error checking it is
(defun global-set-key (key def)
(define-key (current-global-map) key def))
The documentation for define-key says that the "def" can be a number of things, including
a string (treated as a keyboard macro),
So then there is the question about what something like ...
Your problem is not one of encoding but one of decoding.
Try C-x RET r utf-8 RET, which should re-decode your file as utf-8 rather than that which was used by default. I recommend you add a -*- coding: utf-8; -*- on the first line of your file to avoid those problems (alternatively, you can change your Windows's Emacs config so as to default to using utf-8 ...
In order to handle non-ASCII characters, you need turn on multibyte via (set-buffer-multibyte t) (see also (elisp) Selecting a Representation), e.g.,
I wrote a function and added to find-file-not-found-functions
(defun srs-set-new-sql-file-coding-system ()
(if (string-match "\\.d?sql\\'" buffer-file-name)
(setq buffer-file-coding-system 'utf-8-with-signature-dos)
(add-hook 'find-file-not-found-functions 'srs-set-new-sql-file-coding-system)
As mentioned in comments, NUL bytes in the files seem to have caused it, though I have no idea how they got in. The following sed command gets rid of them:
sed -i s/"\x0"// file.org
The next time this file is opened in Emacs, its encoding should be detected correctly.
What is going on is that string in Emacs have historically been used in this context for 2 different purposes:
sequence of characters.
sequence of events.
In your case, you're writing what you think as a sequence of characters, but it's used in a context where Emacs expects a sequence of events.
Since Emacs-19 added support for GUIs, events have become a ...
Sounds like you are asking for something like this:
(defun region-bytes ()
(let ((strg (if (use-region-p)
(buffer-substring-no-properties (region-beginning) (region-end))
(message "Region has %d bytes" (string-bytes strg))))
You might also be interested in showing the region size in the mode ...
Emacs decodes a text file with an appropriate coding system when you open it with find-file.
If you have to tell emacs for some reason what coding system it should use for decoding the file you should do so before you open the file.
You can set the coding system for the next command with Options -> Multilingual Environment -> Set Coding Systems -> For Next ...