Emacs Lisp Example: mark-unicode

Often, when coding HTML, i need to mark a character as Unicode, using a custom HTML tag with special CSS markup, like this:

<b class="u">∑</b>

The <b>bold</b> tag is used to markup a text to stand out, with no particular semantic meaning (as opposed to <strong>strong</strong> or <em>emphasis</em>. (See: HTML5 Tags.)). The class “u” just indicate its Unicode. This way, i can write a Javascript so that when mouse hovers on the symbol, it'll show the Unicode number and also a enlarged font.

I have several elisp commands that wraps HTML tags in various ways, but i need to do this so often that i decided to write a dedicated command just for this. Here it is:

(defun mark-unicode (p1)
  "Wrap 「<b class=\"u\"></span>」 around current character.

When called in elisp program, wrap the tag at point P1."
  (interactive (list (point)))
    (goto-char p1)
    (insert "<b class=\"u\">")
    (forward-char 1)
    (insert "</b>"))

All my easy keys are used up, so i give it a alias of “u”. (See: Emacs: Defining Alias to Increase Productivity.)

Popular posts from this blog

Browser User Agent Strings 2012

11 Years of Writing About Emacs

does md5 creates more randomness?