* An invitation to Emacs ** Setup (set-frame-font "10x20") (load-library "alossage") (auto-lossage-make-frame) ** Why? This talk will teach some concepts of Emacs. It is not a tutorial, but the idea is that you will want to learn Emacs afterwards. (find-file-other-window "emacs-user.jpg") ** What is Emacs? Emacs is the extensible, PROGRAMMABLE customizable, CONFIGURABLE self-documenting DISCOVERABLE real-time INTERACTIVE display editor. SCREEN-ORIENTED ** A very short history 1976: First version in TECO created at MIT by Richard Stallman, Guy Steele, and Dave Moon. (vi was 1976 too!) 1981: C port by Gosling, first Unix version? 1985: GNU Emacs 1994: Lucid Emacs -> XEmacs forked 1996: GNU Emacs 19.34 1997: GNU Emacs 20.1 2000: GNU Emacs 21.1 2006: GNU Emacs 22.1 2009: GNU Emacs 23.1 Current version: 23.3, 24 on the horizon. (Not shown: Lisp machine history.) ** Preliminaries C-... means "keep Control pressed and then type ..." M-... means "keep Alt pressed and then type ..." OR "press ESC and then type ..." Chaining: C-M-s C-x C-s ** Perils of Emacs - RSI - overcustomization - NEO user? You'll need C-x, C-c often. QWERTY on C-...? ** Buffers, Windows, Frames Frames are tiled into windows, which display buffers, which contain the text. A buffer can be shown on multiple windows in multiple frames. These names are older than X11 (and Windows of course). ** Elisp Emacs consists of two parts: An implementation of Elisp (and core data structures) in C, and an implementation of an editor in Elisp. Elisp code can be written and loaded at run-time. Elisp code defines functions, which can be bound to key sequences. Example I: (global-set-key [f12] 'goto-line) Example II: (defun chris2-insert-timestamp () (interactive) (insert " " (downcase (format-time-string "%d%b%Y" (current-time))) " +" (user-login-name) "+")) (global-set-key (kbd "M-p") 'chris2-insert-timestamp) There are global key bindings, and buffer-local key bindings, which depend on the *mode* of the buffer. Find out what a key does: C-h k Find out what a function does: C-h f ** Elementary editing Text is a stream of characters. Editing is not really line-based,newlines are mostly like ordinary characters. The cursor is called the *point*. Insertion happens to the left of the cursor box. There also is a *mark*, which is used operations on ranges (selections, rectangle editing, ...) C-w cuts the selection. M-w copies the selection. C-y yanks, M-y then cycles the "kill buffer". Operations have logical connections and are mnemonic: scroll up: C-v scroll down: M-v scroll other window: C-M-v beginning of line: C-a backward sentence: M-a beginning-of-defun: C-M-a end of line: C-e forward sentence: M-e end-of-defun: C-M-e previous line: C-p next line: C-n backward: C-b forward: C-f delete char: C-d delete word: M-d C-s starts interactive search (isearch). C-M-s starts regexp search. C-x C-c exits Emacs. But why would you want to do that? ** Modes There are many modes! (apropos ".*-mode$") E.g. fundamental-mode, text-mode, c-mode, ruby-mode. Language major modes usually provide syntax-highlighting, smart indentation etc. More complex things ("applications", rather): gnus-group-mode, gnus-article-mode. There are also minor-modes, which add additional keybindings or features. E.g. auto-fill-mode, line-number-mode. ** A whirlwind tour *** c-mode (find-file "hello-world.c") *** ansi-term (ansi-term "/bin/zsh") *** AucTeX (find-file "~/uni/current/bsc/seminar/seminar.tex") Show speedbar. *** Dired File manager. (dired ".") Also, one can open .tar.gz transparently. *** Org-mode A *powerful* outliner, to-do list, spreadsheet. - foo - bar - baz - quux - meh | Article | Price | |----------+-------| | Bananas | 5.00 | | Apples | 3.00 | | Coconut | 5.50 | |----------+-------| | Subtotal | | | Tax | | | Total | | C-c + =(1+@-1)*@-2 *** Gnus Short demo. Emacs has several other mail readers: RMAIL, VM, Mew, MH-E, Wanderlust *** Slime A mighty interactive Common Lisp environment. (setq inferior-lisp-program "/usr/bin/sbcl") (add-to-list 'load-path "/usr/share/emacs/site-lisp/slime/") (require 'slime) (slime-setup) (slime) (find-file "hello-world.lisp") M-. Similar environments exist for Scheme, Erlang and R. *** Ediff (ediff "mirrorlist.pacnew" "mirrorlist") One can also diff buffers, do three way merges etc. *** magit (find-file "~/prj/sabotage") M-x magit-status M-x magit-display-log *** nXML mode (find-file "hello-world.xhtml") *** calc (calc) Can do almost everything, stack-based. Integrates with org-mode, too: |---+-------------+---+-----+--------| | | Func | n | x | Result | |---+-------------+---+-----+--------| | # | exp(x) | 1 | x | | | # | exp(x) | 2 | x | | | # | exp(x) | 3 | x | | | # | x^2+sqrt(x) | 2 | x=0 | | | # | x^2+sqrt(x) | 2 | x=1 | | | * | tan(x) | 3 | x | | |---+-------------+---+-----+--------| #+TBLFM: $5=taylor($2,$4,$3);n3 Simple alternative: (calculator) *** imaxima (imaxima) exp(-x^2); integrate(%, x, -inf, inf); *** Emacs server (server-start) % emacsclient -t *** IRC M-x rcirc M-x erc *** Web browsing w3 is/was a browser written in pure Elisp. emacs-w3m is a usable interface to w3m. (w3m-browse-url "http://gaf.fs.lmu.de") *** Fun M-x 5x5 M-x blackbox M-x decipher M-x doctor M-x dunnet M-x gomoku M-x hanoi M-x life M-x lm M-x morse-region M-x mpuz M-x phases-of-moon M-x pong M-x solitaire M-x studlify-region M-x tetris M-x yow M-x zone ** Onwards! To learn Emacs, I recommend: The Emacs tutorial: C-h t http://www.gnu.org/software/emacs/tour/ O'Reilly: Learning GNU Emacs The Emacs manual: (info "emacs") The Emacs faq: (info "efaq") The Emacs Lisp Intro: (info "eintr") emacswiki.org #emacs @ freenode.net