insert-char provides a very convenient way to enter Unicode code points using their names and even search for code point names. Unfortunately, GNU Emacs 24.3 and Unicode 8 were released at roughly the same time, so the new code points are not available from the list provided by insert-char. How can I add them?


I implemented Aaron's solution (albeit in a lazy manner) and it works. I used the emoji list from http://emojipedia.org/unicode-7.0/ and http://emojipedia.org/unicode-8.0/ (Emacs 24.3 lacks the Unicode 7 code points too, by the way)

(nconc ucs-names
       '(("SLIGHTLY SMILING FACE" . ?πŸ™‚)
         ("SLIGHTLY FROWNING FACE" . ?πŸ™)
         ("SLEUTH OR SPY" . ?πŸ•΅)
         ("EYE" . ?πŸ‘)
         ("HOLE" . ?πŸ•³)
         ;; and so on
  • 1
    Note the current stable emacs is 24.5. There is a development version number 25 which seems to include the unicode 8.0 support. Mar 28 '16 at 14:34

Names and code points used by insert-char come from the value of ucs-names, which is a (very long) alist of Unicode names and code points originating ultimately from C code. This list isn't populated during init, because doing so can take a little while, but during the first call to the function (ucs-names).

If all you want to do is make Unicode 8 code points available in insert-char, you should be able to do so by manually adding them to ucs-names after calling (ucs-names) once to populate it. (If ucs-names is non-nil when that first call occurs, the function will assume that what's there is what should be there, and won't add anything - so whatever you added will be all you have available. This probably will break a lot of things, so you'll want to ensure it doesn't happen.)

Since ucs-names is an alist, you can just push into it; its members are of form ("CODE POINT NAME" . <code point>), where code point is the decimal representation. For example:

(push '("BOTTLE WITH POPPING CORK" . 127870) ucs-names)

would make available in insert-char an emoji which presumably would be useful for, I don't know, chatting about a wedding or the christening of a ship or something. Whether it'll show up in your buffers as an emoji, or in the same form Emacs uses to represent any other un-renderable character, is a different question; if you use a fontset including a font with that code point defined, it should render, but I can't be certain of that because I don't actually have such a font.

Looking at emojify, which uses images to display emoji in Emacs installations without an emoji font available, it appears to include BOTTLE WITH POPPING CORK, and I would expect it to be correctly displayed. Unfortunately, emojify 0.3 from Melpa Stable appears to be broken, or at least it's broken on my machine, so I can't say for certain there either. It's definitely worth a shot, though.

  • Cool! It works.
    – wnrph
    Mar 29 '16 at 9:11
  • I've downloaded the symbols block package from users.teilar.gr/~g1951d to see corks popping 🍾 πŸ˜ƒ. I copied the .ttf files to ~/.fonts and run fc-cache -fv
    – wnrph
    Mar 29 '16 at 9:34
  • 1
    No need to convert the code points to decimal, if you have them as hex (as I think is more common with unicode): The example in the answer could just as well be written (push '("BOTTLE WITH POPPING CORK" . #x1F37E) ucs-names). Mar 29 '16 at 17:16
  • @HaraldHanche-Olsen You don't have to use the hexadecimal representation either. This works too ("BOTTLE WITH POPPING CORK" . ?🍾) gnu.org/software/emacs/manual/html_node/elisp/…
    – wnrph
    Mar 30 '16 at 10:47

Your Answer

By clicking β€œPost Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.