Emacs 24 (Released 2012-06)

By Xah Lee. Date: . Last updated: .

This page is a on-going list of tips and tricks about emacs 24. Emacs 24.1 is released on . For download locations for Windows, Mac, Linux, see: Download Emacs for Windows/Mac.

Emacs NEWS Files

Emacs Package System

New in emacs 24 is a package system. It lets you easily install and manage packages. This is probably the most significant feature in 24. See: Emacs: Install Package with ELPA/MELPA.

electric-pair-mode

See: Emacs Init: Auto Insert Closing Bracket (electric-pair-mode)

New Command: count-words

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.

For how to write simple version of wc in elisp, see: Elisp: Count Lines, Words, Chars.

Note: emacs's count-words does not give the same result as unix “wc”, and count-words is major mode dependent. (it depends on the major mode's syntax table to determine the delimiters for “word”)

New Command: rectangle-number-lines

rectangle-number-linesCtrl+x r N】 will insert a vertical column of numbers into a block of text, like this:

  1. x
  2. x
  3. x
  4. x

For detail, see: Emacs: Edit Column Text, Rectangle.

occur-edit-mode: Edit Search Output in list matching lines

When using list-matching-lines (aka occur) or multi-occur, you can edit the output, so that the change will happen in the original file. In the output buffer, Alt+x occur-edit-modee】. Example:

  1. Open a file, then Alt+x occur or multi-occur.
  2. Switch cursor to the output pane.
  3. Alt+x occur-edit-modee】.
  4. Edit. When done, Alt+x occur-cease-editCtrl+c Ctrl+c】.
  5. Your changes are made in original file(s) too. You still need to save the file(s).

