Emacs blog

20100829 IRC with furigana

Today I have written code that displays kanji reading in Japanese while chatting on IRC. I often know the meaning of the character but forget the pronunciation. Other people who go to Japanese channel might find this hack helpful.

;; lisp/emacs.d/ivan-erc.el

(defvar ivan-erc-japanese-channel
  "#japanese\\|#nihongo"
  "Regexp of channels that are in Japanese")


(defun ivan-erc-furigana ()
  "Display furigana when receiving a message in Japanese"
  (when (and (string-match ivan-erc-japanese-channel (buffer-name))
             (memq 'unicode (find-charset-region
                             (point-min) (point-max)))
             (ivan-japanese-kanji string))
    (insert (kakasi (buffer-substring-no-properties
                     (point-min) (point-max))))
    (erc-restore-text-properties)))

(add-hook 'erc-insert-modify-hook 'ivan-erc-furigana)

;; /lisp/emacs.d/ivan-japanese.el

(defun ivan-japanese-kakasi (input)
  "Take a Japanese string and return INPUT in hiragana"
  (get-buffer-create kakasi-buffer)
  (with-temp-buffer
    (insert input)
    (let ((coding-system-for-read 'euc-jp)
          (coding-system-for-write 'euc-jp))
      (call-process-region (point-min) (point-max)
                           "kakasi" nil kakasi-buffer nil "-JH" "-s")))
  (prog1
      (with-current-buffer kakasi-buffer
        (setq kakasi-ret
              (buffer-substring-no-properties (point-min) (point-max))))
    (kill-buffer kakasi-buffer)))

(defun ivan-japanese-kanji (string)
  "Return t if string contains Japanese kanji"
  (let ((length (length string))
        (count 0)
        (ret nil)
        (char ?a))
    (while (< count length)
      (setq char (aref string count))
      (if (and (< char ?\u9fa5)
               (> char ?\u4e00))
          (setq ret t))
      (setq count (1+ count)))
    ret))

20100826: nterm version 0.4

In this version of nterm I have added unit testing and reworked ED and EL.

20100725: nterm version 0.3

This version fixed several bugs that made the program crash. Optimisation makes nterm noticably faster.

20100530: etags and bookmarks

I did some contracting work on a C++ project that was a complete disaster. I used etags on hundreds of classes and I wish I had a tag history listing mode for emacs. With bookmark it's dead simple, the following code will stash all etags you jumped to in the bookmark file.

;; put etags information in bookmark
(defun ivan-etags-bookmark ()
  (bookmark-set tagname))

(add-hook 'find-tag-hook 'ivan-etags-bookmark)

20100417: new version of winpack

I have made a new version of winpack. I cut it to half the size. It includes emacs and many other goodies. Most Unix users will feel at home with a bash shell and several GNU tools.

20091217: appointment implement variable warning time

I use appointment with org. I find that a global time delay for each appointments is inconvenient. For example I need to be warned an hour before an appointment downtown and only 5 minutes for a meeting at work. I have hacked appt.el to keep track of a delay for each appointment. The function appt-add is compatible with the old appt.

Download the new appt, or apply the patch.

20091129: nterm version 0.2 is out

The big new feature is double width and height font. If you are interested it can be downloade here.

20090927: Picture for bbdb

Bbdb (Big Brother DataBase) is the rolodex of emacs. I have added picture support so that you can see your contacts face.

All you need is to download the following file bbdb-picture.el.

20090914: Why emacs is great

With emacs you can chat in japanese in irc and look up words you don't know.

20070608: Gradient Color Faces on Emacs

Another productive day hacking and what not. A picture is worth a thousand words. Download the code if you want to use it.

Snapshot of emacs with gradient color faces
Snapshot of emacs with gradient color faces

20070629: Miscelleneous projects

This month has been productive with Emacs. The mercurial back-end I wrote last year made it in CVS. I wrote a world clock that should be included as well.

I have made a Real Player interface. It needs X Windows to run. It interface with emacs-w3m so that you can listen to radio. Users can bind keys to pause, fast forward, rewind stream.

It can even embed the player in a frame if emacs is compiled with GTK, I am not using this functionality. I expect it could play video in a different frame.

I made good progress on a password manager called keyring. It was designed with a modular back-end.

Currently, there are two back-ends pwsafe and palm. Pwsafe uses the program of the same name. Palm is a back-end for the GNU Keyring program for the Palm OS. It uses a Perl script that called keyring.pl.

Support for editing, renaming and deleting entries still needs to be written.

20040624: Nxml Mode For Emacs

Another tips on emacs. Use James Clark's nxml mode, it is a fantastic XML mode that validates document on the fly. It is handy to edit Docbook document.

It can also be used to edit XHTML pages. No need to run the document through a validator as the errors will be highlighted on the fly. This software is just too good for words and helps me create valid HTML document quicker.

The screenshot belows show a document with intentional errors. All errors are underlined red. If you move the cursor on the error, it will display more information on the status bar.

Nxml mode in action
Nxml mode in action

There is package ready to install on Debian testing called nxml-mode.

back