.comment-link {margin-left:.6em;}

sticky scratch

Wednesday, October 27, 2004

emacs guide

Emacs tips (using keyboard)
======================

BEFORE USE:
This tips are labeled based on the most known conventions which doesn't mean they are the chosen ones by emacs developers.
It's important to know that this are just some of the default most useful bindings for me. Emacs is much more than that.

NOTATION (taken from 2.3.1 Command Keys (Meta, Esc, Control, and Alt) in http://rootprompt.org/article.php3?article=359):
As you'll soon learn, Emacs makes heavy use of multi-key combinations. Because it is not a modal editor like vi, you don't have to think about being in ``command mode'' or ``editing mode'' before you can try to move the cursor or execute a command. Instead, you just press the right combination of keys and Emacs does as told (usually).

The keys that Emacs makes the most use of are usually abbreviated in the documentation as C (for Control or Ctrl) and M for (Meta). While most modern PC keyboards have one or more keys labeled Ctrl few have one labeled Meta. You'll want to mentally substitute either Esc or Alt for the Meta key. In most standard configurations, both Esc and Alt do essentially the same thing. So when you see a reference in any Emacs related documentation to C-x f it means ``press control-x and then f.'' And if you see a reference to something like M-x shell is means ``press alt-x and type the word shell''.


Running emacs:
bash $ emacs

Running emacs with opened file:
bash $ emacs filename

Inside emacs....
Opening file (aka Find File):
C-x-f

Saving buffer (file):
C-x-s

Saving buffer as (file as):
C-x-w

List buffers:
C-x-b

Switch buffer:
C-x b

Quit buffer:
C-x-k

Quit emacs:
C-x-c

Show menu:
F10

Execute Emacs function (explicitly):
M-x function

Describe Emacs function:
C-h f

Describe Emacs variable:
C-h v

Describe Emacs bindings:
C-h b

Describe Emacs key:
C-h k

Get Emacs tutorial:
C-h t

Get Info:
C-h i

Get Help:
C-h

Get Detailed Help:
C-h ?

Dismiss current operation (when emacs hangs):
C-g

Select Region (cursor position defines its end):
C-@ or C-SPC

Select all:

C-x h

Watch selected Region:
C-x-x

Go to line:
M-x goto-line

Go to end of the current line:
C-e

Go to the beginning of the current line:
C-a

Go to the beginning of the buffer (file):
M-<

Go to the end of the buffer (file):
M->

Indent line:
TAB

Indent Region:
C-M-\ or M-x indent-region

Cut from current cursor position until end of line:
C-k

Cut from current cursor position until end of sequence (including possible newlines):
M-k

Cut region:
C-w

Paste (aka Yank):
C-y

Incremental Search forward (repeat command for next match):
C-s

Incremental Search backward (repeat command for next match):
C-r

Unconditional Replace String:
M-x replace-string <ret> STRING <ret> NEWSTRING <ret>


Unconditional Replace Regular Expression:
M-x replace-regexp <ret> REGEXP <ret> NEWSTRING <ret>

Query Replace String:
M-% STRING <ret> NEWSTRING <ret><ret> or
M-x query-replace <ret> STRING <ret> NEWSTRING <ret>


Query Replace Regular Expression:
C-M-% REGEXP <ret> NEWSTRING <ret>
or
M-x query-replace-regexp <ret> REGEXP <ret> NEWSTRING <ret>

Undo:
C-x u or C-_

Split Windows:
C-x-2

Delete other windows except current one:
C-x-1

Close current Window:
C-x-0

Switch between Windows:
C-x o

Compile:
M-x compile
for erros do: C-x ` (reverse quote)

Debug:
M-x debug

Shell mode:
M-x shell

Find the differences between two files:
M-x ediff

Debug emacs itself:
M-x toggle-debug-on-error

Defining Macros:
C-x ( MACRO C-x )
replace MACRO with the combination of commands you wish to execute.

Run the last keyboard macro defined:
C-x e

Inside the .emacs file (taken from http://www.haifux.org/lectures/64/emacslec.html):
the .emacs file contains lisp code which is executed every time
you run emacs, on startup.

In the .emacs file we will put macro definitions,
variable customizations, key bindings, adding hooks
and actually any lisp code you want.

bind keys:
(global-set-key "\COMMAND" 'function)

unbind keys:
(global-unset-key "\COMMAND" 'function)

using etags:
To use etags you have you to run in the first place:
bash $ etags files
(to generate TAGS file)


See definition of any global symbol of interest (C-u M-. to find next match):
M-.

KNOW MORE (other tools and projects):
Emacs power remains mainly on its versatibility. You can easily plug in other tools and make it provide all those features you need since mail client until tetris (yes, the game!).

One of those tools is "speedbar". Speedbar is an Emacs Lisp program which allows you to create a special skinny frame with a specialized directory listing in it. This listing will have both directories and filtered files in it. You can then load files into your emacs frame, or expand the files to display all the tags that are in them and jump to those tags. You can also expand multiple directories into your speedbar frame (taken from http://cedet.sourceforge.net/speedbar.shtml).

If you code in Java other useful tool is JDE.
The Java Development Environment for Emacs is a software package that interfaces Emacs to command-line Java development tools (for example, JavaSoft's JDK) (taken from http://jdee.sunsite.dk/).

Other project is XEmacs which is a highly customizable open source text editor and application development system with modern graphical user interface support and an open software development model, similar to Linux.

To know more about other tools read the info that comes with emacs.

REFERENCES:
http://www.gnu.org/software/emacs/emacs.html
http://www.emacs.org
http://www.emacswiki.org/
http://www.lib.uchicago.edu/keith/tcl-course/emacs-tutorial.html
http://rootprompt.org/article.php3?article=359
http://www.haifux.org/lectures/64/emacslec.html
http://cedet.sourceforge.net/speedbar.shtml
http://jdee.sunsite.dk/
http://www.dotemacs.de/ (unofficial .emacs home)
http://www-h.eng.cam.ac.uk/help/tpl/emacs/node24.html (example .emacs file)
http://www.linuxjournal.com/article.php?sid=0153
http://www.xemacs.org


ABOUT:
this is a scratch written by Francisco Gama using many quotes from the references that gathers what i consider of most interest using what i consider the most powerful editor tool. This little guide is not finished since i intend to update it regularly with my new knowledge about this great tool. I plan on improving information about macros,debug and .emacs files.
Meanwhile, Good work!

0 Comments:

Post a Comment

<< Home