I want to use auto-fill-mode
in Markdown files. By default, it works fine, with one exception. I'm using the RMarkdown variant of markdown. This requires that code block headers remain on one line. They are frequently much longer than my fill-column, so if I use auto-fill
, they get wrapped. How can I exclude these lines from getting filled?
Add a comment
|
1 Answer
auto-fill-mode
refers to the variable auto-fill-function
to determine how to fill lines. auto-fill-function
is always a local variable, making it easy to define your own function for any mode you like. To solve my own problem, I use the following:
(defun tws-markdown-auto-fill ()
(auto-fill-mode)
(setq auto-fill-function 'tws-markdown-fill-function))
(defun tws-markdown-fill-function ()
(unless
(save-excursion
(beginning-of-line)
(looking-at "```{"))
(do-auto-fill)))
(add-hook 'markdown-mode-hook 'tws-markdown-auto-fill)