From d5413e772fe6aedb8a8aa094f98c96fc20b82d3a Mon Sep 17 00:00:00 2001 Message-Id: From: Ihor Radchenko Date: Fri, 19 Nov 2021 19:13:54 +0800 Subject: [PATCH] org.el: Make emphasis and link fontification consistent with parser * lisp/org.el (org-do-emphasis-faces): (org-activate-links): Do not fontify just based on approximate regexps. Make sure the current object is emphasis. --- lisp/org.el | 62 ++++++++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index cb1b58c51..d9f073100 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -5106,12 +5106,15 @@ (defun org-do-emphasis-faces (limit) (looking-at-p org-outline-regexp-bol)))) ;; Match full emphasis markup regexp. (looking-at (if verbatim? org-verbatim-re org-emph-re)) - ;; Do not span over paragraph boundaries. - (not (string-match-p org-element-paragraph-separate - (match-string 2))) - ;; Do not span over cells in table rows. - (not (and (save-match-data (org-match-line "[ \t]*|")) - (string-match-p "|" (match-string 4)))))) + ;; Verify that we are at the right object. + (let ((object (save-excursion + (save-match-data + (goto-char (match-beginning 2)) + (org-element-context))))) + (and (memq (org-element-type object) + '(bold italic verbatim code strike-through)) + (eq (match-beginning 2) + (org-element-property :begin object)))))) (pcase-let ((`(,_ ,face ,_) (assoc marker org-emphasis-alist)) (m (if org-hide-emphasis-markers 4 2))) (font-lock-prepend-text-property @@ -5206,7 +5209,7 @@ (defun org-activate-links (limit) (eq 'org-tag face)))))) (let* ((link-object (save-excursion (goto-char start) - (save-match-data (org-element-link-parser)))) + (save-match-data (org-element-context)))) (link (org-element-property :raw-link link-object)) (type (org-element-property :type link-object)) (path (org-element-property :path link-object)) @@ -5229,29 +5232,30 @@ (defun org-activate-links (limit) ((and (pred functionp) f) (funcall f)) (_ `(:uri ,link))) 'font-lock-multiline t))) - (org-remove-flyspell-overlays-in start end) - (org-rear-nonsticky-at end) - (if (not (eq 'bracket style)) - (progn + (when (eq (org-element-type link-object) 'link) + (org-remove-flyspell-overlays-in start end) + (org-rear-nonsticky-at end) + (if (not (eq 'bracket style)) + (progn + (add-face-text-property start end face-property) + (add-text-properties start end properties)) + ;; Handle invisible parts in bracket links. + (remove-text-properties start end '(invisible nil)) + (let ((hidden + (append `(invisible + ,(or (org-link-get-parameter type :display) + 'org-link)) + properties))) + (add-text-properties start visible-start hidden) (add-face-text-property start end face-property) - (add-text-properties start end properties)) - ;; Handle invisible parts in bracket links. - (remove-text-properties start end '(invisible nil)) - (let ((hidden - (append `(invisible - ,(or (org-link-get-parameter type :display) - 'org-link)) - properties))) - (add-text-properties start visible-start hidden) - (add-face-text-property start end face-property) - (add-text-properties visible-start visible-end properties) - (add-text-properties visible-end end hidden) - (org-rear-nonsticky-at visible-start) - (org-rear-nonsticky-at visible-end))) - (let ((f (org-link-get-parameter type :activate-func))) - (when (functionp f) - (funcall f start end path (eq style 'bracket)))) - (throw :exit t))))) ;signal success + (add-text-properties visible-start visible-end properties) + (add-text-properties visible-end end hidden) + (org-rear-nonsticky-at visible-start) + (org-rear-nonsticky-at visible-end))) + (let ((f (org-link-get-parameter type :activate-func))) + (when (functionp f) + (funcall f start end path (eq style 'bracket)))) + (throw :exit t)))))) ;signal success nil)) (defun org-activate-code (limit) -- 2.32.0