Learning GNU Emacs, Third Edition
- Chapter 1 Emacs Basics
- Chapter 2 Editing
- Chapter 3 Search and Replace
- Chapter 4 Using Buffers, Windows, and Frames
- Chapter 5 Emacs as a Work Environment
- Chapter 6 Writing Macros
- Chapter 7 Simple Text Formatting and Specialized Editing
- Chapter 8 Markup Language Support
- Chapter 9 Computer Language Support
- Chapter 10 Customizing Emacs
- Chapter 11 Emacs Lisp Programming
- Chapter 12 Version Control
- Chapter 13 Platform-Specific Considerations
- Chapter 14 The Help System
Chapter 1 Emacs Basics
- open file:
c-x c-f
- open file replace current buffer:
c-x c-v
- insert from another file:
c-x i
- save file:
c-x c-s
- save file with another name:
c-x c-w
- quit emacs:
c-x c-c
Chapter 2 Editing
Editing Tricks and Shortcuts
- transposition:
c-t
,m-t
,c-x c-t
- change capitalization:
m-c
,m-u
,m-l
- overwrite mode: the
Insert
key orm-x ov
Canceling Commands and Undoing Changes
- redo: after undo, move the cursor, then undo again
- revert a buffer:
m-x revert-buffer
Making Emacs Work the Way You Want
- turn on CUA mode:
(cua-mode t nil (cua-base))
- remap keys:
(define-key global-map "\C-x\C-u" 'undo)
Chapter 3 Search and Replace
Different Kinds of Searches
- search word under cursor:
c-s c-w
Search and Replace
- query-replace:
m-%
during query-replace
y
: replace and go to nextn
: don't replace, go to next.
: replace and quit,
: replace and wait (see the result)!
: replace all^
: back to previousq
: exitE
: modify replacment stringc-r
: enter recursive editc-w
: delete and enter recursive editc-m-c
: exit recursive edit and resume query-replacec-]
: exit recursive edit and edit query-replace
Chapter 4 Using Buffers, Windows, and Frames
More About Windows
- split window vertically:
c-x 2
- split window horizontally:
c-x 3
- delete window:
c-x 0
- delete other window:
c-x 1
- other window:
c-x o
- enlarge window:
c-x ^
- enlarge/shrink window horizontally:
c-x }
/c-x {
- shrink if large than buffer:
c-x -
- balance windows:
c-x +
- scroll other window:
c-m-v
- find file other window:
c-x 4 f
- select buffer other window:
c-x 4 b
- compare windows:
m-x compare-windows
Holding Your Place with Bookmarks
- set bookmark:
c-x r m
- move to a bookmark:
c-x r b
- bookmark list:
c-x r l
Chapter 5 Emacs as a Work Environment
Executing Commands in Shell Buffers
- insert command output:
m-!
- pipe region to shell command:
m-|
Using Dired, the Directory Editor
(too many, check online)
Chapter 6 Writing Macros
- start recording:
<f3>
- end recording or call:
<f4>
- execute last macro:
c-x e
- name last macro:
c-x c-k n
- bind to key:
c-x c-k b
- edit last macro:
c-x c-k <enter>
- apply macro to region:
c-x c-k r
Chapter 7 Simple Text Formatting and Specialized Editing
- literal tab:
c-q <tab>
- change tab width:
(setq-default tab-width 4)
- insert space rather than tab:
(setq-default indent-tabs-mode nil)
- change tabs to spaces (and vice versa):
untabify
andtabify
- new line and indent:
c-j
- munge into one line:
m-q
- indent region: `c-m-‘
- indent by 10 spaces:
m-10 c-x <tab>
- move to first nonblank character:
m-m
- split line:
c-m-o
- set fill prefixes:
c-x .
- centering text:
m-o m-s
- join line to previous:
m-^
Rectangle Editing
- set mark:
c-<space>
- kill:
c-x r k
- delete:
c-x r d
- yank:
c-x r y
- clear (replace with spaces):
c-x r c
- open (fill with spaces):
c-x r o
- change:
c-x r t
Making Simple Drawings
(funny)
Chapter 8 Markup Language Support
Comments
- indent for comment:
m-;
- new comment line and indent (can also use to split comment):
m-j
- comment block of code:
m-x comment-region
(html-mode is not useful anymore, use emmet-mode
instead)
Chapter 9 Computer Language Support
etags
- read tag table:
m-x visit-tags-table
- find tag:
m-.
- back to previous:
m-*
- find tag but open in other window:
c-x 4 .
- continue find tag:
m-,
- search:
m-x tags-search
motion commands
- move to beginning:
m-m
- new line and indent:
c-j
- join line to previous:
m-^
- move to beginning of statement:
m-a
- move to end of statement:
m-e
- move to beginning of defun:
c-m-a
- move to end of defun:
c-m-e
- mark function:
c-m-h
Chapter 10 Customizing Emacs
Customizing Your Key Bindings
c-x
, esc
and c-c
are bound to special internal functions that cause emacs to wait for another key to be pressed.
three functions are available for creating key bindings:
(define-key keymap "keystroke" 'command-name)
(global-set-key "keystroke" 'command-name)
(local-set-key "keystroke" 'command-name)
where keymap can be global-map
, 'ctl-x-map,
esc-map` etc...
; these 3 are same
(global-set-key "\C-xl" 'goto-line)
(define-key global-map "\C-xl" 'goto-line)
(define-key ctl-x-map "l" 'goto-line)
unset key bindings:
(global-unset-key [f5])
(define-key ctl-x-map "l" nil)
Chapter 11 Emacs Lisp Programming
Introduction to Lisp
syntax of function: (function-name argument1 argument2 ...)
Atoms:
- Integers
- Floating point numbers
- Characters: preceded by a question mark:
?a
or\e
or?\C-a
- Strings: surrounded by double quotes, can be split across multiple lines, until the closing quote.
- Booleans:
t
for true andnil
for false - Symbols: use when refer to the name instead of its value. preceding with single quote:
'function-name
assign values to variable, use setq
:
(setq auto-save-interval 800)
let
construct:
(let ((var1 value1) (var2 value2) ... )
statement-block)
while
loop
(while condition statement-block)
sample
(defun count-words-buffer ()
"Count the number of words in the current buffer;
print a message in the minibuffer with the result."
(interactive)
(save-excursion
(let ((count 0))
(goto-char (point-min))
(while (< (point) (point-max))
(forward-word 1)
(setq count (1+ count)))
(message "buffer contains %d words." count))))
Lisp Primitive Functions
statement block
(progn
statement-block)
(let (var1 var2 ...)
statement-block)
(let (var1 (var2 value2) var3 ...)
statement-block)
control structures
(if condition
true-case
false-block)
(cond
(condition1 statement-block1)
(condition2 statement-block2)
...)
Lists
(list 2 3 4 5)
(cons 1 (list 2 3 4 5))
(car (list 1 2 3 4 5)) ; 1
(cdr (list 1 2 3 4 5)) ; (2 3 4 5)
lambda
(lambda (args)
code)
(setq var-name
'(lambda ()
code))
mode hook
(setq mode-name-hook
'(lambda ()
code for mode hook))
set load-path
(setq load-path (append load-path (list "some directory"))) ; all arguments to append must be lists
if you want your code to be searched first, use cons
(setq load-path (cons "some directory" load-path))
to load file, m-x load-library
or:
(load "package-name")
autoload
(autoload 'function "filename")
Chapter 12 Version Control
(use magit
instead, much better)
Chapter 13 Platform-Specific Considerations
(no notes)
Chapter 14 The Help System
(no notes)
[END]