emacs elisp
(global-set-key (kbd "<f1>") 'my-func)
(add-hook 'emacs-lisp-mode-hook 'show-paren-mode) 在lisp-mode里打开paren-mode
(defun indent-buffer()
(interactive)
(indent-region (point-min) (point-max)))
(defun indent-region-or-buffer ()
(interactive)
(save-excursion
(if (region-active-p)
(progn
(indent-region (region-beginning) (region-end))
(message "Indented selected region."))
(progn
(indent-buffer)
(message "Indented buffer.")))))
(global-set-key (kbd "C-M-\\") 'indent-region-or-buffer)
每个lisp函数要么返回错误消息,要么返回一个值,可以有一个附带效果,例如“赋值”
(set 'a '(1 2 3))
(setq a 1 b 2) setq自动将第1个参数前面加引号 且可以给多个键值对赋值
C-u C-x C-e在光标后面显示结果
(buffer-name) 返回当前buffer的名字
(buffer-file-name) 返回当前buffer的文件的名字
(current-buffer) 返回当前buffer
(other-buffer) 最近使用的buffer
(switch-to-buffer (other-buffer))
(set-buffer)
(buffer-size)
(mark-whole-buffer)
通过C-u 2 M-x abc 给函数abc传递一个前缀参数2
(interactive "p") 交互式函数 p表示接受一个数字作为前缀参数 r接受位点和标记 f文件名 b缓冲区名
(save-excursion ...) 保存并恢复光标位置
(point) 光标位点 即buffer开头到光标处的字符数 或者光标所在字符为第几个字符
(point-min) (point-max) buffer中位点的最小/大可能值 通常point-min就是1
(push-mark) 标记 C-SPC设置一个标记 多次按C-u C-SPC跳到之前标记的位置
C-x C-x(exchange-point-and-mark)
位点和标记之间成为域(region)
(defun append-to-buffer (buffer start end)
(interactive "BAppend to buffer: \nr")
(let ((oldbuf (current-buffer)))
(save-excursion
(set-buffer (get-buffer-create buffer))
(insert-buffer-substring oldbuf start end))))
lisp有<=