Elisp
Contents
string
concat
|
|
equal
eq
|
|
equal
|
|
list
add-to-list
|
|
remove from list
|
|
switch
pcase
|
|
regex
match
|
|
non-greedy
use ?
|
|
defun
defun
define function1 2 3 4
(defun function-name (args) (interactive "...") ... )
- interactive code: reference
interactive
- 通过 interactive 可以把一个函数变成一个可交互的命令
- interactive 的命令才可以通过 M-x 执行, 类似把这个函数对用户 public
file
get parent directory
|
|
file name without suffix
|
|
lexical-binding
- with
;; -*- lexical-binding: t -*-
in the first line, emacs use lexical scope
Binding
- A binding is a correspondence between a name and its value.
In Lisp you can create a binding using ‘let’
a binding made by ‘let’ lasts until the end of the ‘let’ form.
1 2 3 4 5 6 7 8 9
(let ((a 1)) (let ((a 2)) (let ((a 3)) (print a)) (print a)) (print a)) ;; ==> 3 ;; 2 ;; 1
Dynamic Binding Vs Lexical Binding
- Lexical and dynamic binding refer to how variables are looked up by their names.
- Two regimes for handling variable binding emerged:
dynamic
- All variable names and their values live in one global table.
lexical
- Each binding scope (function, let syntax, …) creates a new table of variable names and values, organised in a hierarchy called “the environment”.
mode
major mode
get major mode
|
|
org-mode
get major mode keymap
|
|
keymap
create keymap
(make-keymap)
full keymap with nil binding(make-sparse-keymap)
empty keymap
|
|
suppress-keymap
changes the contents of the full keymap keymap by remapping self-insert-command to the command undefined
1 2 3 4
(let ((map (make-sparse-keymap))) (suppress-keymap map) (keymap-set map "q" 'quit-window) map)
unbind key
|
|
priority
- overriding-terminal-local-map
- overriding-local-map
- text property 'keymap
- emulation-mode-map-alists
- minor-mode-overriding-map-alist
- minor-mode-map-alist (Minor Mode)
- text property 'local-map
- (current-local-map) (Major Mode)
- (current-global-map) (Global Map)
minor-mode
check if active
|
|
list
range
|
|
in list
|
|
loop
dotimes
|
|
dolist
|
|
hotkeys
Keymap | Function |
---|---|
C-M-f | forward-sexp (coresponding bracket) |
C-M-b | backward-sexp (coresponding bracket) |
org-mode
Keymap | Function |
---|---|
C-c - | add - ahead of current line |
buffer & window
get
- 可以通过
(get-buffer BUFFER_NAME)
/(get-buffer-window
直接拿到buffer
/window
- 可以不存在的话是 nil
switch
- window 的话可以用 ace-window 的
aw-switch-to-window WINDOW_NAME
function
function | key | functionality |
file-exists-p | nil | file exisit |
file-name-directory | nil | get the directory of a file |
buffer-file-name | nil | current buffer/file name |
backward-up-list | C-M-u | upper level element (method -> class) |
GPG
keeping your secrets encrypted on your file system is an easy way of keeping your secrets secret
- Gpg(GNU Privacy Guard) is natively supported in emacs called EasyPG
- 只用一个gpg key管理所有加密文件和链接
- 可以不用每次输密码获取 root 权限
authinfo
auth-sources
变量指定 authinfo 文件格式
machine <HOST> login <ACCOUNT> port <PORT> password <PASSWORD>
- example
machine localhost login root port sudo password rootpasswd123
- example
- shell access
gpg2 -q --for-your-eyes-only --no-tty -d ~/.authinfo.gpg | sed -n 's,^machine gmail.com .*password \([^ ]*\).*,\1,p'
Creating a key
gpg --gen-key
font
describe char
- display current char info
|
|
align
- 第一次知道
C-u M-x
调用的命令跟直接M-x
调用的还是不一样的 C-u M-x align-regexp
使用的是更高级的align-regexp
- regexp: match the place you are interested in aligning; to do it, one of its parenthesis groups will be extended with spaces, or shortened by deleting characters
- parenthesis group: choose which one
- spacing: if the group is shorter than this, spaces will be added to it; if it's longer, characters will be deleted from it, starting at the end (unless it's longer for the purposes of alignment, of course)
- repeat: well, this is obvious, I think
- justify: non-blank characters inside the group won't be deleted, and necessary spaces will be added/deleted from the left. On your second case, try: regexp \([0-9]+\), group -1.
- column (instead of spacing): align to that fixed column (of course, it doesn't work well with “repeat”).
debug
debug function
M-x debug-on-entry
设置入口- 直接运行函数
cancel-debug-on-entry
keymap
Shortcut | Function |
---|---|
d | step through |
c | continue(step out) |
on error
|
|
bugs
poll freeze
|
|
- disable XIM (maybe) ref: https://gitlab.freedesktop.org/xorg/lib/libx11/-/issues/35
search by value
apropos-value
package
unload
|
|