2012-03-03

emacs 24 command: count-words

in emacs 24, a frequently asked command is finally here: “count-words”.

this command will count {lines, words, characters} of the current file. If there is a text selection, then it'll count in that region only.

if you are using emacs 23.x, you can define the command yourself. Like this:

(defun count-word-region-or-buffer ()
  (interactive)
  (message "Word count: %s" (how-many "\\w+")))

Thanks to Jon Snader (jcs) for this nice implementation.

For a detailed elisp tutorial, see: See: Emacs Lisp: Count Lines, Words, Chars.

See also: Try Out Emacs 24 Alpha Release

2012-03-02

Conway's Game of Life Recursively Defined

Conway's Game of Life within Conway's Game of Life.

Conway's Game of Life within Conway's Game of Life

more info at: Conway's Game of Life Recursively Defined

Programing Language: Steve Yegge on Dynamic Languages

Steve Yegge on dynamic languages

Dynamic Languages Strike Back (lecture by Steve Yegge)

my opinions, transcript, at: Programing Language: Steve Yegge on Dynamic Languages

Try Out Emacs 24 Alpha Release

emacs 24 alpha has been out for a while.

2 months ago i tried it and it crashes when loading linum-mode (show line numbers on left window border)

today i tried again, and it seems smooth, so far. If you want to give it a try, download at:

For Windows users, after download, unzip it. Go to the folder, in the “bin” dir, then click on file in “runemacs.exe” to launch.

it's probably better if you create a Windows shortcut, which lets you set your home dir properly.

to create a file shortcut:

  • ① Hold Alt then drag that 〔runemacs.exe〕 icon to desktop.
  • ② In the newly created alias icon, right click to open file properties. Then, in the “Start in” field, enter %home%.
  • ③ In the “Target” field, you can add your own init files. For example, here's mine: %home%\apps\emacs-24.0.93\bin\runemacs.exe -Q --load=%home%\ErgoEmacs_Source\ergoemacs\ergoemacs\init.el --load=%home%\.emacs. Here, i suppress loading init files by -Q, but load ErgoEmacs init files, then load my personal init files.

For other Windows emacs tips, such as setting up home dir, see: Emacs and Microsoft Windows Tips.

For what's changed in emacs 24, call “view-emacs-news” 【Ctrl+h n】. For a easy-to-read summary, see:

emacs 24 bookmark location changed

In emacs 23.x, the default location for bookmark is at 〔~/.emacs.bmk〕.

In emacs 24.x, it is 〔~/.emacs.d/bookmarks〕.

So, if you are upgrading to emacs 24, you might want to move and rename your bookmark file.

The default location is controlled by the variable “bookmark-default-file”.

For the basics of bookmark, see: Using Emacs's Bookmark Feature.

Programing Language Design and Language Idioms

This article shows code snippets in {Common Lisp, perl, python} to illustrate why idiomatic programing are bad.

Here's constructions in various languages. See if you can understand what they do and identify each language.

(floor x y)
x/y
x//y
require POSIX; floor(x/y);
int(x/y);

for answer, see: Programing Language Design: Why Idioms Are Bad

2012-02-29

What's “In-place algorithm”?

Here's Wikipedia In-place algorithm excerpt:

In computer science, an in-place algorithm (or in Latin in situ) is an algorithm which transforms input using a data structure with a small, constant amount of extra storage space. The input is usually overwritten by the output as the algorithm executes. An algorithm which is not in-place is sometimes called not-in-place or out-of-place.

for a example of in-place algorithm for reversing a list in {python, perl, emacs lisp, Mathematica}, see: In-place Algorithm for Reversing a List in Perl, Python, Lisp, Mathematica