2008-12-26

a coarse classification of naming conventions(patterns) within the Emacs ecosystem


syntactic : char, word, line, sentence, paragraph, region, page,
sexp, list, defun,
emacs-specific : register, rect, buffer, mode, frame, window,
font : face, font
filesystem : file, dir,
location and direction : beginning, end, forward, backward, next, previous, up, down,
action : search, goto, kill, delete, mark, insert, yank, fill, indent, find, view, describe, change, set,
misc : case, what, default.

2008-12-16

a native simple wc in Emacs Lisp

I googled "count words emacs" and read several articles, "Counting words in Emacs" and "Emacs Tip: Word counting with a regular expression". The first uses a loop and a regular expression to count only words in a region, and the latter uses the emacs built-in function "how-many" to count words in the whole current buffer. So I combined them to the following `wc` function which count in the whold buffer when no region is active and in the region otherwise.

(defun wc ()
"a simple mimic of the linux command `wc`"
(interactive)
(message "Word count: %s"
(how-many "\\w+"
(or (and (region-active-p) (region-beginning)) (point-min))
(or (and (region-active-p) (region-end)) (point-max)))))

2008-12-02

Beautiful Code真是被BC group翻译得糟蹋了

按照本人一贯的态度,是不看国内人翻译的英文计算机类书籍的。因为这帮人粗制滥造得多,而且技艺不精,多是会在windows xp下用鼠标左点右点就觉得自己东计算机科学了。但是碰巧今年早些时候,china pub说有beautiful code的预定,当时也没多想,就订了。没想到到手竟然是中文版,而且是一个叫BC group的团队翻译的。

拿到书很久,因为先入为主的想法,所以没有翻过。今晚因为眼睛不舒服,所以不用电脑,改为翻看这翻译的中文版的第一章,是关于正则表达式的。看到把notation翻译成“记法(notation)”,翻译者还特意在“记法“后加了括号说明原版中的用词,不知道是怕阅读者看不懂”记法“呢,还是自己翻译得没底。我觉得这个翻译为”记法“比较脑残,翻译成“表示法”会更容易明白些,也更接近正则表达式的真正精神。

然后反倒第一章的第二页(全书第10页),赫然发现第四个非空白行上把grep写成了grpe,惨不忍睹,不知道是以什么样的态度来审阅书稿,显然是相当粗糙。

所以我觉得BC group应该是“白痴小组”的意思。真是心疼那买书的66块钱。