emacstips
 
---------------------------
EMACS
---------------------------

uppercase

to upcase words, place yourself at the first letter of the word, and type M-u.

--------------------------------------------------------------------------------
UNIX - DOS - MAC
--------------------------------------------------------------------------------

You can direct Emacs to save a buffer in a specified EOL format with
the C-x <RET> f command.

For example, to save a buffer with Unix EOL format, type C-x <RET> f
unix <RET> C-x C-s.
--------------------------------------------------------------------------------


--------------------------------------------------------------------------------
FIND-DIRED
--------------------------------------------------------------------------------
Running find inside emacs:

M-x find-dired RET
specify the directory RET
specify the command:
-name "myfile.*" RET
--------------------------------------------------------------------------------


--------------------------------------------------------------------------------
DIFF-MODE PATCHING
--------------------------------------------------------------------------------
Put the cursor at the beginning of a hunk:

p diff-hunk-prev
n diff-hunk-next

and then test or apply the hunk:

C-c C-a diff-apply-hunk
C-c C-t diff-test-hunk

For more info: C-h m and C-h b
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
DELETE ALL LINES CONTAINING A STRING
--------------------------------------------------------------------------------
What could be more obvious than `M-x delete-matching-lines'?

Since vim/vi users love the sed syntax, you can always run sed on your
Emacs buffer like this:

C-x h ; mark-whole-buffer
C-u M-| ; [replace region with output from] shell-command-on-region
sed '...' RET ; e.g. /notice/d
--------------------------------------------------------------------------------



--------------------------------------------------------------------------------
PRINTING COLOURED CODE TO A POSTSCRIPT FILE
--------------------------------------------------------------------------------
C-u M-x ps-print-buffer-with-faces

then specify the name and place where you want to save the file.ps
--------------------------------------------------------------------------------


----------------------------------------------------------------------------------
SEARCH FOR THIS WORD
----------------------------------------------------------------------------------
Put cursor at the beggining of the word you want to search, then:
C-s for activating search
C-w for select word (do it as many times as you need)
then again
C-s for search that word in the file
----------------------------------------------------------------------------------



--------------------------------------------------------------------------------
RECTANGLES IN REGISTERS
--------------------------------------------------------------------------------
A register can contain a rectangle instead of linear text. The
rectangle is represented as a list of strings. *Note Rectangles::, for
basic information on how to specify a rectangle in the buffer.

`C-x r r R'
Copy the region-rectangle into register R
(`copy-rectangle-to-register'). With numeric argument, delete it
as well.

`C-x r i R'
Insert the rectangle stored in register R (if it contains a
rectangle) (`insert-register').

The `C-x r i R' command inserts a text string if the register
contains one, and inserts a rectangle if the register contains one.

See also the command `sort-columns', which you can think of as
sorting a rectangle. *Note Sorting::.
--------------------------------------------------------------------------------


---------------------------
USING EMACS
---------------------------

-------------
FILE HANDLING
-------------

M-x set-visited-file-name

Change the file name under which the current buffer will be saved.

----------------------
BASIC EDITING COMMANDS
----------------------

Display the current column number:

M-x column-number-mode

M-x toggle-truncate-line

C-j Insert one or more blank lines as a normal "Ret" hit.

C-o Insert one or more blank lines after the cursor (open-fine).

C-x C-o Delete all but one of many consecutive blank lines
(delete-blank-lines).

--------------------------------------------------------------------------------
Editing directory listings with C-x d
--------------------------------------------------------------------------------
When dired is invoked, usually by typing C-x d, it asks for the name
of a directory, and then shows the contents of that directory.

Immediate commands:

# C (dired-do-copy) --
# D (dired-do-delete) --
# G (dired-do-chgrp) --
# M (dired-do-chmod) --
# O (dired-do-chown) --
# P (dired-do-print) --
# R (dired-do-rename) --
# X (dired-do-shell-command) -- prompts for and runs a shell command
on the specified file(s).
# Z (dired-do-compress) --

Create directory... (+)
Refresh (g)
--------------------------------------------------------------------------------


--------------------------------------------------------------------------------
RECTANGLES
--------------------------------------------------------------------------------
`C-x r k'
Kill the text of the region-rectangle, saving its contents as the
"last killed rectangle" (`kill-rectangle').

`C-x r d'
Delete the text of the region-rectangle (`delete-rectangle').

`C-x r y'
Yank the last killed rectangle with its upper left corner at point
(`yank-rectangle').

`C-x r o'
Insert blank space to fill the space of the region-rectangle
(`open-rectangle'). This pushes the previous contents of the
region-rectangle rightward.

`M-x clear-rectangle'
Clear the region-rectangle by replacing its contents with spaces.

`M-x delete-whitespace-rectangle'
Delete whitespace in each of the lines on the specified rectangle,
starting from the left edge column of the rectangle.

`C-x r t STRING '
Replace rectangle contents with STRING on each line.
(`string-rectangle').

`M-x string-insert-rectangle STRING '
Insert STRING on each line of the rectangle.
--------------------------------------------------------------------------------


--------------------------------------------------------------------------------
transpose
--------------------------------------------------------------------------------
`C-t'
Transpose two characters (`transpose-chars').

`M-t'
Transpose two words (`transpose-words').

`C-M-t'
Transpose two balanced expressions (`transpose-sexps').

`C-x C-t'
Transpose two lines (`transpose-lines').
--------------------------------------------------------------------------------


----------------------------------------------------------------------
BOOKMARKS
----------------------------------------------------------------------
C-x r m RET
Set the bookmark for the visited file, at point.
C-x r m bookmark RET
Set the bookmark named bookmark at point (bookmark-set).
C-x r b bookmark RET
Jump to the bookmark named bookmark (bookmark-jump).
C-x r l
List all bookmarks (list-bookmarks).
M-x bookmark-save
Save all the current bookmark values in the default bookmark file.
----------------------------------------------------------------------


--------------------------------------------------------------------------------
FIND-GREP-DIRED
--------------------------------------------------------------------------------
to find-grep in a specific directory:

M-x find-grep-dired

then you are asked for the directory and the regex.
--------------------------------------------------------------------------------


--------------------------------------------------------------------------------
CPERL-MODE
--------------------------------------------------------------------------------
To cause cperl-mode to be preferred to perl-mode in Emacs (21.2.1), edit .emacs:

(defun modify-alist (alist-symbol key value &optional search-cdr)
(let ((alist (symbol-value alist-symbol)))
(while alist
(if (eq (if search-cdr
(cdr (car alist))
(car (car alist))) key)
(setcdr (car alist) value)
(setq alist (cdr alist))))))

(modify-alist 'interpreter-mode-alist 'perl-mode 'cperl-mode t)
(modify-alist 'auto-mode-alist 'perl-mode 'cperl-mode t)

--------------------------------------------------------------------------------


The following commands are useful for viewing screenfuls:
C-v Move forward one screenful
M-v Move backward one screenful
C-l Clear screen and redisplay all the text,
moving the text around the cursor
to the center of the screen.
(That's CONTROL-L, not CONTROL-1.)

Repeatedly do something:
C-u *number* *something* Do *something* a *number* of times

Replace-string:
M-x replace-string *ret* from *ret* to

Searching an replacing:
 meta-%
 Use 'y' to confirm, 'n' to leave the same
The most basic HELP feature is:
C-h c *cmd or seq* Type C-h, the character c, and
a command character or sequence;
then Emacs displays a very brief
description of the command.

C-h k *cmd or seq* This displays the documentation of
the function, as well as its name,
in an Emacs window.

C-h f *cmd or seq* This displays all the information
Emacs has about the function

C-h a *keyword* Command Apropos. Type in a keyword
and Emacs will list all the commands
whose names contain that keyword.

C-h i Read On-line Manuals (a.k.a. Info). This command puts
you into a special buffer called `*info*' where you
can read on-line manuals for the packages installed on
your system. Type m emacs *Return* to read the Emacs
manual. If you have never before used Info, type ?
and Emacs will take you on a guided tour of Info mode
facilities. Once you are through with this tutorial,
you should consult the Emacs Info manual as your
primary documentation.




--------------------------------------------------------------------------------
SELECTIVE DISPLAY

Emacs has the ability to hide lines indented more than a certain number of columns
(you specify how many columns). You can use this to get an overview of a part of
a program.

To hide lines, type `C-x $' (`set-selective-display') with a numeric argument N.

example: C-n 3 C-x $

To make all lines visible again, type `C-x $' with no argument.

example: C-x $

If you set the variable `selective-display-ellipses' to `nil', the three dots do
not appear

--------------------------------------------------------------------------------


----------------------------------------------------------------------------------
SHOW-PAREN-MODE
----------------------------------------------------------------------------------
This mode turns off the usual kind of matching parenthesis display and instead
uses highlighting to show what matches. Whenever point is after a close
parenthesis, the close parenthesis and its matching open parenthesis are both
highlighted; otherwise, if point is before an open parenthesis, the matching close
parenthesis is highlighted. (There is no need to highlight the open parenthesis
after point because the cursor appears on top of that character.) Use the command

M-x show-paren-mode

to enable or disable this mode.
----------------------------------------------------------------------------------


----------------------------------------------------------------------------------
Tags
----------------------------------------------------------------------------------
* Used to locate functions, structures, typedefs, classes, macros, etc.
* An external program is used to index source code
* Index file is named TAGS by tradition
* At least two tags programs are available:
o etags (comes with emacs)
o ctags-exuberant (a improved version, may not be installed on your system.)
* To index, use: etags *.h *.c
* To locate a tag, just do M-. and enter the name of the tag to locate
* Emacs is smart enough to use the text under the cursor as a default
* If the tag is defined in multiple locations, M-1 M-. will locate the next occurance.
* M-x tags-search can be used to search for arbitrary text within all the files
 mentioned in the tag file. 
----------------------------------------------------------------------------------


----------------------------------------------------------------------------------
SPECIFYING C MODE IN THE FILE
----------------------------------------------------------------------------------
Can be configured on a per-file basis with magic first line:

/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
----------------------------------------------------------------------------------

CVS DIFFING
M-x ediff-revision 
You will then be prompted for the file and which versions you want to compare:
eg: 1.119 and 1.118 

Basic cvs management:
`Need-Merge'
File is changed both in the repository and in the working directory.
`<O> Update'
Merge the repository version into the working copy. If the merge is successful, the status will change to Modified, with a sub-status of “merged”. If the merge is not successful, the status will change to Conflict.
`<d H> ediff Head'
Use ediff to review the differences with the CVS Head revision, before merging into the working copy.

`Modified'

A changed file in the working directory.
`<c> ediff and commit'
Review differences, collect a change comment, commit the file to the repository.
`<U> Undo'
Delete the working copy, replace it with the repository copy. Do this if you decide your changes are not correct.

<l> brings up the CVS log for the current file in another window; useful for seeing the check-in comments. 

==================

Dictionaries and thesaurus

sudo apt-get install dictem