Sunday, December 6, 2009

Emacs Fiddling Stick


1 Introduction

One of the primary reasons for using is emacs is that it gives you the ability to fiddle. If you don't want to fiddle, then you may as well use Vim.

But fiddling can be hard, and if you're just staring out, you have no idea where to begin. It's like you've lost your fiddling stick.

Sort of makes me think of that child's poem that has the line: "my master's lost his fiddling stick and knows not what to do."

Fiddling in emacs starts with learning how to get some of the information that is just waiting for you.

2 Getting Information: keybindings, functions, variables

This is really basic, but if you don't know this no progress can be made towards fiddling with emacs. The true emacs fiddler must know these key strokes cold.

And by the way, getting information about emacs, its functions and variables, key-bindings and everything else is a little like drinking from a fire hydrant. It can be overwhelming, but don't worry. Go at your own pace, get what you need, following what you think is interesting, don't get bogged down. Just learn a little bit at a time. Soon you'll know a lot.

Note: ALL of this information is available to you by typing C-h ?. Here I'm presenting only a bite size amount.

Emacs has a lot of keybindings. A keybinding is emacs speak for the association of a key combination with a Lisp function. Sometimes, it is really helpful to get information about these keybindings. There are four important ways to get documentation about a keybinding:

  1. C-h c KEY: displays the name of the command that KEY is bound to. For example, if you type, C-h k, followed by C-h k, in the minibuffer you'ss see: "C-h c runs the command describe-key-briefly" (without the quotes, of course).
  2. C-h k KEY: sort of like the above, but displays the documentation string (i.e., documentation that is embedded in the Lisp function) of the command as well as it's name, in another window. Try it now. Type C-h k C-h c. You should see:
    C-h c runs the command describe-key-briefly, which is an interactive compiled
    Lisp function.
    
    It is bound to C-h c, <f1> c, <help> c.
    
    (describe-key-briefly &optional key insert untranslated)
    
    Print the name of the function key invokes.  key is a string.
    If insert (the prefix arg) is non-nil, insert the message in the buffer.
    If non-nil, untranslated is a vector of the untranslated events.
    It can also be a number in which case the untranslated events from
    the last key hit are used.
    
    If key is a menu item or a tool-bar button that is disabled, this command
    temporarily enables it to allow getting help on disabled items and buttons.
    
    [back]
    
  3. C-h K KEY: Takes you into the comprehensive Info documentation system and will tell you everything you could possible want or need to know about KEY. Very helpful. As above, try it now. Type C-h K C-h c.
  4. You can get a list of the entire key-to-function bindings by typing C-h b. In this list is displayed the associated function. Clicking on the function will give you the function's documentation string. Here's a sample of the output from C-h b.
    C-@             set-mark-command
    C-a             move-beginning-of-line
    C-b             backward-char
    C-c             mode-specific-command-prefix
    C-d             delete-char
    C-e             move-end-of-line
    C-f             forward-char
    C-g             keyboard-quit
    C-h             help-command
    C-j             newline-and-indent
    C-k             kill-line
    C-l             recenter-top-bottom
    RET             newline
    C-n             next-line
    C-o             open-line
    ...
    ...
    ...
    

And you can also get information about functions and variables that emacs knows about:

  1. C-h f FUNCTION: this displays the documentation for a Lisp function. (Note: if the function is bound to a key sequence, then this is exactly the same as C-h k KEY.)
  2. C-h v VARIABLE: This is the describe variable command.

3 The Motherlode: Info

Typing C-h i takes you into the Info system.

(dir)Top

The Info Directory
******************

The Info Directory is the top-level menu of major Info topics.
Type "d" in Info to return to the Info Directory.  Type "q" to exit Info.
Type "?" for a list of Info commands, or "h" to visit an Info tutorial.
Type "m" to choose a menu item--for instance,
"mEmacs<Return>" visits the Emacs manual.
In Emacs Info, you can click mouse button 2 on a menu item
or cross reference to follow it to its target.
Each menu line that starts with a * is a topic you can select with "m".
Every third topic has a red * to help pick the right number to type.

* Menu:

* Info: (info).                    How to use the documentation browsing system.

Emacs
* Auth-source: (auth).                     The Emacs auth-source library.
* D-Bus: (dbus).                   Using D-Bus in Emacs.
* EasyPG Assistant: (epa).         An Emacs user interface to GNU Privacy Guard.
* Emacs: (emacs).                  The extensible self-documenting text editor.
* Emacs FAQ: (efaq).       Frequently Asked Questions about Emacs.

I have no idea how long it would take you to read all of it. I wouldn't want to try.

4 Conclusion

Congratulations! You have just learned how to get some of the basic information that is available to you in emacs.

No comments:

Post a Comment