Skip to content

Latest commit

 

History

History
167 lines (135 loc) · 10.7 KB

Emacs_Key_Bindings_Elisp.org

File metadata and controls

167 lines (135 loc) · 10.7 KB

Emacs key bindings for Elisp programming

Emacs key bindings for Elisp programming

Elisp Evaluation

Command: M-x [command]Key BindingDescription
eval-last-sexpC-x C-eEvaluate last s-expression under cursor
eval-print-last-sexp-Evaluate last s-expression under cursor and print.
eval-expressionM-:Execute S-expression in minibuffer.
-C-u M-:Evaluate S-expression in minibuffer and insert result at point.
eval-defunC-M-xEvaluates the outermost S-expression, regardless of cursor position
within the s-exp.
eval-bufferC-c C-bEval the whole buffer
eval-region-Eval the selected text
Eval and print last s-expression.
Eval last s-expression.
repeat-complex-commandC-x ESC ESCUseful to reverse engineering Emacs’ commands executed with M-x like M-x
lgrep or repeat it.

Note: command M-x repeat-complex-command.

Example: User enter

  • M-x lgrep
  • Prompt 1 -> Search for: system.windows.forms
  • Prompt 2 -> In files (default *.org): *.org
  • Prompt 3 -> In directory: ~/Documents/wiki

To extract the command type C-x ESC ESC and copy it from the minibuffer with C-k and then paste with in the buffer with C-y. The result will be:

(lgrep "system.windows.forms" "*.org" "~/Documents/wiki" nil)

This s-expression can be run again or used in a function or any Elisp app. Example:

(defun search-my-dir ()
    (interactive)
    (lgrep (read-string "Search wiki: ") "*.org" "~/Documents/wiki" nil))

M-x search-my-dir system.windows will search all *.org files containing the line that matches system.windows in the directory ~/Documents/wiki.

Elisp Debugger / Edebug

This video shows how to use Edebugger to debug Elisp functions and code:

KeybindingM-x commandDescription
Emacs
C-u C-M-xedebug-defunInstrumment function for debugging.
Inside Edebug
qAbort execution
spaceSetep through, single step.
bInsert breakpoint
uUnset breakpoint.
shift-GContinue beyond breakpoint
iJump to definition of defunction
M-:Prompt for an expression to evaluate.
cContinue execution
xSet a conditional breakpoint

Edebug info nodes documentation:

(info "(elisp) Edebug Execution Modes")

(info "(elisp) Instrumenting")

See also:

Useful Commands

Command: M-x [command]Key BindingDescription
check-parenFind unmatched parenthesis
checkdocCheck docstring in an Elisp package (*.el file).
auto-insertInsert header file of an Elisp package’s header file.
view-echo-area-messagesC-h eShow the message buffer
Elisp library
find-variableOpen the elisp file at the point the variable is defined.
find-libraryOpen an Emacs library or package in the load-path.
find-functionOpens an library.el file at the point the function is defined.
locate-libraryShow path of a library.el (Emacs Package) file.
Documentation Commands
aproposSearch for all elisp symbols, variables and functions that match a regex pattern.
apropos-commandC-h aSearch for all commands (M-x cmd) that match a regexp pattern.
apropos-libraryShow all symbols associated with an Elisp library (Emacs Package)
info-aproposFind all info pages that match a pattern.
describe-functionC-h fShow function documentation or docstring.
describe-modeC-h mShow current major mode documentation and all key bindings associated.
describe-bindingsC-h-bShow all associated key bindings with the current buffer.
describe-variableC-h vShow variable documentation
describe-packageDescribe an Emacs package installed from Melpa repository.

IELM - Emacs Lisp Interpreter

M-x ielmRun Emacs Lisp Interpreter
C-c C-b(IELM only) Change the current buffer of IELM. It is useful control buffers from IELM shell.
C-[up](All Shells) Get the next input in the history
C-[down](All Shells) Get the previous input in the history
M-p(All Shells) Get the previous input in the history
M-n(All Shells) Get the next input in the history
C-c C-lDisplay the shell history in another window

S-expression Navigation

C-M-nMove forward over a parenthetical group
C-M-pMove backward over a parenthetical group
C-M-fMove forward over a balanced expression
C-M-bMove backward over a balanced expression
C-M-kDelete s-expression under cursor
C-M-aMove to the beggining of current function
C-M-eMove to the end of current function

Delimiter Wrapping

M-(Wrap selection in parentheses
M-[Wrap selection in square brackets
M-{Wrap selection in curly brackets