Emacs: Key Macro Example: Insert All Unicode Bullets

By Xah Lee. Date: . Last updated: .

This page shows a example of using Emacs: Key Macro to insert all Unicode characters whose name contains “bullet”.

Problem

Find all Unicode characters whose name contains “bullet”. For each one, show the Unicode name, followed by the character. For example, here's the result showing some of them:

BULLET •
TRIANGULAR BULLET ‣
WHITE BULLET ◦
CIRCLED BULLET ⦿

Before reading further, try to spend 10 minutes, using your knowledge of emacs to do it. Test your skill out.

Hint: use ucs-insert and emacs keyboard macro. (note: ucs-insert is obsolete since emacs 24.3. 〔see Emacs Version History〕 Use insert-char instead.) If you stuck somewhere, see:

Solution

Here's one way to do it.

BLACK LEFTWARDS BULLET            BLACK RIGHTWARDS BULLET
BULLET                            BULLET OPERATOR
CIRCLED BULLET                    CIRCLED WHITE BULLET
HYPHEN BULLET                     INVERSE BULLET
REVERSED ROTATED FLORAL HEART     BULLET  ROTATED FLORAL HEART BULLET
ROTATED HEAVY BLACK HEART BULLET  TRIANGULAR BULLET
WHITE BULLET
BLACK LEFTWARDS BULLET
BLACK RIGHTWARDS BULLET
BULLET
BULLET OPERATOR
CIRCLED BULLET
CIRCLED WHITE BULLET
HYPHEN BULLET
INVERSE BULLET
REVERSED ROTATED FLORAL HEART BULLET
ROTATED FLORAL HEART BULLET
ROTATED HEAVY BLACK HEART BULLET
TRIANGULAR BULLET
WHITE BULLET

All this sounds complicated, but if you use emacs daily, it usually is done with reflex and can be finished within 2 minutes.

Now, try a little exercise. Try to list all Unicode chars whose name contains “star” in it. See what kinda starry chars Unicode has. 〔see Unicode Stars ★ ✪ ✭ ✡ ⛤ ❉ ❄ ✿ 🌟 🌠

Emacs Lisp Solution

;; print all Unicode chars up to 2^16 whose name contains "BULLET"
(mapc
  (lambda (x)
    (let ((nn (get-char-code-property x 'name)))
      (when
          (and (not (null nn))
               (string-match "BULLET" nn))
        (insert-char x)
        (insert " " nn "\n") ) ) )
  (number-sequence 0 (expt 2 16)))

;; • BULLET
;; ‣ TRIANGULAR BULLET
;; ⁃ HYPHEN BULLET
;; ⁌ BLACK LEFTWARDS BULLET
;; ⁍ BLACK RIGHTWARDS BULLET
;; ∙ BULLET OPERATOR
;; ◘ INVERSE BULLET
;; ◦ WHITE BULLET
;; ☙ REVERSED ROTATED FLORAL HEART BULLET
;; ❥ ROTATED HEAVY BLACK HEART BULLET
;; ❧ ROTATED FLORAL HEART BULLET
;; ⦾ CIRCLED WHITE BULLET
;; ⦿ CIRCLED BULLET

(2014-04-16 thanks to Martin for initial solution)

Character Properties (ELISP Manual)

Emacs Keyboard Macro