Xah Lee, 2009-08-12, 2009-08-21
This page is a list of major new features in emacs 23, released in 2009-07-30. It also includes practical tips about using the new features. This page only lists the most important or practical changes relevant to average emacs users. It may miss features or changes you find important.
This page is still work in progress. I'm going thru every item in the release notes in detail. When completely done, this sentence will be removed.
Text selection is highlighted by default. This is done by having transient-mark-mode on by default. To turn it off, put the following in your emacs init file:
(transient-mark-mode 0) ; 1 for on, 0 for off
If you leave transient-mark-mode on, now several emacs commands automatically apply to the text selection when text are selected, else they work on the current word or line. These commands are:
| purpose | emacs command name | shortcut |
|---|---|---|
| hard wrap lines | fill-paragraph | Alt+q |
| indenting code | indent-for-tab-command or other | Tab |
| check spelling | ispell-word | Alt+$ |
Also, now you can hold down the Shift key then press arrows key to select text. To turn this off, put:
(setq shift-select-mode nil) ; “t” for true, “nil” for false
However, by default, pressing delete key will not delete the selected text. If you want this, put:
(delete-selection-mode 1) ; make typing override text selection
Pressing down arrow key moves the cursor by a screen line. In emacs 22, pressing down arrow moves the cursor by newline as determined by line breaks.
To revert to emacs 22 behavior, put this:
(setq line-move-visual nil) ; use “t” for true, “nil” for false
If you just want it temporarily on or off, you can call “set-variable”.
Following is a command definition lets you toggle line-move-visual.
(defun toggle-line-move-visual () "Toggle behavior of up/down arrow key, by visual line vs logical line." (interactive) (if line-move-visual (setq line-move-visual nil) (setq line-move-visual t)) )
Long lines can wrapped at word boundary, thus not cutting a word in half into the next line. This is done by having visual-line-mode on. By default, this is off.
visual-line-mode off (top) and on (bottom) in emacs 23.
Typing “Alt+x visual-line-mode” toggles the behavior. Or, use the menu “Options‣Line Wrapping in this Buffer”.
To toggle globally, type “Alt+x global-visual-line-mode”. To set it on or off permanently, put in your emacs init file:
(global-visual-line-mode 1) ; 1 for on, 0 for off.
(info "(emacs) Visual Line Mode")
The visual line mode actually does several things. From a user view, it:
Now you can show line numbers on the margin, a common feature in other editors. (Thanks to Markus Triska)
Emacs with linum-mode on.
To toggle it in current buffer, type “Alt+x linum-mode”. To toggle globally, type “Alt+x global-linum-mode”. To set it permanetnly, put:
(global-linum-mode 1) ; always show line numbers
Minibuffer's Command completion support wildcard char “*”, and also support substring matching in some situations.
For example, if you start to open a file, and emacs prompts you for file name in the minibuffer, you can type “*report” then “Tab”, and emacs will suggest all file names that has the word “report” in it. You can use more than one wildcard at different places and in dir paths, for example: “~/*/report/ja*”.
Completion with wildcard works in minibuffer prompt whenever it makes sense. For example, when you call switch-to-buffer (C-x b), execute-extended-command (M-x), describe-function (C-h f), etc.
Note: this new completion feature applies in minibuffer only. When you are in a programing mode and pressing M-TAB for completing function names, wildcard does not apply, nor substring matching.
(info "(emacs) Completion")
In emacs 22, you can turn on partial-completion-mode or ido-mode for similar features. Both are still available in emacs 23. For some detail, see emacswiki.
whitespace-mode is a mode that make whatspace visible. Calling it toggles it. whitespace-newline-mode is similar, except that it is only for newline char.
Thanks to Vinicius Jose Latorre for whitespace-mode.
This feature is useful when you need to trim your whitespaces. For example, Python code copied from the web, or working with Tab separated values files for spreadsheets and address books.
For some tips and detail, see: How to use and setup Emacs's whitespace-mode.
Now you can open multiple files in buffer. When you open a file (find-file; C-x C-f), you can type for example “*.html”, and emacs will open all those files in buffer and show just one. (Type “Alt+x ibuffer” to see your buffers.)
In dired, the function wdired-change-to-wdired-mode now has a shortcut “Ctrl+x Ctrl+q”. Look at the menu “Immediate‣Edit File Names”. This is a very useful and little known command. It lets you rename files just by editing the dired buffer. This feature beats rename by regex (shortcut “% R”) because it is visual and not abstract as regex. When you are done editing file names, type “Ctrl+c Ctrl+c” to commit, “Ctrl+c Esc” to abort. Or, you can press “Ctrl+x Ctrl+q” again, and emacs will ask you if you want to commit the renaming.
In dired, the command “dired-do-query-replace-regexp” (shortcut “Q”) does interactive find & replace on multiple files. (See tutorial)
In emacs 23, there are 2 new functionalities. During query replace, Pressing “Y” replaces all remaining matches in all remaining files. Pressing “N” stops doing replacements in the current file and skips to the next file. These 2 new functionalities is available for all commands that use “tags-query-replace”.
This is a implementation of suggestion in bug 267.
The font engine has been rewritten. Now it support the operating system's fonts, and also supports anti-aliasing, on Windows, Mac, Linux.
To choose font, use menu “Options‣Set Default Font...”. Use “Options‣Save Options” to save for future sessions.
(Font rendering with Fontconfig and Xft. (Keith Packard))
The font selection dialogue in Emacs 23 on Windows. Emacs now uses operating system's fonts.
Font rendering in Emacs 22 and Emacs 23. The top is emacs 22 compiled normally with X11 support, running in Mac OS X's X11. The bottom is emacs 23 compiled “--with-ns”, for Mac OS X.
Characters are now represented by Unicode's utf-8 encoding internally. Thanks to Kenichi Handa.
You can see a effect of the change by typing “Alt+x describe-char”.
Output of “describe-char” on char “★” in Emacs 22
character: ★ (299365, #o1110545, #x49165, U+2605)
charset: mule-unicode-2500-33ff
(Unicode characters of the range U+2500..U+33FF.)
code point: #x22 #x65
syntax: w which means: word
buffer code: #x9C #xF2 #xA2 #xE5
file code: #xE2 #x98 #x85 (encoded by coding system mule-utf-8-unix)
display: by this font (glyph code)
-apple-monaco-medium-r-normal--12-120-72-72-m-120-iso10646-1 (#x2605)
Output of “describe-char” on char “★” in Emacs 23
character: ★ (9733, #o23005, #x2605)
preferred charset: unicode (Unicode (ISO10646))
code point: 0x2605
syntax: _ which means: symbol
category: .:Base, c:Chinese, h:Korean, j:Japanese
buffer code: #xE2 #x98 #x85
file code: #xE2 #x98 #x85 (encoded by coding system utf-8-unix)
display: by this font (glyph code)
uniscribe:-outline-BatangChe-normal-normal-normal-mono-13-*-*-*-c-*-gb2312.1980*-* (#xB18)
Character code properties: customize what to show
name: BLACK STAR
general-category: So (Symbol, Other)
Note the lines “buffer code:” and “file code:” above. In emacs 23, the info also shows the char's unicode name.
Emacs's new character engine does not effect daily emacs use much but is critical through out emacs. New in emacs 23 is support for languages, encodings, input systems that was not there before. See: list-input-methods, list-coding-systems, list-character-sets, list-charset-chars.
Byte compiled elisp files (byte-compile-file) that contains non-ascii chars now will not be compatible with emacs 22. This means elisp files byte compiled in emacs 23 cannot run in emacs 22. However, emacs 22 byte compiled files still runs in emacs 23. You should byte compile your emacs 22's “.elc” files if you don't plan to use emacs 22 anymore, because it saves a decoding process and loads faster.
This also means that autosave file are utf-8 encoded, instead of emacs 22's emacs-mule encoding. This means, those #autosave# files containing non-ascii chars can be viewed legibly by any editor that supports unicode.
The ucs-insert command now has the shortcut “Ctrl+x 8 Enter”, and it also support wildcard completion on unicode char names. For example, suppose you are looking for a unicode char that represent a star. Type “Alt+x ucs-insert”, then type “*star” then Tab, then emacs will list all unicode char names that have a star in it.
(info "(emacs) International")
Emacs can be run as a server/client. This allows you to start emacs in remote machine, and have multiple terminal emacs instances connected to it, without the delay or resource in starting another emacs instance. You can of course still start multiple emacs full process as before.
Thanks to Károly Lőrentey, Dan Nicolescu.
To launch a emacs server, type “emacs --daemon” in shell. Or, within emacs, type “Alt+x server-start”. Note that a emacs server simply runs in the background, ready for clients to launch and connect.
To start a emacs client, type “emacsclient ~” in shell. Note that you must provide a file name or dir. When a client starts, it starts in text mode in shell, not GUI.
You can set your environment variable “EDITOR” to “emacsclient”, so that, other shell apps such as mail, cron, etc will automatically launch emacs client. Multiple clients can connect to the same server.
On Windows, you start emacs server by first launching emacs, then call the command “server-start”. Running “emacs --daemon” in shell is not supported. (The error message is: “This platform does not support the -daemon flag.”)
On Mac, you launch server like this: “/Applications/Emacs.app/Contents/MacOS/Emacs --daemon”, then client like this: “/Applications/Emacs.app/Contents/MacOS/bin/emacsclient ~”.
(info "(emacs) Emacs Server")
nxml-mode by James Clark.
This is a superb mode for working with XML documents. It validates your XML as you type.
There is a bug in emacs 23.1.50 such that when you open a “.xml” file, the file is opened with the old xml mode the sgm-mode, not nxml-mode. To fix that, put:
; for xml files, use nxml-mode instead of sgml-mode (add-to-list 'auto-mode-alist '("\\.xml\\'" . nxml-mode))
Note that James Clark is one of the world's top expert on SGML and XML, author of the widely used Expat XML parser. The nxml-mode + emacs is probably the world's most advanced xml editor.
(info "(nxml-mode) Top")
“proced” by Roland Winkler, for managing OS processes, similar to dired in managing files.
Start it by “Alt+x proced”.
Emacs 23's proced mode, showing running processes.
You can click on the column at the top to sort by that. In the mode, type “Alt+x describe-mode” to see its inline doc, as usual.
You use it pretty much like dired. Type “m” to mark the process, type “u” to unmark, type “x” to send a signal to the process, and type Tab to see what signal you can send.
Be sure to check the menu “Proced” while you are in proced mode.
Note that this feature does not work on Mac OS X out of the box.
ruby-mode by Yukihiro Matsumoto & Nobuyoshi Nakada.
rst-mode by Martin Blais et al. ReStructuredText is a lightweight markup format, mostly used in Python community for inline documentation of code, pretty much like Perl's pod or Java's Javadoc. rst-mode documentation is at: http://docutils.sourceforge.net/docs/user/emacs.html.
doc-view-mode by Tassilo Horn. This allows you to view PDF documents within emacs, as well as PostScript and DVI files.
This feature does not work on Windows or Mac OS X out of the box.
(info "(emacs) Document View")
EasyPG Assistant (epa) is interface to GNU Privacy Guard (gpg).
The tools can be invoked in the menu “Tools‣Encryption/Decryption”. To see what command are available, type “Alt+x epa-” then “Tab”.
In dired, you can call these function with keyboard shortcuts:
| Shortcut | Purpose |
|---|---|
| :e | Encrypt |
| :s | Sign |
| :v | Verify |
| :d | Decrypt |
These are listed in the menu “Immediate” while in dired.
(info "(epa) Top")
Deleting files in emacs can now be set so that they move to the OS's trash.
; deleting files goes to OS's trash can (setq delete-by-moving-to-trash t) ; “t” for true, “nil” for false
However, this feature has a few problems. When this is on, your system trash will be filled with tens or hundreds of emacs temp files, such as those “#autosave#” files, “backup~” files, “.emacs.desktop”, “emacs00164”, “server”, etc. Also, when deleting a directory from dired, your system trash will end up with each individual files, instead of just a folder. If the folder has few hundred files, the process will be super slow. This happens at least on Windows emacs.
“remember” by John Wiegley. Lets you write down notes quickly. Not sure what's the deal here, or what's the diff just writing to a file.
To start, type “Alt+x remember”. Then type your notes. When done, type “Ctrl+c Ctrl+c”, then it should save the data to “~/.notes” and close the buffer.
(info "(remember) Top")
Support D-BUS, thanks to Michael Albinus. This feature allows emacs to provide and receive services from other apps. (info "(dbus) Top")
Support Xesam spec for desktop search. Thanks to Michael Albinus. If you have desktop search tools installed such as Beagle, Strigi, then you can invoke search by the command xesam-search. You'll need to load it first by “(require 'xesam)”.
Support X11's XEmbed protocol. This means, you can embed emacs in other apps.
Thanks to all the Emacs developers.
“Emacs 23.1 released” (2009-07-29) by Chong Yidong, on emacs-dev mailing list. http://lists.gnu.org/archive/html/emacs-devel/2009-07/msg01526.html
Official Emacs release notes: http://www.gnu.org/software/emacs/NEWS.23.1
Interview with emacs maintainer Chong Yidong and Stefan Monnier, 2009-08-03: Source.
Please post comments & suggestions at: http://xahlee.blogspot.com/2009/08/emacs-23-features.html.
Related essays: