emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Elecrtic-pair-mode works incorrectly in code blocks


From: Ihor Radchenko
Subject: Re: Elecrtic-pair-mode works incorrectly in code blocks
Date: Sat, 12 Oct 2024 08:32:31 +0000

the_wurfkreuz <the_wurfkreuz@proton.me> writes:

> Reproduction:
>
> 1. emacs -Q
> 2. In the scratch buffer enable to org-mode.
> 3. Enable electric-pair-mode.
> 4. Paste this code:
>
> #+begin_src emacs-lisp
>
> ;; (if (eq major-mode 'org-mode)
> ;; (org-cycle)
> ;; (yas-expand)))
> ;; ;; (my-completion-preview-insert)))
>
> #+end_src
>
> 5. Then in the first line of the code block try to insert an opening
> bracket - '('. It wont be closed. Writing a closing bracket will make
> the cursor to jump to the next bracket. At the same time i don't have
> such problem outside of org-mode.

There is no bug here.
Org mode does not provide support for src-block rules when completing
the pairs. In other words, electric-pair-mode has no idea about Elisp
syntax rules in this context. Instead, only Org mode markup rules are
used, treating parenthesis more or less like in plain text.

The behavior you are observing happens because

> ;; (if (eq major-mode 'org-mode)
> ;; (org-cycle)
> ;; (yas-expand)))

has trailing unbalanced ), which means that inserting ( before will make
the following parenthesis balanced (again, electric-pair-mode has no
idea that ;; means comment here).

In contrast, when inserting ( after the comment, there no other )
present in the Org file afterward, so electric-pair-mode does close the
input with ().

Of course, it would be nice to make electric-pair-mode aware of src
block syntax in addition to native Org syntax. For example, this can be
done by applying src-block-specific syntax-table text property just for
src-block.

I did try implementing exactly this as a feature, but, unfortunately,
local syntax tables break some parts of Org mode's own parser, opening a
whole can of worms. So, adding the feature you expected to see is not
trivial.

Patches welcome though, if someone is dare enough to dive into fixing
Org mode syntax reliance upon very specific syntax table.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]