This Monday, Emacs has an exciting new release, version 24.4. It’s a minor release, but with plenty of new features. Check this post to see all new features.

I’ve actually played with this version a half years ago. I am not a native English speaker. When I write some English notes, posts or papers with Emacs, I check the dictionary very often. Online dictionaries such as Bing dict are always my first choice. Compare to traditional dictionary, they are usually up-to-date, and provide lots of real use cases, which are very helpful. I could infer usage of words from these examples.

So I image if I could look up words inside Emacs with just one keystroke, that will save me lots of time. I tried many possible solutions, like command-line dictionaries, such as stardict. Sadly, they are all somewhat out of date, and don’t work well. I still like the online dictionary better. So looking up a word online and rendering the result html page in Emacs could be a better solution.

Then I checked web render engines in Emacs, such as w3m and w3. None of them worked good enough. I was frustrated. Somehow, I heard Emacs 24.4 shipping with a new web browser, eww. Why not give it a try? Bang! It turned out amazing. I could see all examples of the word, even images related to the word. Admittedly, it isn’t powerful as a browser, but it fits perfectly in this situation.

Conclusion: The new browser in Emacs do a pretty good job. If all you want to do is read text and view some simple images, no complicate layout and interaction, you might give it a try, and it won’t let you down. That’s definitely another reason to try the new version of Emacs.

Looking up the word “cow”

Looking up the word “cow”



(defun bing-dict ()

"Search current word in bing dictionary."

(interactive)

(save-restriction

(let (start end)

(skip-chars-backward "A-Za-z0–9") (setq start (point))

(skip-chars-forward "A-Za-z0–9") (setq end (point))

(setq current-word (buffer-substring start end))

(eww (concat "

(if (not (string= (buffer-name) "*eww*"))

(switch-to-buffer-other-window "*eww*"))

(hl-line-mode "*eww*")

;wait for 2 second, because the buffer will refresh soon and it go back to top line.

(sit-for 2)

(search-forward current-word nil t 2)

;mark the word for 1 second

(end-of-line)

(set-mark (line-beginning-position))

(sit-for 1)

(deactivate-mark)

))

) ;; ==================== DICT ==================================(defun bing-dict ()"Search current word in bing dictionary."(interactive)(save-restriction(let (start end)(skip-chars-backward "A-Za-z0–9") (setq start (point))(skip-chars-forward "A-Za-z0–9") (setq end (point))(setq current-word (buffer-substring start end))(eww (concat " http://cn.bing.com/dict/search?q= " current-word))(if (not (string= (buffer-name) "*eww*"))(switch-to-buffer-other-window "*eww*"))(hl-line-mode "*eww*");wait for 2 second, because the buffer will refresh soon and it go back to top line.(sit-for 2)(search-forward current-word nil t 2);mark the word for 1 second(end-of-line)(set-mark (line-beginning-position))(sit-for 1)(deactivate-mark))) (global-set-key (kbd "C-c q") 'bing-dict)

Above is the elisp code for online dictionary in Emacs, I use bing dict as the source, you could change it to whatever you like. Copy it to your .emacs or intit.el, then you can look up word with C-c q in Emacs.