emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@posteo.net>
To: the_wurfkreuz <the_wurfkreuz@proton.me>
Cc: "emacs-orgmode@gnu.org" <emacs-orgmode@gnu.org>
Subject: Re: Elecrtic-pair-mode works incorrectly in code blocks
Date: Sat, 12 Oct 2024 08:32:31 +0000	[thread overview]
Message-ID: <871q0lu3fk.fsf@localhost> (raw)
In-Reply-To: <FXM2VZuwpiwURtnPBGKJmafdNYRRUZ0UuRUX6jrlVmXD_sw5e5w8sBvF316gyQWTSZ_RVB1EH7VBrY3u4KXZXixWbk_sWBRIwm0vgCIbhGQ=@proton.me>

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>


      parent reply	other threads:[~2024-10-12  8:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-30 17:31 Elecrtic-pair-mode works incorrectly in code blocks the_wurfkreuz
2024-10-11  4:16 ` Dilip via General discussions about Org-mode.
2024-10-11 18:19   ` Dilip via General discussions about Org-mode.
2024-10-12  8:32 ` Ihor Radchenko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871q0lu3fk.fsf@localhost \
    --to=yantar92@posteo.net \
    --cc=emacs-orgmode@gnu.org \
    --cc=the_wurfkreuz@proton.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).