Emacs Lisp

Created Thursday 28 November 2013

  1. Emacs Lisp manual:
    1. Full reference:
      1. http://www.gnu.org/software/emacs/manual/html_node/elisp/
    2. Intro tutorial:
      1. https://www.gnu.org/software/emacs/manual/html_node/eintr/

  1. Emacs Lisp – keyboard shortcuts
    1. TAB – Indent
    2. M-C-\ – Indent area
    3. C-x C-e – Evaluate (result to minibuffer) – (eval-last-sexp)
    4. C-j – Evaluate (result to current buffer)
    5. C-u C-x C-e – like C-j
    6. q – quit from the debugger
    7. C-u – used to pass argument to function in interactive call (see example below); default argument is 4
    8. C-<SPC> – set the mark position
    9. C-x C-x(exchange-point-and-mark)
    10. C-u C-<SPC> – jump the cursor to a saved mark
    11. C-h f, C-h v – help for function, variable
    12. C-h p – search the standard Emacs libraries by topic keywords
    13. describe-function – location of function definition
    14. find-tag – jump to a funcion in its original source file
    15. M-x visit-tags-table – goto a TAGS table
  2. Syntax, functions, variables
    1. (x y z) – list, (x y “hi !”) – list; x, y, “hi !” – atoms
    2. '(x y z) – don't treat x as a command or function
    3. = – whether 2 args, nums and markers are equal
    4. equal – true if the 2 objs have a similar structure and content
    5. eq – true if the 2 args are the same obj
    6. string-lessp | string< – whether the 1st smaller than the 2nd
    7. string-equal | string= – test for equality
    8. (concat “abc” “def”) – concatenate to “abcdef”
    9. (substring “The quick brown fox jumped.” 16 19) – returns “fox”
    10. (number-to-string (+ 2 3)) – also known as int-to-string
    11. (message “This buffer is: %s.” (buffer-name)) – return the buffer name to the minibuffer (echo area)
    12. (message “The fill-column is %d” fill-column)%d for int
    13. (set 'myvar '(some list)) – set the value of the symbol myvar
    14. (setq var1 '(val1) var2 (val2) …) – set multiple autoquoted
    15. (buffer-name) – the current buffer name
    16. (buffer-file-name) – full path to file to wich the buffer refers
    17. (current-buffer) – return the current buffer itself
    18. (other-buffer) – return the previous (not visible) buffer
    19. (other-buffer (current-buffer) t) – other visible buffer
    20. (switch-to-buffer (other-buffer)) – display and focus other buffer
    21. (set-buffer (other-buffer)) – focus without displaying
    22. (buffer-size) – returns a count of chars in the buffer
    23. (point) – num of chars from buffer start up to cursor point
    24. (point-min) – minimum permissible value of point in cur. buf.
    25. (point-max) – maximum etc...
    26. (mark-whole-buffer) – is bound to C-x h
    27. (zap-to-char) – kill all up-to (including) specified char
  3. Code examples
    1. Define a function:
(defun function-name (arguments...)
"optional-documentation..."
(interactive argument-passing-info) ; optional
body...)
  1. Define an interactive function:
(defun multiply-by-seven (number) ; Interactive version.
"Multiply NUMBER by seven."
(interactive "p")
(message "The result is %d" (* 7 number)))
Type:
C-u [number] M-x multiply-by-seven <RET>
  1. Setting local variables (useful in functions, default is nil):
(let ((variable value)
(variable value)
...)
body...)
  1. If statement:
(if true-or-false-test
action-to-carry-out-if-the-test-returns-true)
  1. If-else statement:
(if true-or-false-test
action-to-carry-out-if-the-test-returns-true
action-to-carry-out-if-the-test-returns-false)
  1. Interactive
    1. p – interpret a prefix as a number to be passed to the function
    2. c – tells the function the name of the character
    3. b – the name of an existing buffer
    4. f – the name of an existing file
    5. r – point and mark, as 2 num args, smallest first
    6. \n – newline, separates the interactive args specification
    7. (interactive "p\ncZap to char: ") – example for (zap-to-char)
    8. (interactive) – for the function that doesn't require args



Backlinks: