Current focus: EndSoftwarePatents.org: wiki, mailing list, news, donate

Portrait photo of Ciaran

GNU Emacs tips

Emacs makes a computer serene - each marvellously accommodating command satisfies. Everyone may attempt creating superior enhancements, making all code super, ergo, most actions complete splendidly.

(I also have a page of useful shell command.)

Menu


Execute one lisp expression in the minibuffer

Simple: M-:

That gives you a prompt (Eval:), then, for example, if you want to see the lisp name of the current major mode (which is stored in the variable major-mode, you type:

(message "%s" major-mode)

And the output appears in the echo area (same place as the minibuffer).

This only lets you execute one expression, so typing in two expressions one after the other won't work, but you can put your two expressions inside another expression, like in this (pointless) example:

(progn (message "%s" major-mode) (message "%s" major-mode))

Relevant manual pages: , , , .

Using variables. Example: print increasing numbers

[M-: (setq x 1)]
[F3]
Ligne numéro [C-u M-: x]
[M-: (setq x (+ x 1))]
[F4]

Relevant manual pages: , , , .

Unbinding a key in a specific mode (unsetting a keybinding)

blah.

Relevant manual pages: , , , .

Aargh! My Gnus inboxes disappeared! What the fuck!?

(Note: I'm not a real Emacs expert, I'm just a poor sod that's had this problem three times and found no web pages to help him, so I'm writing what I know.)

The good news is, you'll get most of your mail back. The bad news is:

First: what happened? You probably accidently hit C-w, which calls gnus-group-kill-region. The region isn't visible in the Gnus Group buffer but it seems to cover the area from the top of the screen to wherever the cursor is ("point"). So C-w gets rid of all those inboxes. (I don't know why anyone thought this deserved a keyboard shortcut.)

Second: how do I undo this? The 'undo' function doesn't work. It'll just tell you that the buffer is read only. What's happened is, you've "unsubscribed" yourself from your inboxes. So you need to resubscribe. The U key (that's capital-u) can be used to resubscribe. You'll see a list of choices, and you just go through the list one-by-one and resubscribe to all your inboxes.

Lastly: to avoid this problem in the future, unbind the C-w key in the Gnus Group keymap. (I'm still working out how to do this...)

Make Gnus safe by unbinding its dangerous keys

Gnus has easily typed keybindings for commands that will ruin your inbox. C-w is a painful example. It runs gnus-group-kill-region which makes most of your inboxes disappear, and 'undo' just gives "Buffer is read-only: #<buffer *Group*>"

Non-greedy highlighting. Example: hiding ref tags while editing Wikipedia

Summary: use highlight-regexp and instead of .* use .*? - that's the non-greedy variant.

Example: Sometimes when I edit Wikipedia, I want to focus on the text without being distracted by the contents of the ref tags. Each paragraph is a single line of text, so if I highlight a regexp like <ref.*</ref> then emacs highlights from the first ref tag to the end of the last ref tag, and everything in between. If instead I highlight <ref.*?</ref> then Emacs highlights just from the first ref tag to the end of that ref tag, and again from the start of the second ref tag to the end of the second ref tag, but the text between the tags is left alone.

Relevant manual pages: , , , .


(top)

List of commands to remember

(top)

External links


(Go: homepage of Ciarán O'Riordan)

Valid XHTML 1.1! Powered by GNU Made with Emacs Join FSF! (I'm member #8)

(I made the Emacs and GNU buttons. Feel free to do with them whatever you like.)

© Copyright 2013 Ciarán O'Riordan. Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved. Distribution of modified versions of all or part of this article are permitted, provided that such works carry three things: (1) this copyright notice, (2) prominent notices stating the that it has been changed, and (3) information for how to obtain the original (such as a URL).