emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: the_wurfkreuz <the_wurfkreuz@proton.me>
To: "emacs-orgmode@gnu.org" <emacs-orgmode@gnu.org>
Subject: [BUG] Incorrect application of 'comment-region' in code blocks
Date: Sat, 13 Jul 2024 07:32:04 +0000	[thread overview]
Message-ID: <tA2VeQZNq2sUAadeIoxtM2j1yRVm0Zb-g0zRuMpZESm5Owe3jG_FcXxeU7hbmXq3W_T6JvFVz_-l3b9Gww6jo5XfdPc0jHcgmRplwQ78Ayk=@proton.me> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 3942 bytes --]

Reproduction:

1. emacs -Q
2. Enable org-mode in the scratch buffer (M-x org-mode)
3. Paste this code:

#+begin_src emacs-lisp

(with-eval-after-load 'evil
(define-key evil-insert-state-map (kbd "C-S-v") 'yank)
(define-key evil-visual-state-map (kbd "{") 'evil-backward-paragraph)
(define-key evil-visual-state-map (kbd "}") 'evil-forward-paragraph)
(define-key evil-insert-state-map (kbd "M-w") 'evil-forward-word-begin)
(define-key evil-insert-state-map (kbd "M-b") 'evil-backward-word-begin)
(define-key evil-insert-state-map (kbd "M-W") 'evil-forward-WORD-begin)
(define-key evil-insert-state-map (kbd "M-B") 'evil-backward-WORD-begin)

(define-key evil-normal-state-map (kbd "gq") 'FormatToThreshold)
(define-key evil-visual-state-map (kbd "gq") 'FormatToThreshold))

(defun my-move-beginning-of-line ()
"Move point to the first non-whitespace character of the line and enter insert mode."
(interactive)
(evil-first-non-blank)
(evil-insert-state))

#+end_src

(with-eval-after-load 'evil
(define-key evil-insert-state-map (kbd "C-S-v") 'yank)
(define-key evil-visual-state-map (kbd "{") 'evil-backward-paragraph)
(define-key evil-visual-state-map (kbd "}") 'evil-forward-paragraph)
(define-key evil-insert-state-map (kbd "M-w") 'evil-forward-word-begin)
(define-key evil-insert-state-map (kbd "M-b") 'evil-backward-word-begin)
(define-key evil-insert-state-map (kbd "M-W") 'evil-forward-WORD-begin)
(define-key evil-insert-state-map (kbd "M-B") 'evil-backward-WORD-begin)

(define-key evil-normal-state-map (kbd "gq") 'FormatToThreshold)
(define-key evil-visual-state-map (kbd "gq") 'FormatToThreshold))

(defun my-move-beginning-of-line ()
"Move point to the first non-whitespace character of the line and enter insert mode."
(interactive)
(evil-first-non-blank)
(evil-insert-state))

4. Highlight the first code paragrapth in the org code block:

(with-eval-after-load 'evil
(define-key evil-insert-state-map (kbd "C-S-v") 'yank)
(define-key evil-visual-state-map (kbd "{") 'evil-backward-paragraph)
(define-key evil-visual-state-map (kbd "}") 'evil-forward-paragraph)
(define-key evil-insert-state-map (kbd "M-w") 'evil-forward-word-begin)
(define-key evil-insert-state-map (kbd "M-b") 'evil-backward-word-begin)
(define-key evil-insert-state-map (kbd "M-W") 'evil-forward-WORD-begin)
(define-key evil-insert-state-map (kbd "M-B") 'evil-backward-WORD-begin)

5. Execute 'comment-region'. It will apply partial commenting on the
next line like this:

;; (with-eval-after-load 'evil
;; (define-key evil-insert-state-map (kbd "C-S-v") 'yank)
;; (define-key evil-visual-state-map (kbd "{") 'evil-backward-paragraph)
;; (define-key evil-visual-state-map (kbd "}") 'evil-forward-paragraph)
;; (define-key evil-insert-state-map (kbd "M-w") 'evil-forward-word-begin)
;; (define-key evil-insert-state-map (kbd "M-b") 'evil-backward-word-begin)
;; (define-key evil-insert-state-map (kbd "M-W") 'evil-forward-WORD-begin)
;; (define-key evil-insert-state-map (kbd "M-B") 'evil-backward-WORD-begin)

;; (define-key e
vil-normal-state-map (kbd "gq") 'FormatToThreshold)

6. Now apply highlighting and comment the same code, but outside of the
org code block, and the end result will be correct:

# (with-eval-after-load 'evil
# (define-key evil-insert-state-map (kbd "C-S-v") 'yank)
# (define-key evil-visual-state-map (kbd "{") 'evil-backward-paragraph)
# (define-key evil-visual-state-map (kbd "}") 'evil-forward-paragraph)
# (define-key evil-insert-state-map (kbd "M-w") 'evil-forward-word-begin)
# (define-key evil-insert-state-map (kbd "M-b") 'evil-backward-word-begin)
# (define-key evil-insert-state-map (kbd "M-W") 'evil-forward-WORD-begin)
# (define-key evil-insert-state-map (kbd "M-B") 'evil-backward-WORD-begin)

Emacs : GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.41, cairo version 1.18.0)
of 2024-04-23
Package: Org mode version 9.8-pre (release_9.7.6-101-g4f6aab @ /home/wurfkreuz/.emacs.d/straight/build/org/)

[-- Attachment #1.2: Type: text/html, Size: 6773 bytes --]

[-- Attachment #2: emacs1.png --]
[-- Type: image/png, Size: 48674 bytes --]

[-- Attachment #3: emacs2.png --]
[-- Type: image/png, Size: 46624 bytes --]

[-- Attachment #4: emacs3.png --]
[-- Type: image/png, Size: 102469 bytes --]

             reply	other threads:[~2024-07-13  7:33 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-13  7:32 the_wurfkreuz [this message]
2024-07-13 13:29 ` [BUG] Incorrect application of 'comment-region' in code blocks Ihor Radchenko
     [not found]   ` <HCkTNlq00DJCqKYbN1PPA5smHPuiAmGGuHdg_PffhnW1JiIddRvs976pxnd2Sp2cVBE__yeAKlhzUTGuIUU-jubuN7Yb-rf54EAxPuouJ78=@proton.me>
2024-07-13 16:15     ` Ihor Radchenko

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='tA2VeQZNq2sUAadeIoxtM2j1yRVm0Zb-g0zRuMpZESm5Owe3jG_FcXxeU7hbmXq3W_T6JvFVz_-l3b9Gww6jo5XfdPc0jHcgmRplwQ78Ayk=@proton.me' \
    --to=the_wurfkreuz@proton.me \
    --cc=emacs-orgmode@gnu.org \
    /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).