Emacs and slime reference
From PaskvilWiki
Emacs in General --------------------------------------------------------------- General: * C-u N cmd repeat the 'cmd' N-times (N is a number) - further on denoted [N] cmd * M-N cmd repeat the 'cmd' N-times (N is a number) - further on denoted [N] cmd * C-g stop current command - useful if emacs stops responding; also to discard command typed so far * <Esc> <Esc> <Esc> general "get out" command * C-h c cmd display brief help for the 'cmd' * C-h k cmd display a full help for the 'cmd' * C-h f fn display a full help for the function 'fn' * C-h a apropos - type word or regex to show all commands related to it * C-h r reference manual * chord C-h print a list of all command that start with a given key 'chord' e.g. C-x C-h gives all commands starting with C-x * C-h b, C-h m list of available bindings, info about current mode * C-x C-c quit To (re)define key chord, edit your ~/.emacs file like this: (define-key slime-repl-mode-map (kbd "C-c ;") 'slime-insert-balanced-comments) (global-set-key (quote [C-tab]) 'slime-complete-symbol) To interactively create bindings, use (in Emacs): 1) M-x global-set-key 2) press the key combination you want 3) type the command to run upon this 4) press C-x ESC ESC to see the command in full Moving around: * C-v, M-v one screen ahead/back * [N] C-v, [N] M-v move the screen down/up by N lines * C-l center the screen around cursor, move to top, and move to bottom (on repetition of the stroke) * [N] C-l move the current line to be N-th on the screen, 0-based * C-b, C-f, C-p, C-n move left/right/up/down * M-b, M-f move by words backward/forward * C-a, C-e move to the beginning/end of current line * M-a, M-e move to the beginning/end of current sentence * M-<, M-> move to the beginning/end of whole text Editing: * M-Bcksp, M-d kill word before/after cursor * C-k, M-k kill from cursor to end of line (second C-k will kill \n at the end), to end of sentence repeating C-k will accumulate the killed text (if you press C-k 10 times - killing 5 lines, and then yank the text, it will yank all 5 lines, not just the last) * [N] C-k kill N lines, including the newlines * C-y yank the killed text * M-y replace the yank with previous kill (i.e. after C-y, you can press M-y, and it will replace the yank with text that was killed before this one, and so on; this is circular queue - press M-y will get you back to the last kill; you can also use [N] M-y, where N can be positive or negative) * C-x u, C-_ undo undo's are considered ordinary changes; thus if the chain of undo's is stopped, e.g. with C-f, undo's can be undone Windows: * C-x 1 kill all other windows - go to "one window" editing; deletes all other windows, and expands current to full screen * C-x 2 split screen in 2 * C-x o move to "other" window * C-M-v scroll the other window * C-x 3 split window vertically * C-x 4 C-f file open file in new bottom window and jump to it Files: * C-x C-f find (open) file; opens in a new buffer * C-x C-s save the file contents Buffers: * C-x C-b list of buffers * C-x b switch to buffer (prompts for buffer name) * C-x s save some buffers * C-x <lft>, C-x <rgh> previous/next buffer * C-x k bfr kill buffer 'bfr', defaults to current buffer Search and Replace: * C-s, C-r search forward/backward, incrementally; C-s/C-r repeats the search, Backspace goes back, Enter ends the search * M-x replace-string params 'from' 'to' SLIME - Superior Lisp Interaction Mode for Emacs ------------------------------- -- note: all 3-key commands can be used with or without `C-' for the last key; e.g C-c C-d d can also be used as C-c C-d C-d C-c C-w c can also be used as C-c C-w C-c, etc. with the exception of the last key being 'h' -- Evaluation * C-x C-e, C-c C-p evaluate expression before point and show result in echo area/pretty print result in new buffer * C-M-x evaluate current toplevel (note - if evaluating defvar, resets the variable even if already bound) * C-c : evaluate expression read from minibuffer * C-c C-r evaluate region * C-x M-e evaluate expression before point, and show output buffer (useful for expressions that print to stdout) * C-c E edit value of set-able form in new buffer, and set its value in Lisp upon commit with C-c C-c * C-c C-u undefine (fmakunbound) function for the symbol at point -- Compilation * C-c C-c compile toplevel form at point; the code is executed afterwards * [N] C-c C-c -"-, with N>0 compile for maximal debugging, for N<0 for speed * C-c C-k compile and load current buffer's source file * C-c M-k compile but do not load current buffer's source file * C-c C-l load Lisp file ---- after the compilation (notes are indicated as underlining on source forms) * M-n, M-p move to next/previous compiler note, and display it * C-c M-c remove all annotations from buffer * C-x ` go to next error message -- Completion and Editing * M-TAB complete symbol at point * C-c M-q reindent current defun * M-x slime-close-all-parens-in-sexp * M-x slime-insert-balanced-comments * M-C-a, M-C-e slime-beginning/end-of-defun * M-x slime-ensure-typeout-frame create typeout frame if necessary; it's like echo area, just scrollable and more persistent * M-x slime-highlight-edits-mode toggle on-off highlighting edits is file (e.g. to see what to recompile with C-c C-c) -- Finding Definitions * M-. go to the definition of the symbol at point * M-, go to the point where M-. was invoked * C-x 4 . like M-. but switches to the other window to edit the definition * C-x 5 . like M-. but opens another frame to edit the definition in -- Documentation * SPC inserts space and looks up arguments list for the function at point * C-c C-d d describe the symbol at point * C-c C-f describe the function at point * C-c C-d a perform apropos search on Lisp symbol names, and display their doc strings * C-c C-d z like C-c C-d a, but includes internal symbols by default * C-c C-d p show apropos results of all symbols in package * C-c C-d h hyperspec lookup, location defined in 'common-lisp-hyperspec-root'; the 'C-c C-d C-h' does not work here! * C-c C-d ~ lookup a 'format character' in hyperspec -- Cross-Reference * C-c C-w c show callers of a function * C-c C-w w show all known callees * C-c C-w r show references to global variable * C-c C-w b show bindings of a global variable * C-c C-w s show assignments to a global variable * C-c C-w m show expansions of a macro * M-x slime-who-specializes show all known methods that specialized on a class ---- Lisp system dependent (works by going through heap, and is only somewhere available) * C-c < list callers of a function * C-c > list callees of a function -- Macro-Expansion * C-c C-m macro-expand1 the expression at point * C-c M-m macro-expand the expression at point -- Disassembly * C-c M-d disassemble the function definition of the symbol at point * C-c C-t toggle tracing of the function at point * M-x slime-untrace-all untrace all functions -- Abort/Recovery * C-c C-b interrupt Lisp (send SIGINT) * M-x slime-restart-inferior-lisp * C-c ~ synchronize the current package and working directory from Emacs to Lisp * C-c M-p set the current package of the REPL * M-x slime-cd set the cwd of the Lisp process and of the REPL buffer * M-x slime-pwd print the current directory of the Lisp process -- Inspector * C-c I inspect the value of an expression entered in the minibuffer ---- within the inspector * RET call inspector on the value at point; call the action if point is on action * d describe the slot at point * v toggle between verbose and terse mode * l go back from the previous object (return from RET) * n inverse of 'l', also bound to SPC * q dismiss the inspector buffer * M-RET store the value under point in variable '*', to access it in REPL -- Profiling * M-x slime-toggle-profile-fdefinition toggle profiling of a function * M-x slime-profile-package profile all functions in a package * M-x slime-unprofile-all unprofile all functions * M-x slime-profile-report report profiler data * M-x slime-profile-reset reset profiler data * M-x slime-profiled-functions show list of currently profiled functions SLIME Debugger (SLDB) -- Examining Frames (going through stack frames in debugger) * t toggle display of local variables and CATCH tags * v view frame's current source expression in Lisp source file's buffer * e evaluate an expression in the frame; it can refer to local variables in the frame * d -"- and pretty print the result in a temp buffer * D disassemble the frame's function * i inspect the result of evaluating expression in the frame -- Invoking Restarts * a invoke the ABORT restart * q "quit" - THROW to a tag that the toplevel SLIME request-loop catches * c invoke the CONTINUE restart * 0..9 invoke restart by number; also can be called with RET on them in the buffer -- Navigating between Frames * n, p move between frames * M-n, M-p move with "sugar" - display details and source of the next frame only -- Stepping * s step to the next expression in the frame * x step to next form in the current function * o stop single-stepping temporarly, resume it upon return to this function -- Miscellaneous * r restart execution of the frame with the original arguments to it * R return from the frame with the value entered in the minibuffer * B exit SLDB and debug the condition using Lisp system's default debugger * : evaluate an expression entered in the minibuffer SLIME Misc -- slime-selector command - for quickly switching to important buffers -- to bind it to e.g. 'C-c s', use: (global-set-key "\C-cs" 'slime-selector) -- the following keys switch to buffers: * ? help buffer for current SLIME connection * r the REPL for current SLIME connection * d the most recently activated SLDB buffer * l the most recently visited lisp-mode source buffer * s the *slime-scratch* buffer -- slime-macroexpansion-minor-mode * C-c C-m macro-expand1 the current form in place (replaces the original form) * g repeat the last macroexpansion, replacing the contents of the buffer with new expression * q close the expansion buffer SLIME Tips and Tricks -- Setting Up the Lisp Image - to load swank without Emacs, just run: (load "/path/to/swank-loader.lisp") within the running Lisp image. now just run the swank server: (swank:create-server); to use just one port, e.g. when tunneling through ssh, tell swank not to use extra connection for output: (setf swank:*use-dedicated-output-stream* nil) [this is now default]. -- parameters to swank:create-server: :port - port number to listen on (default 4005) :dont-close - should the server continue accepting connections after the first one? (default NIL) :coding-system - encoding to use for communication, e.g. "utf-8-unix" - then, on the Emacs side, you set these as parameters: (setq slime-net-coding-system 'utf-8-unix) (slime-connect "127.0.0.1" 4005) - to create ssh tunnel for swank/slime: `ssh -L4005:localhost:4005 user@remote-machine.com`, then start the SLIME with 'M-x slime-connect RET RET' - RET RET means accepting defaults - localhost and 4005 port, the ssh tunnel will forward this to the 'remote-machine.com' - to translate filenames from local to remote, use 'tramp-mode', like this: (push (slime-create-filename-translator :machine-instance "remote-machine.com" :remote-host "remote" ; this is what cl:machine-instance returns for the host name :username "user" slime-filename-translations) -- Connecting to SLIME automatically if you want SLIME to connect to Lisp whenever you open a Lisp file, add this to ~/.emacs: (add-hook 'slime-mode-hook (lambda () (unless (slime-connected-p) (save-excursion (slime))))) SLIME Presentations -- presentation is region of text associated with Lisp object; right-click brings up menu with allowed operations; some, like inspecting, are for all, other are specialized; you can cut-paste presentations - the objects themselves, not just the text, - even if it's unreadable object -- the package 'slime-presentations' installs them in REPL; they appear in red; they can be e.g. copied to a new input in REPL; copying incomplete presentation, or editing text within it will turn it to plain text; this can be undone -- they are also available in inspector (all inspectable parts are presentations) and debugger (all local variables), thus can be evaluated in REPL; they are valid as long as the corresponding buffers are open * C-c C-v SPC marks presentation at point, making it possible to copy it * C-c C-v w, C-c C-v r copying the presentation at point to the kill ring/REPL * C-c C-v d, C-c C-v i describe/inspect the object associated with the presentation at point * C-c C-v n, C-c C-v p move point to the next/previous presentation in the buffer