有一个 userscript,元信息对齐的不直观,不方便阅读,怎么办呢?
// ==UserScript==
// @name Github Commented Issues
// @namespace https://github.com/jiacai2050
// @description Show your commented issues on github easily.
// @match https://github.com/issues*
// @author jiacai2050
// @version 0.2.3
// @icon https://github.githubassets.com/favicons/favicon.svg
// @grant none
// ==/UserScript==
align-regexp
to the resuce!
C-u M-x align-regexp RET @[a-z]+\(\s-*\) RET 1 RET 1 RET n
解释上面的命令前先看下其签名:
(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 是否作用在这一整行上,在本示例无所谓,因为最终只有两列
// ==UserScript==
// @name Github Commented Issues
// @namespace https://github.com/jiacai2050
// @description Show your commented issues on github easily.
// @match https://github.com/issues*
// @author jiacai2050
// @version 0.2.3
// @icon https://github.githubassets.com/favicons/favicon.svg
// @grant none
// ==/UserScript==
最后,封装成一个函数
(defun my/align-userscript-metablock (start end)
(interactive "r")
(align-regexp start end
"@[a-z]+\\(\\s-*\\)" 1 1 t))
练习
the quick brown fox
jumped over the lazy
dogs the quick brown
C-u M-x align-regexp \(\s-*\)\s- RET 1 RET 0 RET y
the quick brown fox
jumped over the lazy
dogs the quick brown