1

For example, I would like to use orgtbl-mode in the comments instead of org-mode as follows, even in ruby-mode, etc.

# |----+--------|
# | id | name   |
# |----+--------|
# |  1 | alice  |
# |  2 | bob    |
# |----+--------|
// |----+--------|
// | id | name   |
// |----+--------|
// |  1 | alice  |
// |  2 | bob    |
// |----+--------|

At present, (orgtbl-mode) is executed and it works when minor mode is introduced, but the table must be uncommented before every change and commented again afterwards.

I wondered if orgtbl-line-start-regexp was involved, so I changed it in various ways, but it didn't work well.

2
  • 1
    You probably already know this, but just to point out to others, a heavyweight way of doing this would be to do literate programming in Org mode itself, where everything outside of the blocks of code (including Org tables) is/can be exported as comments. May 7 at 11:53
  • Bind orgtbl-toggle-comment to a key to make it easy to uncomment/comment the table?
    – NickD
    May 7 at 12:16

1 Answer 1

4

Use M-x orgtbl-toggle-comment to uncomment the table, make your changes and do the same command to comment the table again. Typing all that is a bit tedious of course but you can bind the command to a key, e.g.

(global-set-key (kbd "C-c c") #'orgtbl-toggle-comment)

assuming C-c c is undefined (otherwise use some other such combination that is reserved for users).

Then the process is just C-c c, make changes to the table, C-c c.

BTW, I found this by using the awesome Emacs documentation features: C-h i g(org)i orgtbl mode RET and then clicking on the Tables in arbitrary syntax link takes you to the section that describes how to use it (including examples). The Radio tables subsection contains a few methods you can use to manage such tables for various comment conventions, including the orgtbl-toggle-comment method.

3
  • 1
    You are welcome. Please visit the Help Center by clicking on the ? icon in the upper right to find out how the site operates. In particular, read What to do if someone answers my question.
    – NickD
    May 8 at 8:27
  • I looked at the package and I cannot tell what it does by its description - but I have not tried it out. If you think it's a better way to solve your problem, you should write up your own answer (perhaps describing what it does exactly) and you can then accept it (yes, you can accept your own answer). The important thing is that there is an answer (or more than one) and that the answer that you think best solves your problem is marked accepted.
    – NickD
    May 10 at 5:55
  • Also, if somebody (could be you, could be somebody else, it could even be me) comes up with a better answer, you can unmark this answer as accepted and accept the better one. The Help Center describes all these possibilities.
    – NickD
    May 10 at 6:49

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.