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?
environment:
org-version is a variable defined in ‘org.el’. Its value is "9.3"
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.
Sign up to join this communityIt'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."
(interactive)
(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)
(save-excursion
(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))))
M-x toggle-debug-on-quit
, then when you press thatC-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).