EmacsTalk

使用 align-regexp 对齐 userscript 元信息

  tags: tips text

文章目录

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

收听方式

反馈