2013-10-21 34 views
1

假设我有一句台词:如何在emacs中创建标题行?

 
This is a title 

我想强调此行是这样的:

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

任何想法,如果这样的功能是在emacs中已经可用?

+0

这是在任何特定的上下文;模式,文件类型,何时,何处等?或者,这是否涉及我尚未见过的emacs的某些区域。 – ArniDat

+0

我写了纯文本文件,我想用ASCII字体突出显示标题的印象。 – pyfex

回答

2

WRT可读性不写的最短途径:

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

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

编辑:我没有最新的2.0版本还没有,但如果我理解正确的释放指出,markdown-insert-title已更名为markdown-insert-header-setext-1和按键绑定已更改为C-C C-T!

+0

不错的模式。但是,markdown-insert-title仅插入一行10 = s的行,而不是标题所具有的行数。 – pyfex

+0

@pyfex:如果你有一个活动区域,它将使用与你所选择的'='一样多的数字,只有当你没有选择的情况下使用该功能时,固定长度才会出现。 –

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

只需将' - '更改为'=',它会做你想做的。