使用 align-regexp 对齐 userscript 元信息
文章目录
有一个 userscript,元信息对齐的不直观,不方便阅读,怎么办呢?
1// ==UserScript==
2// @name Github Commented Issues
3// @namespace https://github.com/jiacai2050
4// @description Show your commented issues on github easily.
5// @match https://github.com/issues*
6// @author jiacai2050
7// @version 0.2.3
8// @icon https://github.githubassets.com/favicons/favicon.svg
9// @grant none
10// ==/UserScript==align-regexp to the resuce!
C-u M-x align-regexp RET @[a-z]+\(\s-*\) RET 1 RET 1 RET n
解释上面的命令前先看下其签名:
1(align-regexp BEG END REGEXP &optional GROUP SPACING REPEAT)- BEG/END 表示 region 的起始、结束位置
REGEXP 用以对齐的正则,至少包含一个 group 即
(),通过修改这个 group 来达到对齐的效果@[a-z]+\(\s-*\)这个正则表示用@name后的零或多个空格作为修改的 group\s-表示空格,具体语法可参考 Regexp-Backslash
- GROUP 标明正则式中哪个 group 用做修改来达到对齐效果
- SPACING 不同列之间的空格数
- REPEAT 是否作用在这一整行上,在本示例无所谓,因为最终只有两列
1// ==UserScript==
2// @name Github Commented Issues
3// @namespace https://github.com/jiacai2050
4// @description Show your commented issues on github easily.
5// @match https://github.com/issues*
6// @author jiacai2050
7// @version 0.2.3
8// @icon https://github.githubassets.com/favicons/favicon.svg
9// @grant none
10// ==/UserScript==最后,封装成一个函数
1(defun my/align-userscript-metablock (start end)
2 (interactive "r")
3 (align-regexp start end
4 "@[a-z]+\\(\\s-*\\)" 1 1 t))练习
1the quick brown fox
2jumped over the lazy
3dogs the quick brownC-u M-x align-regexp \(\s-*\)\s- RET 1 RET 0 RET y
1the quick brown fox
2jumped over the lazy
3dogs the quick brown收听方式

反馈
- 对节目有想法或发现内容错误?欢迎来信交流️