From ce5e8ecbb81ec24cc9f62d15ce56ccae5aedaf11 Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Fri, 31 Dec 2021 22:39:03 +0800 Subject: [PATCH] Prioritize underline over subscript inside parenthesis MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * lisp/org-element.el (org-element--object-lex): Prioritise underline parser over subscript. `org-element-underline-parser' is more strict compared to `org-element-subscript-parser'. * testing/lisp/test-org-element.el (test-org-element/underline-parser): Add test. * etc/ORG-NEWS (Underline syntax now takes priority over subscript when both are applicable): Announce the breaking change. Reported-by: Juan Manuel MacĂ­as Link: https://list.orgmode.org/87v8z52eom.fsf@posteo.net/T/#t --- etc/ORG-NEWS | 11 +++++++++++ lisp/org-element.el | 8 ++++---- testing/lisp/test-org-element.el | 11 ++++++++++- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index b71347145..a3015d9fc 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -13,6 +13,17 @@ Please send Org bug reports to mailto:emacs-orgmode@gnu.org. * Version 9.7 (not released yet) ** Important announcements and breaking changes +*** Underline syntax now takes priority over subscript when both are applicable + +Previously, Org mode interpreted =(_text_)= as subscript. +Now, the interpretation is changed to underline. + +=(_text_)= matches both subscript and underline markup. The +interpretation is changed to keep consistency with other emphasis like +=(*bold*)=. + +Most of the users should not be affected by this change - it only applies when character immediately preceding =_= is one of =-=, =(=, ='=, and ={=. + *** ~org-latex-to-mathml-convert-command~ and ~org-latex-to-html-convert-command~ may need to be adjusted Previously, =%i= placeholders in the diff --git a/lisp/org-element.el b/lisp/org-element.el index 5857bc63a..f4eec1695 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -5258,10 +5258,10 @@ to an appropriate container (e.g., a paragraph)." (pcase (char-after) (?^ (and (memq 'superscript restriction) (org-element-superscript-parser))) - (?_ (or (and (memq 'subscript restriction) - (org-element-subscript-parser)) - (and (memq 'underline restriction) - (org-element-underline-parser)))) + (?_ (or (and (memq 'underline restriction) + (org-element-underline-parser)) + (and (memq 'subscript restriction) + (org-element-subscript-parser)))) (?* (and (memq 'bold restriction) (org-element-bold-parser))) (?/ (and (memq 'italic restriction) diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el index e309ed97f..c49dc80d1 100644 --- a/testing/lisp/test-org-element.el +++ b/testing/lisp/test-org-element.el @@ -3306,7 +3306,16 @@ Outside list" (= 2 (org-test-with-temp-text "__test__" (length - (org-element-map (org-element-parse-buffer) 'underline 'identity)))))) + (org-element-map (org-element-parse-buffer) 'underline 'identity))))) + ;; Starting after non-blank + (should + (eq 'underline + (org-test-with-temp-text "(_underline_)" + (org-element-type (org-element-context))))) + (should-not + (eq 'underline + (org-test-with-temp-text "x_underline_)" + (org-element-type (org-element-context)))))) ;;;; Verbatim