EmacsTalk

使用 align-regexp 对齐 userscript 元信息

  tags: tips text

文章目录

有一个 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)
 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 brown

C-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

收听方式

反馈