emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Elecrtic-pair-mode works incorrectly in code blocks
@ 2024-09-30 17:31 the_wurfkreuz
  2024-10-11  4:16 ` Dilip via General discussions about Org-mode.
  2024-10-12  8:32 ` Ihor Radchenko
  0 siblings, 2 replies; 4+ messages in thread
From: the_wurfkreuz @ 2024-09-30 17:31 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org

[-- Attachment #1: Type: text/plain, Size: 726 bytes --]

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.

Emacs : GNU Emacs 31.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.43, cairo version 1.18.2)
of 2024-09-15
Package: Org mode version 9.8-pre (release_9.7.11-145-g28b631 @ /home/wurfkreuz/.source/org-mode/lisp/)

[-- Attachment #2: Type: text/html, Size: 1499 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Elecrtic-pair-mode works incorrectly in code blocks
  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
  1 sibling, 1 reply; 4+ messages in thread
From: Dilip via General discussions about Org-mode. @ 2024-10-11  4:16 UTC (permalink / raw)
  To: emacs-orgmode

Hi the_wurfkreuz,

I tried with the code block.

I confirm that it did not insert the closing bracket near those comment
blocks. But it did create pair brackets when I inserted after those 4
lines.

> #+begin_src emacs-lisp
   ( ### No closing bracket here
>   ;; (if (eq major-mode 'org-mode)
>   ;;     (org-cycle)
>   ;;   (yas-expand)))
>   ;;   ;; (my-completion-preview-insert)))
    () ### there was closing bracket here
> #+end_src

> Writing a closing bracket will make the cursor to jump to the next
> bracket.

I did not face this, writing closing bracket in first few lines anywhere
did not jump me, it inserted at point itself.

Although, I'd like to point that in ~org-edit-special~ the pairing works
as expected.

Emacs: GNU Emacs 31.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.43, cairo version 1.18.0)
Org: Org mode version 9.7.11 (9.7.11-6a5d0e @ /nix/store/8ci96509yzbng9nyb8wa9pfmp4ldmr2m-emacs-packages-deps/share/emacs/site-lisp/elpa/org-9.7.11/)

-- 
Best,
Dilip




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Elecrtic-pair-mode works incorrectly in code blocks
  2024-10-11  4:16 ` Dilip via General discussions about Org-mode.
@ 2024-10-11 18:19   ` Dilip via General discussions about Org-mode.
  0 siblings, 0 replies; 4+ messages in thread
From: Dilip via General discussions about Org-mode. @ 2024-10-11 18:19 UTC (permalink / raw)
  To: emacs-orgmode


Quoting the reply:

>> I confirm that it did not insert the closing bracket near those comment
>> blocks.

> So this is a bug that needs to fixed, isn't it?

I'm not sure if this is bug or intended near comment block or how org
handles/preserves the src block editing (indentation, pairs, other prog features)

-- 
Best,
Dilip



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Elecrtic-pair-mode works incorrectly in code blocks
  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-12  8:32 ` Ihor Radchenko
  1 sibling, 0 replies; 4+ messages in thread
From: Ihor Radchenko @ 2024-10-12  8:32 UTC (permalink / raw)
  To: the_wurfkreuz; +Cc: emacs-orgmode@gnu.org

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>


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-10-12  8:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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

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).