describe-key and apropos

Emacs is often described as a self-documenting text editor. Part of that is because of the superb manuals that are built-in but another part is that you can ask the editor to describe itself using C-h k (describe key) and M-x apropos.

describe-key tells you which function is invoked when you press a certain key chord. For example, I wanted to know what C-h k invoked so I pressed C-h k C-h k. Whilst writing a script I needed to know which function positions the cursor at the beginning of the line. C-h k C-a gives the answer – (move-beginning-of-line arg). Okay, so that is useful, but what if you are looking for a command that isn’t bound to a key combination. That is where apropos comes in.

apropos enables you to list all the functions in emacs that match a regular expression. For example, say you are not sure which function returns the current time. You might try M-x apropos time$<RET> and search through the list of functions that are returned or perhaps M-x apropos current.*time which quickly points you at (current-time). However, current-time returns a list of three integer values which isn’t very useful. Maybe you can convert it into an integer?

M-x apropos integer<RET>
C-s (isearch-forward) time - no matches

Maybe not… How about a float?

M-x apropos float<RET>
C-s time

Both of the following look to be suitable for my purposes. Of course, your purposes may be different!

(float-time (current-time))

Right, that is quite enough about time. How about a search for all the hooks?

M-x apropos hook$

This returns 155 hooks in my emacs. One interesting hook is post-command-hook which runs after every command. I will be using that in a later post.

Right, that should have given you an idea of how to search for the functions you need.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: