假设我有一条线:
这是一个标题
我想像这样突出显示这一行:
这是一个标题 ================
如果这些功能已经在 emacs 中可用,有什么想法吗?
呵呵,很久以前就想要了,所以写了一个。我不知道它是否已经打包并以另一种形式存在。这是我的版本:
(defun underline-previous-line ()
"Insert enough dashes on the current line to \"underline\" the line above the point.
Underline the line above the current point,
but don't underline any whitespace at the beginning of the line.
Delete the current line when made of whitespace and/or dashes."
(interactive)
(let ((p (point)))
(forward-line -1)
(if (looking-at "^\\([ \t]*\\).+$")
(progn
(goto-char p)
(beginning-of-line)
(let ((spaces (if (match-end 1) (- (match-end 1) (match-beginning 1)) 0)))
(insert (concat
(make-string spaces ?\ )
(make-string (- (match-end 0) (match-beginning 0) spaces) ?\-)
(save-match-data
(if (looking-at "^[- ]*-[- ]*$") ; need one dash
(delete-region (match-beginning 0) (match-end 0))
"\n")))))))
(goto-char p)
;; yes, next-line is what we want for intuitive cursor placement
;; a save-excursion makes life a little more difficult b/c the point
;; moves around oldly b/c of the insert
(next-line 1)))
只需将“-”更改为“=”,它就会做你想做的事。
安装降价模式。它使用函数markdown-insert-title
(绑定到C-c C-t t)执行此操作。
编辑:我还没有最新的 2.0 版本,但是如果我正确理解了发行说明,markdown-insert-title
它已被重命名为,markdown-insert-header-setext-1
并且它的键绑定已更改为C-c C-t !.
WRT 可读性不是最短的写法:
(defun underline ()
(interactive "*")
(let* ((len (- (line-end-position) (line-beginning-position)))
(strg (make-string len ?\=)))
(end-of-line)
(insert "\n")
(insert strg)))