使用 align-regexp 对齐 userscript 元信息

发布: 2021-07-26   上次更新: 2024-10-29   标签: tips text

文章目录

有一个 userscript,元信息对齐的不直观,不方便阅读,怎么办呢?

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
// ==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

解释上面的命令前先看下其签名:

1
(align-regexp BEG END REGEXP &optional GROUP SPACING REPEAT)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
// ==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==

最后,封装成一个函数

1
2
3
4
(defun my/align-userscript-metablock (start end)
  (interactive "r")
  (align-regexp start end
                "@[a-z]+\\(\\s-*\\)" 1 1 t))

练习

1
2
3
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

1
2
3
the    quick brown fox
jumped over  the   lazy
dogs   the   quick brown

参考



收听方式

反馈