help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Inserting an unicode character


From: Florian Beck
Subject: Re: Inserting an unicode character
Date: Fri, 17 Jul 2009 21:57:58 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux)

Alberto Simões <hashashin@gmail.com> writes:

> Is there any way to visit an unicode table from within emacs? Or, for
> instance, inserting the caracter using its name.

The emacs sources come with a file called »UnicodeData.txt« (in 
admin/unidata/). You can do
all kinds of cool things with it. To insert a character by name:


(defvar unicode-character-alist nil)
(defvar unicode-character-names nil)

(defun unicode-get-names ()
  (let (unidata)
    (with-temp-buffer
      (insert-file-contents "/path/to/emacs/admin/unidata/UnicodeData.txt")
      (goto-char (point-min))
      (while (re-search-forward "^\\(?1:[[:alnum:]]+\\);\\(?2:.*?\\);" nil t)
        (add-to-list 'unidata
                     (cons (downcase (match-string 2)) (string-to-number 
(match-string 1) 16)))))
    (setq unicode-character-names (mapcar 'car unidata))
    (setq unicode-character-alist unidata)))

(defun unicode-insert-by-name (name)
  (interactive
   (list
    (progn
      (unless unicode-character-names (unicode-get-names))
      (completing-read
       "Insert unicode character named: "
       unicode-character-names nil t))))
  (insert (cdr (assoc name unicode-character-alist))))


-- 
Florian Beck





reply via email to

[Prev in Thread] Current Thread [Next in Thread]