1

Consider the following piece of text (in whatever general major mode it may be):

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur.

```
function foo()
    println("Hello World")
    println("Don't fill me please!")
end
```

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur.

The idea is that I want triple backticks to serve as delimiters for regions of the text that I would like to not fill. I am using the filladapt mode and right now executing fill-paragraph with the cursor in the "code block" region causes a fill:

```
function foo()
    println("Hello World") println("Don't fill me please!")
end
```

I would like to specify that all blocks of text inside triple backticks should be left verbatim - not filled, not touched in any way at all by the fill algorithm. Is this possible? Preferrably in filladapt since I am using it already.

2

Polymode

Polymode might serve your purpose here. It supports editing documents that combine code in different languages. It does a lot more than just let you tweak autofilling, so it might be worth spending a bit of time to investigate.

Basically, it allows you to edit your document in one major mode, and seamlessly switch to a different major mode when editing code blocks. You can then turn auto-fill on in your 'host mode', and turn it off for the 'inner mode'. At the same time, you get the syntax highlighting and keyboard shortcuts you normally use for editing your code, without requiring you to use the same shortcuts and highlighting for the surrounding text.

Your example looks like a markdown document with a code block in programming language. There may already be a polymode for this combination - Poly-markdown already exists, and can be combined with Poly-R to get support for R code in markdown code blocks, for example. If the appropriate combination doesn't exist, it's relatively easy to make your own. The polymode manual is the best place to get started.

Orgmode

As NickD points out, you can also use orgmode in this way. This has a few additional limitations, but also gives you access to a whole ecosystem of tools built into the orgmode system.

The primary 'limitation' with orgmode, compared to polymode, is that the main document has to be in org format. This is similar to markdown, and easily exported to html, latex/pdf, odt etc. It also has a lot more features for task management, scheduling (and a lot more).

You don't need to use all those features. The one you'll be interested in will be code blocks. You won't be able to use arbitrary delimiters, (i.e., triple backticks), you'll have to use the slightly more verbose orgmode style:

#+begin_src LANG
function foo()
    println("Hello World")
    println("Don't fill me please!")
end
#+end_src

The advantage here is that you can include code blocks of most (all?) languages in the same document, so long as there's an Emacs mode for editing them. You get the same syntax highlighting support as in polymode. You don't get the seamless editing, but it's almost as good. There's a shortcut key for creating a temporary buffer for editing your code in its 'normal' mode, and then returning to your org document.

Both approaches are rather involved for your simple question. But if you do a lot of mixed-language editing I think it's worthwhile to learn one or the other, or both.

If you mostly use the same two languages, and especially if you have collaborators who don't use Emacs but want to edit your documents, I would recommend polymode. That's what I use for RMarkdown (markdown with R code blocks).

Orgmode is much more powerful and flexible, but it requires that you adopt the org format, and it won't be as easy to share with non-Emacs users. I use this for files that only I will edit, especially when I'm mixing more than two languages into a document.

2
  • 2
    As a more specialized solution, the OP might want to investigate the "Literate Programming" features that are built into Org mode.
    – NickD
    Apr 30 at 17:04
  • 1
    Good point @NickD. I updated my answer
    – Tyler
    Apr 30 at 18:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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