branch: externals/org commit d3878cb6fe6b365972c73de55adb12e3d517dbb3 Author: Ihor Radchenko <yanta...@posteo.net> Commit: Ihor Radchenko <yanta...@posteo.net>
Consistently combine markup and the containing element faces during fontification * lisp/org-src.el (org-fontify-inline-src-blocks-1): * lisp/org.el (org-fontify-macros): * lisp/org.el (org-activate-footnote-links): (org-set-font-lock-defaults): Prepend faces during activation instead of overriding. Add a comment explaining the general rule how we combine faces. * etc/ORG-NEWS (Org mode faces are now consistently combined, with markup faces taking precedence over the containing element faces): Document the breaking change. Reported-by: StrawberryTea <l...@strawberrytea.xyz> Link: https://orgmode.org/list/875xy21e49.fsf@localhost --- etc/ORG-NEWS | 9 +++++++++ lisp/org-src.el | 18 ++++++------------ lisp/org.el | 55 ++++++++++++++++++++++++++++++++++--------------------- 3 files changed, 49 insertions(+), 33 deletions(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index ee2cdfd169..f8f21d573b 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -13,6 +13,15 @@ Please send Org bug reports to mailto:emacs-orgm...@gnu.org. * Version 9.7 (not released yet) ** Important announcements and breaking changes +*** Org mode faces are now consistently combined, with markup faces taking precedence over the containing element faces + +Previously, fontification of inline source blocks, macros, footnotes, +target links, timestamps, radio targets, targets, inline export +snippets, verbatim code, and COMMENT keyword in headings replaced the +containing element fontification. Now, this is changed - the inner +markup faces and the containing element faces are combined, with +"inner" faces taking precedence; just as for all other markup. + *** Built-in HTML, LaTeX, Man, Markdown, ODT, and Texinfo exporters preserve the link protocol during export Previously, some link types where not exported as =protocol:uri= but diff --git a/lisp/org-src.el b/lisp/org-src.el index bec13427c2..df1aff7398 100644 --- a/lisp/org-src.el +++ b/lisp/org-src.el @@ -778,12 +778,9 @@ as `org-src-fontify-natively' is non-nil." (lang-beg (match-beginning 1)) (lang-end (match-end 1)) pt) - (font-lock-append-text-property - lang-beg lang-end 'face 'org-meta-line) - (font-lock-append-text-property - beg lang-beg 'face 'shadow) - (font-lock-append-text-property - beg lang-end 'face 'org-inline-src-block) + (add-face-text-property beg lang-end 'org-inline-src-block) + (add-face-text-property beg lang-beg 'shadow) + (add-face-text-property lang-beg lang-end 'org-meta-line) (setq pt (goto-char lang-end)) ;; `org-element--parse-paired-brackets' doesn't take a limit, so to ;; prevent it searching the entire rest of the buffer we temporarily @@ -795,13 +792,11 @@ as `org-src-fontify-natively' is non-nil." (point))) (point-max)))) (when (ignore-errors (org-element--parse-paired-brackets ?\[)) - (font-lock-append-text-property - pt (point) 'face 'org-inline-src-block) + (add-face-text-property pt (point) 'org-inline-src-block) (setq pt (point))) (when (ignore-errors (org-element--parse-paired-brackets ?\{)) (remove-text-properties pt (point) '(face nil)) - (font-lock-append-text-property - pt (1+ pt) 'face '(org-inline-src-block shadow)) + (add-face-text-property pt (1+ pt) '(org-inline-src-block shadow)) (unless (= (1+ pt) (1- (point))) (if org-src-fontify-natively (org-src-font-lock-fontify-block @@ -809,8 +804,7 @@ as `org-src-fontify-natively' is non-nil." (1+ pt) (1- (point))) (font-lock-append-text-property (1+ pt) (1- (point)) 'face 'org-inline-src-block))) - (font-lock-append-text-property - (1- (point)) (point) 'face '(org-inline-src-block shadow)) + (add-face-text-property (1- (point)) (point) '(org-inline-src-block shadow)) (setq pt (point))))) t))) diff --git a/lisp/org.el b/lisp/org.el index f3fae134d9..58285f40b9 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -5654,9 +5654,10 @@ by a #." (match-string 1)) (let ((end (match-end 1)) (closing-start (match-beginning 1))) + (add-face-text-property begin end 'org-macro) (add-text-properties begin end - '(font-lock-multiline t font-lock-fontified t face org-macro)) + '(font-lock-multiline t font-lock-fontified t)) (org-remove-flyspell-overlays-in begin end) (when org-hide-macro-markers (add-text-properties begin opening-end '(invisible t)) @@ -5700,6 +5701,7 @@ by a #." (goto-char beg) (search-forward (or label "fn:")) (org-remove-flyspell-overlays-in beg (match-end 0)))) + (add-face-text-property beg end 'org-footnote) (add-text-properties beg end (list 'mouse-face 'highlight 'keymap org-mouse-map @@ -5707,8 +5709,7 @@ by a #." (if referencep "Footnote reference" "Footnote definition") 'font-lock-fontified t - 'font-lock-multiline t - 'face 'org-footnote)))))) + 'font-lock-multiline t)))))) (defun org-activate-dates (limit) "Add text properties for dates." @@ -5919,6 +5920,8 @@ needs to be inserted at a specific position in the font-lock sequence.") (defun org-set-font-lock-defaults () "Set font lock defaults for the current buffer." (let ((org-font-lock-extra-keywords + ;; As a general rule, we apply the element (container) faces + ;; first and then prepend the object faces on top. (list ;; Call the hook '(org-font-lock-hook) @@ -5942,21 +5945,22 @@ needs to be inserted at a specific position in the font-lock sequence.") (list org-property-re '(1 'org-special-keyword t) '(3 'org-property-value t)) - ;; Drawers + ;; Drawer boundaries. '(org-fontify-drawers) + ;; Diary sexps. + '("^&?%%(.*\\|<%%([^>\n]*?>" (0 'org-sexp-date t)) ;; Link related fontification. - '(org-activate-links) + '(org-activate-links) ; `org-activate-links' prepends faces (when (memq 'tag org-highlight-links) '(org-activate-tags (1 'org-tag prepend))) - (when (memq 'radio org-highlight-links) '(org-activate-target-links (1 'org-link t))) - (when (memq 'date org-highlight-links) '(org-activate-dates (0 'org-date t))) + (when (memq 'radio org-highlight-links) '(org-activate-target-links (1 'org-link prepend))) + (when (memq 'date org-highlight-links) '(org-activate-dates (0 'org-date prepend))) + ;; `org-activate-footnote-links' prepends faces (when (memq 'footnote org-highlight-links) '(org-activate-footnote-links)) ;; Targets. - (list org-radio-target-regexp '(0 'org-target t)) - (list org-target-regexp '(0 'org-target t)) - ;; Diary sexps. - '("^&?%%(.*\\|<%%([^>\n]*?>" (0 'org-sexp-date t)) + (list org-radio-target-regexp '(0 'org-target prepend)) + (list org-target-regexp '(0 'org-target prepend)) ;; Macro - '(org-fontify-macros) + '(org-fontify-macros) ; `org-fontify-macro' pepends faces ;; TODO keyword (list (format org-heading-keyword-regexp-format org-todo-regexp) @@ -5978,8 +5982,10 @@ needs to be inserted at a specific position in the font-lock sequence.") "\\)")) '(2 'org-headline-done prepend))) ;; Priorities + ;; `org-font-lock-add-priority-faces' prepends faces '(org-font-lock-add-priority-faces) ;; Tags + ;; `org-font-lock-add-tag-faces' prepends faces '(org-font-lock-add-tag-faces) ;; Tags groups (when (and org-group-tags org-tag-groups-alist) @@ -5987,12 +5993,13 @@ needs to be inserted at a specific position in the font-lock sequence.") (regexp-opt (mapcar 'car org-tag-groups-alist)) ":\\).*$") '(1 'org-tag-group prepend))) - ;; Special keywords + ;; Special keywords (as a part of planning) (list (concat "\\<" org-deadline-string) '(0 'org-special-keyword t)) (list (concat "\\<" org-scheduled-string) '(0 'org-special-keyword t)) (list (concat "\\<" org-closed-string) '(0 'org-special-keyword t)) (list (concat "\\<" org-clock-string) '(0 'org-special-keyword t)) ;; Emphasis + ;; `org-do-emphasis-faces' prepends faces (when org-fontify-emphasized-text '(org-do-emphasis-faces)) ;; Checkboxes `(,org-list-full-item-re 3 'org-checkbox prepend lax) @@ -6004,34 +6011,40 @@ needs to be inserted at a specific position in the font-lock sequence.") 1 'org-list-dt prepend) ;; Inline export snippets '("\\(@@\\)\\([a-z-]+:\\).*?\\(@@\\)" - (1 'font-lock-comment-face t) - (2 'org-tag t) - (3 'font-lock-comment-face t)) + (1 'font-lock-comment-face prepend) + (2 'org-tag prepend) + (3 'font-lock-comment-face prepend)) ;; ARCHIVEd headings (list (concat org-outline-regexp-bol "\\(.*:" org-archive-tag ":.*\\)") '(1 'org-archived prepend)) ;; Specials - '(org-do-latex-and-related) - '(org-fontify-entities) - '(org-raise-scripts) + '(org-do-latex-and-related) ; prepends faces + '(org-fontify-entities) ; applies composition + '(org-raise-scripts) ; applies display ;; Code - '(org-activate-code (1 'org-code t)) + '(org-activate-code (1 'org-code prepend)) ;; COMMENT (list (format "^\\*+\\(?: +%s\\)?\\(?: +\\[#[A-Z0-9]\\]\\)? +\\(?9:%s\\)\\(?: \\|$\\)" org-todo-regexp org-comment-string) - '(9 'org-special-keyword t)) + '(9 'org-special-keyword prepend)) ;; Blocks and meta lines + ;; Their face is an override - keywords, affiliated + ;; keywords, blocks, and block boundaries are all + ;; containers or part of container-only markup. '(org-fontify-meta-lines-and-blocks) + ;; `org-fontify-inline-src-blocks' prepends object boundary + ;; faces and overrides native faces. '(org-fontify-inline-src-blocks) ;; Citations. When an activate processor is specified, if ;; specified, try loading it beforehand. (progn (unless (null org-cite-activate-processor) (org-cite-try-load-processor org-cite-activate-processor)) + ;; prepends faces '(org-cite-activate)) '(org-activate-folds)))) (setq org-font-lock-extra-keywords (delq nil org-font-lock-extra-keywords))