With help from commenters, I have things kind of working.

  • I removed :comments link from Properties.
  • I manually added comments to the top of every code block to replicate what :comments link would do.
  • I had to install modes for each language I was missing (lua, vimrc, maybe others?).

Now I can tangle in Doom Emacs or in default Emacs. I wish I could solve this without manually adding comments, but this is Good Enough®


In an org file, how do I define a comment syntax for lua and vimrc?


I am moving all my various config files into 1 org file. When trying to tangle it, I get a prompt "No comment syntax is defined. Use: " for each lua and vimrc code block. I don't want to have to specify this for every lua and vimrc code block I have, every time I tangle the file, for each block. I don't see a way to specify the comment syntax in the header, but that's the kind of solution I'm looking for.


I use Doom Emacs in case that's relevant. I'm experiencing this issue on two different machines.

Machine 1

  • OS: macOS 12.1
  • Emacs: GNU Emacs 27.2 (build 1, x86_64-apple-darwin18.7.0, Carbon Version 158 AppKit 1671.6) of 2021-03-27
  • Org Mode: Org mode version 9.6 (9.6-??-e7ea951ac)

Machine 2

I'm not on this machine at the moment so I'm only going by memory here, but I update my software about weekly.

  • OS: macOS 12.1
  • Emacs: 28.0.92
  • Org Mode: 9.6

Example org file

#+TITLE: Configs
#+PROPERTY: header-args :tangle yes :mkdirp yes :comments link :tangle-mode (identity #o444)

** Nvim
#+NAME: nvim_init
#+begin_src lua :tangle ~/.config/nvim/init.lua
vim.cmd('set runtimepath^=~/.vim runtimepath+=~/.vim/after')
-- etc

#+NAME: vimrc
#+begin_src vimrc :tangle ~/.vim/vimrc
set nocompatible
" etc
  • EDIT: Mar 25 Add Environment section
  • EDIT: Mar 26 Add Resolution section
  • 1
    Cannot reproduce on my side. What's your Emacs and Org version. Commented Mar 23, 2022 at 1:40
  • 1
    Cannot reproduce it either.
    – NickD
    Commented Mar 23, 2022 at 3:45
  • 1
    That message is used in function comment-normalize-vars. It would be interesting to find out how that gets called. You could instrument the function with e.,g. edebug and when execution stops in the function, you could get a backrace with d. That might (or might not) help with debugging the problem.
    – NickD
    Commented Mar 23, 2022 at 3:58
  • 2
    Emacs 28.0.92 Org 9.5.2. Can you reproduce with emacs -Q? If not, I thought you can raise an issue if you can reproduce this with empty doom config. Commented Mar 25, 2022 at 12:43
  • 1
    @Jason Sorry, I can reproduce now with the full example file. I didn't copy PROPERTY before, and I find out it is because you set :comment link and Emacs doesn't know the comment syntax for both modes. Commented Mar 26, 2022 at 12:14

1 Answer 1


I just stumbled upon this when writing a config file for which there is no existing major mode.

It looks like Doom Emacs uses the same code that's used by (comment-dmim) for org-babel-tangle. So to debug this, you could run with :comments none first, then open the generated file, verify that it has the correct major mode, then do M-x comment-dmim.

Installing LUA Mode in Doom Emacs

As it turns out, lua-mode is not installed by default in Doom Emacs and it's also not part of that template module list that's provided in the documentation.

However, installing it is quite easy by putting (package! lua-mode) into your packages.el and (use-package! lua-mode :defer t) into your config.el. I am using a literate config.org file, so here's how that looks like:

Install LUA mode.

#+begin_src emacs-lisp :tangle packages.el
(package! lua-mode)

#+begin_src emacs-lisp
(use-package! lua-mode
  :defer t)

I have the following at the top of my config.org, that's why the second code block doesn't need an explicit file name:

#+property: header-args:emacs-lisp :tangle config.el

Setting up vimrc should work the same way.

Manual setup for generic files

In case there isn't any existing major mode availabe, one thing you could do is to use text-mode and then explicitly configure the comment style for it.

It looks like all that's needed is to (setq-local comment-use-syntax nil) and `(setq-local comment-start "// ").

For instance, if you put this into foo.txt, load it with the local variables and then do M-x comment-dmim, it should work:

-*- mode: text; comment-use-syntax: nil; comment-start: "// " -*-


Custom Minor Mode

To make this work nicely in Org Mode, I simply defined a custom minor mode:

#+begin_src emacs-lisp
(define-minor-mode xkb-mode
  "Minor mode for editing XKB config files."
  :lighter nil
  (if xkb-mode
        (setq-local comment-use-syntax nil)
        (setq-local comment-start "// ")))

And then I can just do

#+begin_src xkb :tangle xkd-test
xkb_keycodes "moonlander" {
// Test comment.

As an added benefit of using the custom minor mode, you can then edit the code block via org-edit-special and use comment-dwim inside that buffer.

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.