Emacs Keyboard Macro Example: Insert All Unicode Bullets

Buy Xah Emacs Tutorial. Master emacs benefits for life.
, , …,

This page shows a example of using emacs keyboard macro feature to insert all Unicode characters whose name contains “bullet”.

Problem Description

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 . If you stuck somewhere, see:

(note: ucs-insert is obsolete in emacs 24.3. Use insert-char instead.)

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. (you should get 45 chars. If counting only unique ones, it should be 42.)

Use this search box to verify:

Unicode Search

Emacs Lisp Solution

;; print all Unicode chars up to 2^16 who's 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

(info "(elisp) Character Properties")

For a Python solution, see: Python: Processing Unicode: unicodedata Module Tutorial.

Like it?
Buy Xah Emacs Tutorial
or share
blog comments powered by Disqus