其实很简单:

1
M-x flush-lines RET ^\s-*$ RET

什么?你还想要个函数?来,自行车给你:

1
(fset 'delete-empty-lines (kbd "M-x flush-lines RET ^\s-*$ RET"))

涉及的知识点看之前写的理解Emacs的键盘宏

至于里面正则用到的\sCODE形式,也是我记不住的一个地方(另外一个是Emacs正则里的category),所以也把它抄下来:

Whitespace characters: ‘ ’ or ‘-’
Word constituents: ‘w’
Symbol constituents: ‘_’
Punctuation characters: ‘.’
Open parenthesis characters: ‘(’
Close parenthesis characters: ‘)’
String quotes: ‘"’
Escape-syntax characters: ‘\’
Character quotes: ‘/’
Paired delimiters: ‘$’
Expression prefixes: ‘’’
Comment starters: ‘<’
Comment enders: ‘>’
Inherit standard syntax: ‘@’
Generic comment delimiters: ‘!’
Generic string delimiters: ‘|’

Table of Syntax Classes