commit 44f9859cf12641ef81f4706dcc09d9f917b9a689
parent a82cad065d36043ce009ed621651446312ecb77c
Author: Anton Konyahin <me@konyahin.xyz>
Date: Wed, 5 Apr 2023 22:15:11 +0300
emacs: rename md buffers to their header
Diffstat:
1 file changed, 13 insertions(+), 0 deletions(-)
diff --git a/emacs/.emacs.d/init.el b/emacs/.emacs.d/init.el
@@ -37,6 +37,19 @@
(require 'markdown-mode)
(add-hook 'markdown-mode-hook 'auto-fill-mode)
(add-hook 'markdown-mode-hook 'flyspell-mode)
+
+(defun knh-set-buffer-name-md ()
+ "Rename md buffer to their header"
+ (interactive)
+ (save-excursion
+ (beginning-of-buffer)
+ (search-forward "# ")
+ (let ((beg (point)))
+ (move-end-of-line nil)
+ (rename-buffer
+ (string-trim (buffer-substring beg (point)))))))
+(add-hook 'markdown-mode-hook 'knh-set-buffer-name-md)
+
(define-key markdown-mode-map (kbd "M-<up>") 'markdown-previous-visible-heading)
(define-key markdown-mode-map (kbd "M-<down>") 'markdown-next-visible-heading)