0

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?

1 Answer 1

1

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.