1

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). Commented May 30, 2019 at 12:27
  • @NickD Thanks. That kind sucks. I would imagine such delimiter is customizable. Commented 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. Commented 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. Commented 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. Commented May 31, 2019 at 5:55

2 Answers 2

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. Commented 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. Commented Jun 5, 2019 at 17:28
0

Based on the code by @Omar, I have this code in my emacs setup that auto-converts the Org format table to the GFM format each time I save the buffer.

The functions are declared (interactive) if you want to bind them to a key.

(defun modi/markdown-next-table () "Move point to the next table." (interactive) (when (markdown-table-at-point-p) (markdown-forward-paragraph)) (while (not (or (eobp) (markdown-table-at-point-p))) (let ((prev-pt (point))) (markdown-forward-paragraph) (backward-char) (when (eq prev-pt (point)) (markdown-forward-paragraph)))) (when (markdown-table-at-point-p) ;; Go to the beginning of the table. (markdown-backward-paragraph))) (defun modi/convert-tablefmt-to-gfm () "Convert the table format from Org to GFM." (interactive) (save-excursion (goto-char (point-min)) (while (not (eobp)) (modi/markdown-next-table) (let ((table-end (save-excursion (markdown-forward-paragraph) (point)))) (while (search-forward "-+-" table-end :noerror) (replace-match "-|-")))))) (defun modi/markdown-mode-customization () "My customization for `markdown-mode'." ;; Correct the table format. (add-hook 'before-save-hook #'modi/convert-tablefmt-to-gfm nil :local)) (add-hook 'markdown-mode-hook #'modi/markdown-mode-customization) 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.