如何在emacs中创建标题行?

时间:2013-10-21 18:45:42

标签: emacs

假设我有一行:

This is a title

我想强调这一行:

This is a title
===============

如果emacs中已经提供了此类功能的任何想法吗?

3 个答案:

答案 0 :(得分:2)

安装markdown-mode。它使用函数markdown-insert-title(绑定到 C-c C-t t )执行此操作。

修改:我还没有最新版本2.0,但如果我正确理解发行说明,则markdown-insert-title已重命名为markdown-insert-header-setext-1且其键绑定已包含已改为 Cc Ct!

答案 1 :(得分:2)

嘿,我很久以前就想这样,所以我写了一篇。我不知道它是否已经打包并以其他形式出现在那里。这是我的版本:

(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)))

只需将' - '更改为'=',它就可以做你想要的。

答案 2 :(得分:2)

WRT的可读性不是用最短的方式写的:

(defun underline ()
  (interactive "*")
  (let* ((len (- (line-end-position) (line-beginning-position)))
     (strg (make-string len ?\=)))
    (end-of-line)
    (insert "\n")
    (insert strg)))