2013-10-21 31 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))) 

只需將' - '更改爲'=',它會做你想做的。