Notes on Programming in Emacs Lisp (1)

2018/04/07

1. List processing

Open elisp REPL in Emacs: M-x ielm.

'(rose violet daisy buttercup)
'(rose (violet (daisy buttercup)))
(+ 2 2)
4
(+ (- 4 1) 1)
4

Some built-in variables: fill-column

(message "helo")
"helo"
(message "The name of this buffer %s" (buffer-name))
"The name of this buffer *scratch*"
;; using set (noted: both variable and value must be quoted unless you want otherwise)
(set 'flowers '(rose violet daisy buttercup))
;; (rose violet daisy buttercup)
;; using setq, automatically quoted the variables
(setq trees '(pine fir oak maple)
      herbivores '(gazelle antelope zebra))
(gazelle antelope zebra) ; last value is returned

2. Practicing Evaluation

This section for Emacs users.

;; get buffer name
(buffer-name)
"elisp-prog.el"

;; name of file associated with the buffer
(buffer-file-name)
"/home/anchu/elisp-prog.el"

;; get the buffer itself
(current-buffer)
#<buffer elisp-prog.el>

;; the most recently selected buffer
(other-buffer)
#<buffer *Messages*>

;; jump the other buffer
(switch-to-buffer (other-buffer))

;; number of characters in the buffer
(buffer-size)
1109

;; current position of cursor
(point)
1124

(point-max)
1143

(point-min)
1