For example, write only one line in foo.org.

| a |

So if execute M-x orgtbl-toggle-comment, it will freeze. (can stop with C-g)

Is there a way to solve this?


org-version is a variable defined in ‘org.el’. Its value is "9.3"

  • If you M-x toggle-debug-on-quit, then when you press that C-g, you would get a backtrace, which would allow you to debug the problem (I assume that's how @matteol found the problem to come up with the fixed version in the answer below).
    – NickD
    May 8 at 8:15

1 Answer 1


It's a bug in orgtbl-toggle-comment that gets stuck on the line

(while (looking-at re) (beginning-of-line 0))

if the table is on the first line of the buffer. You can use the following patched definition of the function. I'll submit a bug report to org.

(defun orgtbl-toggle-comment ()
  "Comment or uncomment the orgtbl at point."
  (let* ((case-fold-search t)
     (re1 (concat "^" (regexp-quote comment-start) orgtbl-line-start-regexp))
     (re2 (concat "^" orgtbl-line-start-regexp))
     (commented (save-excursion (beginning-of-line 1)
                    (cond ((looking-at re1) t)
                      ((looking-at re2) nil)
                      (t (user-error "Not at an org table")))))
     (re (if commented re1 re2))
     beg end)
      (beginning-of-line 1)
      (while (and (looking-at re) (not (eql (point) (point-min))))
        (beginning-of-line 0))
      (unless (looking-at re) (beginning-of-line 2))
      (setq beg (point))
      (while (looking-at re) (beginning-of-line 2))
      (setq end (point)))
    (comment-region beg end (if commented '(4) nil))))
  • I guess it does not make much difference, but why eql and not =?
    – NickD
    May 8 at 8:29
  • @NickD I always forget = exists
    – matteol
    May 8 at 8:36
  • 1
    @megeton: if this answered your question, please accept the answer. That's how the site is supposed to work: accepting an answer makes it clear to whoever has the same question in the future that there is at least one answer that resolved the problem.
    – NickD
    May 8 at 23:47

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.