0

The default column-delimiter for horizontal lines in tables is a + sign. How to change it to vertical bar |?

Currently, it looks likes this:

|---+---+---+---+---|
|   |   |   |   |   |
|---+---+---+---+---|
|   |   |   |   |   |
|---+---+---+---+---|
|   |   |   |   |   |

But I want it do be like this:

|---|---|---|---|---|
|   |   |   |   |   |
|---|---|---|---|---|
|   |   |   |   |   |
|---|---|---|---|---|
|   |   |   |   |   |
11
  • I'm not sure this is possible without changes to the code. If that is true and If you do change the code for yourself, you will make it impossible to share org documents with anybody else. You will also be saddled with a continuing maintenance problem, since you will have forked the upstream repo, unless you can convince the maintainers to make the change upstream (that is highly unlikely: there will be lots of current users who will object).
    – NickD
    May 30, 2019 at 12:27
  • @NickD Thanks. That kind sucks. I would imagine such delimiter is customizable.
    – rph
    May 30, 2019 at 14:38
  • As I said, that would make it so you couldn't share documents with anybody else unless they set the hypothetical option to exactly the same thing as you.
    – NickD
    May 30, 2019 at 16:51
  • 1
    It might be possible to use text faces to just change the appearance of the delimiter in your buffers if this is simply an aesthetic wish.
    – shoshin
    May 30, 2019 at 19:46
  • I wanted to follow the Markdown syntax for tables. Using the org-table delimiter mess up when I try to visualize it on GitHub for example.
    – rph
    May 31, 2019 at 5:55

1 Answer 1

1

You can use this function:

(defun toggle-table-org/gfm ()
  "Toggle table at point between Org Mode and GitHub-Flavored Markdown syntaxes."
  (interactive)
  (save-excursion
    (let ((table-end (progn
                       (markdown-forward-paragraph)
                       (point))))
      (markdown-backward-paragraph)
      (while (search-forward "-+-" table-end t)
        (replace-match "-|-"))
      (while (search-forward "-|-" table-end t)
        (replace-match "-+-")))))

By the way, I specifically chose to call the syntax "GitHub-Flavored Markdown", because table syntax varies a lot in different types of Markdown.

The function uses markdown-forward-paragraph which you have if you are editing your markdown in markdown-mode. If you don't use markdown-mode, let me know and we'll figure out how to implement it then.

2
  • I do use markdown-mode. I wouldn't want to have to call this script every time. But I guess this is the best solution we can get since there is no way to replace the delimiter for org-mode. Thanks a lot.
    – rph
    Jun 5, 2019 at 16:10
  • 1
    There is already something you do everytime: yank the table. You could modify the above function to yank the converted version instead.
    – Omar
    Jun 5, 2019 at 17:28

Your Answer

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

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