You are on page 1of 17

EMACS

1. Basics 1. "set" assigns a value to a symbol


2. (set 'fname "Mitch")

Since quoting the symbol name is so common a second assignment operator was created, "setq" 3. "setq" sets the value of a variable,
4. (setq fname "Mitch")

but can take multiple arguments,


(setq varname value [varname value]...) (setq fname "Mitch" lname "Fincher")

It returns the last value set. 2. ";" is the comment character


3. ; I'm a comment 4. (setq fname "Mitch") ; and so am i

5. List operators A List is a sequence of zero or more lisp expressions enclosed in parens. Function Description Example car returns the first element of the list (car '(a b c d)) => a returns the list without the first (cdr '(a b c d)) => (b c d) cdr element list cons makes a list from its arguments
(list 'a 'x "asdf" 6) => (list a x "asdf" 6)

append reverse length nthcdr nth mapcar apply setcar

prepends its first argument to its (cons '(a b) '(c d)) => ((a b) c d) second strips the outer parens from its args (append '(a b) '(c d (e))) => (a b and then c d (e)) munges all of them into a single list reverses a list's top level elements c b a)
(setq x '(a b c d))(reverse x) => (d

returns number of top level list (length '(a b c (e f))) => 4 elements (nthcdr 2 '(a b c d e)) => (c d e) returns the 'nth' cdr (nth 2 '(a b c d e)) => c returns the nth element of a list given a function and a list, it calls (mapcar 'length '((a)(a b)(a b c))) the function on each element of the => (1 2 3) list
(apply 'max '( 3 6 1))> 6

sets the value of the car in a cons cell

(setq a (cons 'x 'y))

=> (x . y)

(setcar a 'w)

=>(w . y) => (x . y)

(setq a (cons 'x 'y))

setcdr sort

sets the value of the cdr in a cons cell sorts a list

(setcdr a 'w)

=>(x . w)

(sort '(5 3 9 27) '<) => (3 5 9 27)

Note on characters: Characters are represented by prefacing them with "?". ?a denotes the character a. Characters can also be represented by their ascii integer value. 6. String functions Function

Description Example compares two strings for (string= s1 s2) (string= "asdf" "asdf")=> t equality (stringp x) tests if arg is a string (stringp 3) => nil (concat "I " "went to " "the woods ")=> "I (concat a b [c...]) concats its args together went to the woods " (length s) returns the length of s (length "I went to the woods ")=> 20 returns the ith char (0 (aref s i) (aref "abcd" 2)=> 99 based) (aset s i ch) sets the nth char (aset "run" 1 ?a) => (substring s from (substring "Gaul is" 0 4) => "Gaul" [to]) 7. List background. Lists are composed of smallers units called 'cons cells'. A cons cell has two parts, a 'car' and a 'cdr'. Lists are made by having data in the 'car' part and the 'cdr' part pointing to another cons cell. The last cdr of a proper list is nil. 8. Data Types 1. Integer 2. Floating Point 3. Character 4. Symbol 5. Sequences: 1. List 2. Array 6. String 7. Vector 9. Arithmetic Function Description Example + addition (+ 1 2 3 4) => 10 subtraction (- 10 1 2 3) => 4 max returns largest of arguments (max 14 99 18 44 ) => 99 min returns smallest of arguments (min 14 99 18 44 ) => 14 / division (/ 16 2)=> 8 * multiplication (* 4 2 3) => 24

% modulo (remainder) 10. Logical functions (and, or, not, eq) Function or = /= >,<.>=,<= numberp vectorp consp atom listp null bolp eolp bobp eobp
11. 12. 13. 14.

(% 5 2)=> 1

Description evaluates args in order and returns first true one tests if two numbers are equal tests if two numbers are not equal kinda what you would think Is argument a number? Is argument a vector? tests if its argument is a cons cell tests if its argument is an atom tests if its arg is a list true for cons cells and nil tests if its argument is nil is point at the beggining of a line is point at the end of a line is point at the beggining of a buffer is point at the end of a buffer

Example
(or nil 5) => 5 (= 1 2) => nil (= 1 2) => nil (< 1 2) => t (numberp 5)=> t (vectorp 5)=> nil (consp '(a b)) => t

(consp "asdf") => nil


(atom '(a b)) => nil

(atom "asdf") => t


(listp '(a b)) => t

(listp nil) => t


(null nil) => t

(null 7) => nil

=>
(setq a nil) (setq b "mike") (setq c "jeremiah") (and b c ) ;; if all are true, it returns the last true value = "jeremiah" 15. (and b a c ) ;; = nil

16. eq takes two args and tests if they are the same object (eq 23 23) => t 17. equal takes two args and tests if the values are equal
18. (if (equal "Monday" (format-time-string "%A" (current-time))) (insert "- timesheet\n"))

19. Conversion number-to-string string-to-number char-to-string int-to-string 20. Condition structures 1. if statement
2. (if test 3. then 4. else1, else2,...)

If test is true the then clause executes. If test is false all the else clauses execute. Example:
(setq testme nil) (if testme (setq a "1") (setq a "3") (setq a "2") ) (message a)

when testme is nil, the value of a is "2". When testme is true a is "1" Note: "if" returns the value of the last expression executed. 5. cond cond returns the first true condition
(setq home-dir-emacs (cond ((string= emacs-version "22.1.1") "c:/opt/gnu/emacs-22.1/") ((string= emacs-version "21.3.1") "c:/opt/gnu/emacs-21.3/") ))

21. Function Template

22. (defun function-name ([arg1 ... argN]) 23. "optional, but encouraged documentation". 24. (interactive cryptic-argument-passing-codes) 25. body...)

any arg with a type embedded in the name (ie, integer1) is assumed to be of that type. 26. Errors
27. 28. 29. 30. 31. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. (defun errortest() (if nil (error "something is wrong in errortest") (message "everything is peachy")) ) (add-hook 'find-file-hooks 'display-file-info) (add-hook 'java-mode-hook '(lambda () (turn-on-font-lock) (modify-syntax-entry ?_ "w") ;asdf_asdf (modify-syntax-entry ?- "w") ;asdf-asdf (c-toggle-auto-state t) (c-toggle-auto-hungry-state t) (define-key c-mode-map "\ea" nil) ;; use global value (define-key c-mode-map "\el" nil) ;; use global value )) ;; to remove the hook (remove-hook 'find-file-hooks 'display-file-info)

32. Hooks

Commands and functions can also have hooks. These are created using "defadvice". 46. let

creates a temporary space for vars.


(setq a "apple") (let ((b (a (message (message "banana") "avacado")) a)(sit-for 1)) a)

This will display "avacado" and then "apple" uninitialized variables may also be used.
(let ((b "banana") (a "avacado") c d)

This creates temporary variables "c" and "d", but assigns no value. 47. let* ;; forces sequential execution 48. The yes-or-no-p function
49. 50. 51. 52. 53. (defun nice-day-p () (if (yes-or-no-p (format "Did you have a good day?")) (message "great") (message "sorry"))) (nice-day-p)

54. defvar syntax (defvar varname defaultvalue "documentation string") defvar is like setq, but offers some advantages like a description and the defaultvalue is set only if the varname is undefined. if the documentation string begins with a "*", the variable is user definable with the Mxset-variable command 55. Window Positioning functions 1. (point) This is the number of characters into the buffer we are. (point) returns the value. 2. (window-start) returns the position of the character in the upper left corner. 3. (goto-char n) takes cursor to the nth character in the buffer 4. (set-window-start nil n) ;;sets the window start of the current buffer to n. 56. Useful, but hard to remember misc key sequences and commands:

57. nxml-mode is a more powerful xml-mode. To use by default: 58. (add-to-list 'auto-mode-alist '("\\.xml\\'" . nxml-mode)) 59. when deleted a file goes to the OS's trash folder: 60. (setq delete-by-moving-to-trash t) 61. (setq mouse-wheel-scroll-amount '(1)) ;; set the mouse scroll wheel to move 1 line per event 62. (setq fill-column 72) ;; set the wrap margin column 63. (setcdr (nthcdr (1- (length my-list)) my-list) nil) ;; kill last item in list 64. C-u - M-xfont-lock-modeRET ;; turns off any mode (font-lock-mode is example) 65. C-u 1 M-xfont-lock-modeRET ;; turns on any mode 66. describe-mode ;; tells all about the current minor and major modes

67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86.

copy-to-buffer ;; copies current region to a file M-xedit-options ;; to see all the user definable variables - way cool C-Xb *ftp[TAB] ;;; to get to the ftp buffer C-XC-E eval-last-sexp in a lisp buffer C-y then M-y ;;; to go thru the yank ring In keyboard macros, if you need to copy part of a block of text and then paste it later, you can you something like, ;; move forward through the file set-mark-command ;; set the mark to be used as the beginning of region copy-region-as-kill ;;; copies the text into the clipboard ;; move to where the text is needed clipboard-yank ;; pastes the text into your buffer occur ;; shows all lines in a buffer matching a regular expression (message "howdy") (sit-for 1) ;; shows a message and waits (redisplay) ;;forces redisplay, same as (sit-for 0) (setq debug-on-error t) ;; goes into debug mode on errors (setq debug-on-quit t) ;; goes into debug mode when C-g is entered ; (buffer-string beg end) ;; returns the text within the two positions (buffer-substring (point) (mark)) ;; returns a string given two positions 87. (setq mytext (replace-regexp-in-string "\\(public\\|private\\| protected) " "\\1 " mytext)) ;;wrap html span tags around some keywords 88. 89. cool functions 90. where-is func_name;; shows all the keys bound to the function 91. list-colors-display shows all the available colors. 92. font-lock-face-attributes contains all the current colors 93. set-fill-prefix ;; takes the text *on the current line* and makes it 94. the automatic start of any wrapped lines. you need to be in 95. fill-mode. 96. kill-rectangle ;; deletes the rectangle defined in the highlighted region 97. (ok its really between point and mark 98. yank-rectangle ;; inserts the rectangular text back into the buffer. 99. clear-rectangle ;; replaces all the text in the rectangle with spaces. 100. open-rectangle ;; inserts spaces in the defined rectangle. 101. indented-text-mode ;; special mode to created automatically indented paragraphs 102. edit-picture ;; special mode to do ascii art stuff; exit with C-cC-c 103. ;; C-c^ text goes up 104. ;; C-c. text goes down C-c< left C-c> right 105. 106. 107. 108. C-c` C-^ C-c' 109. ` | ' 110. ` | ' 111. ` | ' 112. `|' 113. C-c< -----------\----------- C-c> 114. /|\ 115. / | \ 116. / | \ 117. / | \ 118. / | \ 119. C-c/ C-c. C-c\ 120. 121. 122. 123. dired mode; 124. D marks a file for deletion 125. x deletes the ones marked 126. g refreshes the buffer 127.

128.

Insert Random Number into a file

Use with a temp macro to stuff random values into a file


(defun randomizer() (interactive)(insert (format "%010d" (random 10000000000))) )

129.

Symbol Properties.

Each symbol has an associated Property list that can be used as an associative array. The get and put function access them
(setq automobile "Mitchs") (put 'automobile 'year "1994") (put 'automobile 'make "nissan") (message (concat automobile " car is a " (get 'automobile 'year) " " (get 'automobile 'make) ) ) => Mitchs car is a 1994 nissan

Nil is returned when using "get" on a symbol that does not have a binding for the requested property. 130. Quotes and Backquotes

Quotes delay evaluation


(set x '(a b)) ;; sets x to a two item list (set x (a b)) ;; sets x to the result of calling function a with argument b

Backquote does something simaliarly, but items prefaced with a comma in the list may be evaluated 131. Control Structures 1. while - looping (always returns nil)
2. 3. 4. 5. 6.

(setq i 0) (while (< i 10) ;; do somthing interesting here (setq i (1+ i)) )

132.

reduce

reduce takes a function which takes two arguments and applies it successively to a list. In this example we use '+' to sum all the elements of a list. ((((+ 1 (+ 2)) (+ 3))(+ 4))(+ 5))
(reduce '+ '(1 2 3 4 5)) => 15 ; equivalent to: (+ 1 (+ 2 (+ 3 (+ 4 (+ 5)))))

Another reduce example which creates a regular expression substring based on a list of keywords

(setq keywords (list "public" "private" "protected" "using" "internal" "static" "this" "return" "namespace" "new" "class" "var" )) (setq regex-keywords (reduce '(lambda(x y) (concat x " \\|" y)) keywords)) ==> "public \\|private \\|protected \\|using \\|internal \\|static \\|this \\|return \\|namespace \\|new \\|class \\|var"

133. Macro Functions These are like regular functions, but do not evaluate their arguments
134. 135. 136. 137. 138. 139. (defmacro dec (var) "decrements a variable" (list 'setq var (list '- var 1))) (setq x 4) (dec x) (message (format "%d" x))

this prints "3" 140. misc 1. defunst defunst works like defun but "inlines" the function. Works like "Inline" in C++. 2. progn aggregates a series of expressions into a single one and returns the value of the last one.
(progn expr1 [expr2...]) (progn (setq a "fish")(setq b "fowl")) => "fowl"

3. prog1 Use prog1 to return the value of the first expression


4. (prog1 (setq a "fish")(setq b "fowl")) => "fish" 5.

141. interactive Letter Action as the first character in the interactive line of a function * implies that it can be run only in buffers with write permission User Input n N s b B e f F S r a number a number, unless a invoked with a prefix argument string name of existing buffer name of non-existing buffer event name of existing file name of new file Symbol Environmental the hilighted region

Example

(interactive "nNumber of Rows:") (interactive "sYour name:")

defun myfunc (begin end) (interactive "r")

142. Code %s %c %d %e %f %g 143.

format Meaning String Character Integer Exponental Floating point Shortest of %f or %e example:

144. (message "%s is brought to you by the number %d and the letter %c" 145. "This message" 7 ?q)

146. Help KeyStroke

Result Give a substring, and see a list of commands (functions C-h a command-apropos interactively callable) that contain that substring. See also the apropos command. C-h b describe-bindings Display table of all key bindings. C-h f describe-function Type a function name and get documentation of it. Info-goto-emacsType a function name; it takes you to the Info node for C-h C-f command-node that command. C-h F view-emacs-FAQ Shows emacs frequently asked questions file. C-h i info The info documentation reader. Type a command key sequence; it displays the full C-h k describe-key documentation. Info-goto-emacsType a command key sequence; it takes you to the Info C-h C-k key-command-node node for the command bound to that key. C-h l view-lossage Shows last 100 characters you typed. Print documentation of current major mode, which C-h m describe-mode describes the commands peculiar to it. C-h s describe-syntax Display contents of syntax table, plus explanations Type name of a variable; it displays the variable's C-h v describe-variable documentation and value. Type command name; it prints which keystrokes invoke C-h w where-is that command. 147. Vectors Vectors are similar to lists, but have a fixed size and elements can be accessed directly.
(setq a 1 b 2 c 4) (vector a b c) => [1 2 4] (make-vector 6 "ab") => ["ab" "ab" "ab" "ab" "ab" "ab"] ;; makes a vector with 6 elements with the default value of "ab" (aset myvector 4 "cd") ;; sets the fourth element to cd. (aref myvector 3) ;; gets the third element (vectors are zero based) (setq myvector (make-vector 6 "ab")) (message "%s" myvector) ;; shows the vector

Command

(length myvector) ;; returns the number of elements

148.

Some of my favorite functions

149. ;; this shows the use of markers. 150. (defun simple-html-create-href () 151. "given a bare url, this creates the href for it. If www.fincher.org is highlighted, then this will produce &lt;a href=\"www.fincher.org\"&gt;www.fincher.org" 152. (interactive "*") 153. (setq simple-html-start-marker (make-marker)) 154. (setq simple-html-end-marker (make-marker)) 155. (set-marker simple-html-start-marker (mark)) 156. (set-marker simple-html-end-marker (point)) 157. (copy-region-as-kill (mark) (point)) 158. (goto-char simple-html-start-marker) 159. (insert "<a href=\"") 160. (goto-char simple-html-end-marker) 161. (insert "\">") 162. (clipboard-yank) 163. (insert "</a>") 164. ) 165. 166. (defun simple-html-insert-table (nrows ncols) 167. "inserts a table template -mdf" 168. (interactive "nNumber of Rows: \nnNumber of Columns: ") 169. (beginning-of-line) 170. (insert "<table border=2>\n") 171. (setq i -1);; -1 instead of 0, since the header row takes up one loop 172. (while (< i nrows) ;; loop over the rows 173. (insert "<tr>") 174. (setq j 0) 175. (while (< j ncols) ;; loop over the cols 176. (if (eq i -1) 177. (insert "<th> </th>") 178. (insert "<td> </td>") 179. ) 180. (setq j (1+ j)) 181. ) 182. (insert "</tr>\n") 183. (setq i (1+ i)) 184. ) 185. (insert "</table>\n") 186. (forward-line (- (+ nrows 3))) 187. (message "%d rows, %d number of columns" nrows ncols) 188. ) 189. 190. (defun convert-html-angles () 191. " replaces all < and > to &lt; and &gt; in the region" 192. (interactive "*") 193. (narrow-to-region (point) (mark)) 194. (goto-char (point-min)) 195. (replace-string "<" "&lt;") 196. (goto-char (point-min)) 197. (replace-string ">" "&gt;") 198. (widen) 199. ) 200. 201. (defun delete-leading-whitespace () 202. (interactive) 203. (narrow-to-region (point) (mark)) 204. (goto-char (point-min)) 205. (replace-regexp "^[\t ]*" "") 206. (widen)

207. ) 208. 209. (defun unify-region (top bottom &optional macro) 210. "removes all carriage returns in region" 211. (interactive "r") 212. (save-excursion 213. (let ((end-marker (progn 214. (goto-char bottom) 215. (beginning-of-line) 216. (point-marker))) 217. next-line-marker) 218. (goto-char top) 219. (if (not (bolp)) 220. (forward-line 1)) 221. (setq next-line-marker (point-marker)) 222. (while (< next-line-marker end-marker) 223. (goto-char next-line-marker) 224. (save-excursion 225. (forward-line 1) 226. (set-marker next-line-marker (point))) 227. (save-excursion 228. ;; command goes here 229. (end-of-line)(delete-char 1) 230. )) 231. (set-marker end-marker nil) 232. (set-marker next-line-marker nil)) 233. ) 234. ) 235. 236. (defun downcase-tag ()(interactive) 237. "downcases HTML tags to make them more like xhtml wants. (<HTML> and </HTML> are downcased. Bad Side Effects to be corrected: Permanently changes case-fold-search and starts by downcasing the word at the point." 238. (setq case-fold-search nil) 239. (downcase-word 1) 240. (search-forward-regexp "<[/]*[A-Z]") 241. (forward-char -1) 242. (setq case-fold-search t) 243. ) 244. (defun display-file-info() 245. "trival function to show find-file-hooks functionality" 246. (message (concat "the filename is " buffer-file-name " and it is " 247. (if buffer-read-only "read only." "writable"))) 248. ) 249. (defun insert-numbers (arg) 250. "insert number into a file, starting with 1 -mdf" 251. (interactive "NHow many numbers to insert: ") 252. (setq i 0) 253. (while (< i arg) 254. (setq i (1+ i)) 255. (insert (int-to-string i)) 256. (backward-char 1) 257. (next-line 2) 258. (beginning-of-line 0) 259. ) 260. ) 261. 262. (defun bubble-line-up(click) 263. ;; by mitch fincher 264. (interactive "@e") 265. (beginning-of-line)(transpose-lines 1) 266. (previous-line 2)) 267. 268. (defun insert-date-stamp ()

269. "Insert current date at current position." 270. (interactive "*") 271. (message "starting to date stamp the line...") 272. (beginning-of-line) 273. (insert "<!------------------------------------------------->\n") 274. (insert (format-time-string "%D %a" (current-time))) 275. (insert "\n<!------------------------------------------------>\ntimetool:\n\n") 276. (forward-char -1) 277. (message "starting to date stamp the line - finished.") 278. ) 279. 280. (defun sqlupcase () 281. " upcases sql keywords in selected region" 282. (interactive "*") 283. (setq sqlkeywords '("add " "all " "alter " "and " "any " "as " "asc " "authorization " "backup " "begin " "between " "break " "browse " "bulk " "by " "cascade " "case " "check " "checkpoint " "close " "clustered " "coalesce " "collate " "column " "commit " "compute " "constraint " "contains " "containstable " "continue " "convert " "create " "cross " "current " "current_date " "current_time " "current_timestamp " "current_user " "cursor " "database " "dbcc " "deallocate " "declare " "default " "delete " "deny " "desc " "disk " "distinct " "distributed " "double " "drop " "dummy " "dump " "else " "end " "errlvl " "escape " "except " "exec " "execute " "exists " "exit " "fetch " "file " "fillfactor " "for " "foreign " "freetext " "freetexttable " "from " "full " "function " "goto " "grant " "group " "having " "holdlock " "identity " "identitycol " "identity_insert " "if " "in " "index " "inner " "insert " "intersect " "into " "is " "join " "key " "kill " "left " "like " "lineno " "load " "national " "nocheck " "nonclustered " "not " "null " "nullif " "of " "off " "offsets " "on " "open " "opendatasource " "openquery " "openrowset " "openxml " "option " "or " "order " "outer " "over " "percent " "plan " "precision " "primary " "print " "proc " "procedure " "public " "raiserror " "read " "readtext " "reconfigure " "references " "replication " "restore " "restrict " "return " "revoke " "right " "rollback " "rowcount " "rowguidcol " "rule " "save " "schema " "select " "session_user " "set " "setuser " "shutdown " "some " "statistics " "system_user " "table " "textsize " "then " "to " "top " "tran " "transaction " "trigger " "truncate " "tsequal " "union " "unique " "update " "updatetext " "use " "user " "values " "varying " "view " "waitfor " "when " "where " "while " "with " "writetext ")) 284. (narrow-to-region (point) (mark)) 285. (while sqlkeywords 286. (goto-char (point-min)) 287. (setq keyword (car sqlkeywords)) 288. (replace-string keyword (upcase keyword)) 289. (setq sqlkeywords (cdr sqlkeywords)) 290. (message keyword)(sit-for 0 1) 291. ) 292. (widen) 293. (message "sqlupcase complete.") 294. ) 295. 296. Or the mapcar function can be used to make it more elegant: 297. 298. (defun sqlupcase () 299. " upcases sql keywords in selected region" 300. (interactive "*") 301. (setq sqlkeywords '("add " "all " "alter " "and " "any " "as " "asc " "authorization " "backup " "begin " "between " "break " "browse " "bulk " "by " "cascade " "case " "check " "checkpoint " "close " "clustered " "coalesce " "collate " "column " "commit " "compute " "constraint " "contains " "containstable " "continue " "convert " "create " "cross " "current " "current_date " "current_time " "current_timestamp "

"current_user " "cursor " "database " "dbcc " "deallocate " "declare " "default " "delete " "deny " "desc " "disk " "distinct " "distributed " "double " "drop " "dummy " "dump " "else " "end " "errlvl " "escape " "except " "exec " "execute " "exists " "exit " "fetch " "file " "fillfactor " "for " "foreign " "freetext " "freetexttable " "from " "full " "function " "goto " "grant " "group " "having " "holdlock " "identity " "identitycol " "identity_insert " "if " "in " "index " "inner " "insert " "intersect " "into " "is " "join " "key " "kill " "left " "like " "lineno " "load " "national " "nocheck " "nonclustered " "not " "null " "nullif " "of " "off " "offsets " "on " "open " "opendatasource " "openquery " "openrowset " "openxml " "option " "or " "order " "outer " "over " "percent " "plan " "precision " "primary " "print " "proc " "procedure " "public " "raiserror " "read " "readtext " "reconfigure " "references " "replication " "restore " "restrict " "return " "revoke " "right " "rollback " "rowcount " "rowguidcol " "rule " "save " "schema " "select " "session_user " "set " "setuser " "shutdown " "some " "statistics " "system_user " "table " "textsize " "then " "to " "top " "tran " "transaction " "trigger " "truncate " "tsequal " "union " "unique " "update " "updatetext " "use " "user " "values " "varying " "view " "waitfor " "when " "where " "while " "with " "writetext ")) 302. (narrow-to-region (point) (mark)) 303. (mapcar (lambda (keyword) 304. (goto-char (point-min)) 305. (replace-string keyword (upcase keyword) ) 306. (message keyword)(sit-for 0 5) 307. ) sqlkeywords) 308. (widen) 309. (message "sqlupcase complete.") 310. ) 311. 312.

313.

How to have the recently used files show up as an option under "File"

Put this in your .emacs file


(recentf-mode 1)

314.

How to reverse sort selected lines

reverse-region
C-u1M-x sort-lines

315.

How to run an external command and get the results in an Emacs buffer

E-!"your command goes here"

316. How to use Abbreviation mode. Abbreviation allows you to enter a few characters and emacs expands those to a longer string. in your .emacs file place the following lines:
317. (setq-default abbrev-mode t) 318. 319. (read-abbrev-file "~/.abbrev_defs") 320. 321. (setq save-abbrevs t) 322.

To define an abbreviation, enter the shortened form and then "C-x aig" for "add-inverseglobal" 323. Using Bookmarks.

Bookmarks are a quick index into your frequently visited files. Keystroke Command Description C-xrm bookmark-set saves this file and position as a bookmark C-x rb bookmark-jump goes to the defined bookmark 324. Using gnus, the emacs news reader Add the following code if you are reading from a remote news server:
325. (add-hook 'nntp-server-opened-hook 'nntp-send-authinfo) 326. (setq gnus-nntp-server "news.your.isp")

Helpful keystrokes:
j - jump to newsgroup space - open this newsgroup

327. W3 a web browser inside emacs. This is located at http://www.cs.indiana.edu/elisp/w3/docs.html My favorite keystrokes: Key Meaning C-xC-b Show index of visited links F Move forward a page B Move backward a page s Show HTML source for current page C-o Open a user-supplied URL 328. Macros are our friends. Keystroke Command Description C-x( start-kbd-macro Starts recording keystrokes C-x) end-kbd-macro Stop recording keystrokes C-xe call-last-kbd-macro C-g keyboard-quit quit defining Executes current macro and opens it for appending C-uC-x( new commands name-last-kbd-macro Gives the macro a name inserts the textual definition at the current point insert-kbd-macro usually done into the .emacs file set-local-key key binds the key name to the macro for this session macroname C-uC-xq Insert a pause into a macro definition Continue in the macro after ESC C-c a pause 329. Defining the meaning of keys

function

syntax (define-key keymap "keystroke" define-key 'command-name) gloabal-set- (gloabal-set-key "keystroke" 'commandkey name) (local-set-key "keystroke" 'commandlocal-set-key name) 330.

Notes

like a define-key, but uses "globalmap" like a define-key, but uses the local keymap

Note: the argument to the define-key function can be a keymap itself. example:

331. (setq ctlf1-map (make-sparse-keymap)) 332. 333. (global-set-key [(control f1)] ctlf1-map) 334. 335. (define-key ctlf1-map "t" 'simple-html-insert-table) 336.

337. Now if you enter "C-f1 t" it will run the command simple-html-insert-table. 338. To add info files to directories other than default: Example to add a new info directory. I think this is better than adding to the default one, since we I upgrade emacs the old one (and my additions go away).
339. (setq Info-directory-list (cons "c:/fincher/emacs/info/make" Infodirectory-list)) 340. 341.

The c:/emacs/lisp/dir file will still need the top level pointers added. e.g.,
* Make: (make). gnu make documents.

342.

Using Registers to save scraps of text

Registers allow you to have multiple copy/paste buffers. You need two commands, Register-Save (C-x r s) and Register-Insert(C-x r i) To use this, hilight an area of text and enter "C-x r s"; emacs will ask you for which buffer to save it in. Pick a letter a-z.. Use "Cx r i" to insert the saved text. 343.
344. // replaces all instances of xxx.JAVA with xxx.java 345. M-x replace-regexp "\(^[a-z]+\)\.c" "\1.C"

Regular Expressions

myfile.c other.c twice.c

results in:
myfile.C

other.C twice.C

346. Completion. You can tell emacs to ignore certain file extensions when giving you possible completions:
347. (setq completion-ignored-extensions '(".o" ".elc" "~" ".bin" ".bak" ".obj" ".map" ".a" ".ln" ".class"))

348. 1. 2. 3. 4. 349.

Command Line args "--no-site-file" tells emacs not to look for a site-init.el file. "--no-init-file" do not run the ~/.emacs or default.el "-q" start emacs without running ~/.emacs "--debug-init" allows debugging of the .emacs file etags:

To create the TAG file


etags -o c:\fincher\TAGS c:/emacs/lisp/*.el

350.

Output (print "howdy") => "howdy" ("AUTOEXEC.BAT" "Adobe" "CONFIG.SYS" ...) ("AUTOEXEC.BAT") the Lisp Printer, used to show printed representation of a Lisp object

(print OBJECT & optional PRINTCHARFUN) (directory-files "c:" ) (directory-files "c:" t "\\.BAT$") prin1

351.

352. (defun forward-paragraph (&optional arg) 353. "docuemtation string" 354. (interactive "p") 355. (or arg (setq arg 1)) 356. ...

Arguments:

357. 360.

How to change the background and foreground colors Misc:

358. (set-face-background 'default "black") 359. (set-face-foreground 'default "white") 361. > I seems like most of the commands only operate on the current buffer. Is 362. > there way to apply a command (query-replace, for exapmple) on all loaded 363. > bufferes, other than by creating etags ? 364. M-x load-library RET dired-x RET 365. Then, you can mark files in dired and use `A' to search in all of them and `Q' to do query-replace in all of them. 366. -kai

367. 1. 2. 3. 4. 5. 6.

My favorite Emacs references: http://tiny-tools.sourceforge.net/emacs-keys.html emacswiki.org windows info Emacs and Unicode FAQ in text Manual in HTML

7. an emacs email reader 8. Emacs and Java (JDE) 9. gnu's nt page 10. GNU Emacs Lisp Reference Manual Excellent source of info on the language 11. GNU Emacs on Windows NT and Windows 95 Paul Voelker's Excellent Work on NT issues 12. Programming in Emacs Lisp An Introduction 13. Writing GNU Emacs Extensions A real carbon based book. Excellent intro into emacs and lisp 14. My .emacs, .vm, and simple-html-mode.el files. The name "Emacs" is derived from "Editor Macros", but I like "Escape Meta Alt Control Shift" better. 368. "Lambda: The Ultimate Imperative" by Guy Lewis Steele, Jr. and Gerald Jay Sussman.

You might also like