次の行があるとします。
これはタイトルです
この行を次のように強調表示します。
これはタイトルです ===============
そのような機能がすでにemacsで利用可能である場合、何かアイデアはありますか?
次の行があるとします。
これはタイトルです
この行を次のように強調表示します。
これはタイトルです ===============
そのような機能がすでに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)))
「-」を「=」に変更するだけで、必要なことが行われます。
最短の方法で書かれていない可読性への WRT:
(defun underline ()
(interactive "*")
(let* ((len (- (line-end-position) (line-beginning-position)))
(strg (make-string len ?\=)))
(end-of-line)
(insert "\n")
(insert strg)))
markdown-modeをインストールします。markdown-insert-title
関数( にバインド) を使用してこれを行いますC-c C-t t。
編集: 最新のバージョン 2.0 はまだ持っていませんが、リリース ノートを正しく理解していれば、markdown-insert-title
名前がmarkdown-insert-header-setext-1
に変更され、キーバインドが に変更されましたC-c C-t !。