Thanks to [Darren ha https://plus.google.com/106100313935900317010/posts] for the tip on occur-edit-mode.

See also:

Linux/Emacs Copy/Paste Problem

2012-04-22 in GNU Emacs 24.0.93.1, x-select-enable-clipboard is set to t now. For what it means, see: Emacs: Sync Copy/Paste Clipboards with Linux X11.

Support for Bidirectional Text

For example: { Arabic, Persian (Iran), Hebrew (Israel)}. They flow from right to left.

Paste this paragraph in emacs “(كتاب ألف ليلة و ليلة)”. Then, hold down right arrow key, then when cursor moves into the Arabic text, it'll suddenly reverse direction.

Note, when a buffer's text is all Right To Left (R2L) or all Left To Right (L2R) script, then right-char always move to the right, and forward-char moves depending on context.

When a buffer's text contains mixed R2L/L2R text, then both visually change direction, VISUALLY. But logically, right-char still moves to the right only, LOGICALLY.

This is a fairly complex issue, i don't quite understand. Eli Zaretskii (a long time emacs dev) gave a detailed explanation in this thread: http://groups.google.com/group/gnu.emacs.help/browse_frm/thread/2e362e81042bda91

{beginning-of-defun, end-of-defun} in {C, C++} modes

There's some changes on how the cursor moves when you call {beginning-of-defunCtrl+Alt+Home】, end-of-defunCtrl+Alt+End】} in {C,C++} modes in emacs.

Now, it move the cursor just one level up of a nested block. Before, it moves several levels up to actual function/class definition, out of several nested blocks of code if necessary.

Here's a sample C++ template code you can test on.

namespace my_namespace {

  void func1() {
  }

  void func2() {
  }

  class MyClass {
  public:
    MyClass() {
    }

    void method1() {
    }

    void method2() {
    }
  };

}

Here's a video showing the difference. (Thanks a lot to David Capello [https://davidcapello.com/].)

vidthumb 6sOdsoQbwm8

Unicode 6 Support

Unicode 6 is now supported. For example, Alt+x ucs-insertCtrl+x 8 Enter】 then “GRINNING CAT FACE WITH SMILING EYES”, then you get this char 😸.

Note: the char won't display in emacs. First, make sure your system has the font. Best is Symbola. 〔see Download Free Unicode Fonts〕 But even if you have Symbola installed, emacs won't show the char unless you actually switch to that font. Am not sure there's much one can do to fix this. (Question asked at http://groups.google.com/group/gnu.emacs.help/browse_frm/thread/f76ba66700f97967#)

Unicode {Space, Hyphen} Chars Display

Certain non-ASCII space and hyphen Unicode characters are displayed with a reddish color to distinguish them from similar ASCII ones. Emacs 24 added 2 more. The complete list of such chars are:

(Copy the above list and paste in emacs to see.) Call describe-variable on nobreak-char-display for detail.

To insert unicode, Alt+x ucs-insert. 〔see Emacs: Insert Unicode Character

Color Themes

To activate, Alt+x load-theme, then press Tab to show a list of available themes. 〔see Emacs Init: Set Color Theme

describe-char Shows Char Position

When Alt+x describe-char, now it display the char's position in the first line.

Here's emacs 23 output:

        character: m (109, #o155, #x6d)
preferred charset: ascii (ASCII (ISO646 IRV))
       code point: 0x6D
           syntax: w    which means: word
…

Here's emacs 24 output:

             position: 9198 of 11337 (81%), column: 0
            character: m (displayed as m) (codepoint 109, #o155, #x6d)
    preferred charset: ascii (ASCII (ISO646 IRV))
code point in charset: 0x6D
               syntax: w        which means: word
…

Spell-Checking on Windows is 25 Times Faster!

Just discovered something incredible. For emacs on Windows, Alt+x flyspell-buffer usually takes 5 seconds for a small file (e.g. 8k sized). In emacs 24, it is now less than a second!

Here's a exact timing, on a 80k HTML file:

the release notes (aka emacs NEWS) didn't mention anything about spell, but has the following:

** The default value of redisplay-dont-pause is now t
This makes Emacs feel more responsive to editing commands that arrive
at high rate, for example, if you lean on some key, because stopping redisplay
in the middle (when this variable is nil) forces more expensive
updates later on, and Emacs appears to be unable to keep up.

however, setting redisplay-dont-pause to t, didn't help in emacs 23.

Misc

calc keys

calc's keymapping has improved.

before, supposed you have set Alt+z for undo globally. But it won't work in calc. You have to use emacs's default. Now it does.

Bookmark File Location

The default location for bookmark changed. In emacs 23, it's at ~/.emacs.bmk. In emacs 24, it's at ~/.emacs.d/bookmarks.

You should move and rename your bookmark file to the new location.

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

For the basics of bookmark, see: Emacs: Bookmark Tutorial.

Sort list-colors-display by Hue

Alt+x list-colors-display to list colors and their RGB hexadecimal values. But the result is not sorted. Now, you can sort it by hue. Much better. Put this in your Emacs Init File:

(setq list-colors-sort 'hsv )

See also: CSS: HSL Color.

Docstring Link to Elisp Doc

Some function's doc string now has a link to elisp manual. For example, Alt+x describe-variable on font-lock-defaults. Excerpt:

font-lock-defaults is a variable defined in `font-core.el'.

…

(See also Info node `(elisp)Font Lock Basics'.)

…

see also: Elisp: Docstring Markup

Emacs Lisp Changes

copy-directory Change

in emacs 24, there's this major backward-incompatible change

** `copy-directory' now copies the source directory as a subdirectory
of the target directory, if the latter is an existing directory.  The
new optional arg COPY-CONTENTS, if non-nil, makes the function copy
the contents directly into a pre-existing target directory.

this means, all existing elisp scripts will break. (it broke mine)

basically, it's trying to follow the behavior of unix “cp” command. There are 2 problems:

here's a workaround:

(if (>= emacs-major-version 24)
           (if (file-exists-p toDir)
               (copy-directory fromDir (concat toDir "/../"))
             (copy-directory fromDir toDir) )
         (copy-directory fromDir toDir) )

🛑 WARNING: in emacs 24.3, copy-directory had incompatible change again.

Emacs 24 Common Lisp Package Name Change

Emacs 24 Common Lisp Package Name Change

Misc, to be Written

** New basic faces `error', `warning', `success' are available to highlight strings that indicate failure, caution or successful operation.


new scroll-up-line. Can't see how this effectively differs from scroll-up-command or scroll-up. They are all implemented on top of scroll-up, which is written in C code.

new commands: {scroll-up-line, scroll-up-command}. They are all implemented on top of the old scroll-up, which is written in C code.

Note that scroll-up does a page down, with key PageDown. But when given a argument of n, it scroll by n lines. Now, PageDown is associated with scroll-up-command.

Other Sources on Emacs 24 Changes

For a official list of what's changed in emacs 24.1, Alt+x view-emacs-news. See also: