Category Archives: Emacs

Display the character code of the character at the cursor position on Emacs

C-x = (M-x what-cursor-position)

The code point in Unicode of the character at the cursor position is displayed in the minibuffer.
For example, if you place the cursor on the letter "あ" in the file of Shift_JIS and press 'C-x =', the following is displayed in the minibuffer.

Char: あ (12354, #o30102, #x3042, file ...) point=1 of 2 (0%) column=0

`12354, #o30102, #x3042` are decimal, octal, hexadecimal notation of the code point in Unicode of "あ".

C-u C-x = (M-x describe-char)

Display detailed information of the character at the cursor position in the split window.
For example, place the cursor on the letter "あ" in the file of Shift_JIS and press 'C-u C-x =', then the following is displayed in the split window.

             position: 1 of 2 (0%), column: 0
            character: あ (displayed as あ) (codepoint 12354, #o30102, #x3042)
    preferred charset: japanese-jisx0208 (JISX0208.1983/1990 Japanese Kanji: ISO-IR-87)
code point in charset: 0x2422
               script: kana
               syntax: w  which means: word
             category: .:Base, H:2-byte Hiragana, L:Left-to-right (strong), c:Chinese, h:Korean, j:
Japanese, |:line breakable
             to input: type "C-x 8 RET 3042" or "C-x 8 RET HIRAGANA LETTER A"
          buffer code: #xE3 #x81 #x82
            file code: #x82 #xA0 (encoded by coding system japanese-shift-jis-dos)
              display: terminal code #xE3 #x81 #x82

`code point in charset: 0x2422` represents the code point of "あ" in character set JIS X 0208,
`buffer code: #xE3 #x81 #x82` represents the encoding in the buffer (UTF-8),
`file code: #x82 #xA0` represents the encoding in the file (Shift_JIS).

How to input control characters

Emacs

C-q <Control Character>

Example: Input escape character

C-q C-[

Shell, Vim

Ctrl+V <Control Character>

Example: Input escape character

Ctrl+V Ctrl+[

How to find a letter which should be pressed in combination with Control key?

<Control Character> in above explanation should be input in combination with Control key. The letter which should be input with Control key is a letter which is produced by setting 7th bit of the letter you want to input to 1, that is to say, by adding 0x40(64).
You can find it in `man ascii` etc.

Example:
Escape character is 0x1B(27).
Set 7th bit to 1, i.e. add 0x40(64) and you get 0x5B(91).
0x5B(91) is '['.
Therefore, to input escape character press Ctrl+[.

Line feed is 0x0A(10).
Set 7th bit to 1, i.e. add 0x40(64) and you get 0x4A(74).
0x4A(74) is 'J'.
Therefore, to input line feed press Ctrl+J.

Source: https://en.wikipedia.org/wiki/Control_character#How_control_characters_map_to_keyboards
エスケープ文字の入力方法 - nelnalog.note