From 715927aa2f1baae32040e52d2cfca4aef2edc14b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Le=20Gouguec?= Date: Fri, 7 Aug 2020 11:04:53 +0200 Subject: [PATCH] Fix org-fontify-whole-*-line by setting face extension (bug#42184) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * lisp/org-faces.el (org-block): Set background extension beyond end-of-line. * lisp/org-compat.el (org--extended-face): New function to add :extend attribute to face definition for Emacs≥27. (org--set-faces-extend): New function to temporarily (re)set :extend for Emacs≥27. * lisp/org.el (org-mode): Call it to set the extend attribute of relevant faces to the correct value. --- lisp/org-compat.el | 15 +++++++++++++++ lisp/org-faces.el | 2 +- lisp/org.el | 6 +++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lisp/org-compat.el b/lisp/org-compat.el index 5953f89d2..a9cf400a7 100644 --- a/lisp/org-compat.el +++ b/lisp/org-compat.el @@ -109,6 +109,21 @@ is nil)." (newline-and-indent)) (defalias 'org-newline-and-indent #'newline-and-indent)) +(defmacro org--extended-face (attributes) + "Make face that extends beyond end of line. + +Up to Emacs 26, all faces extended beyond end of line; getting +the same behaviour starting with Emacs 27 requires :extend t." + `(nconc ,attributes (when (>= emacs-major-version 27) '(:extend t)))) + +(defun org--set-faces-extend (faces extend-p) + "Set the :extend attribute of FACES to EXTEND-P. + +This is a no-op for Emacs versions lower than 27, since face +extension beyond end of line was not controllable." + (when (fboundp 'set-face-extend) + (mapc (lambda (f) (set-face-extend f extend-p)) faces))) + ;;; Emacs < 26.1 compatibility diff --git a/lisp/org-faces.el b/lisp/org-faces.el index d78b606ec..0c7de38ff 100644 --- a/lisp/org-faces.el +++ b/lisp/org-faces.el @@ -408,7 +408,7 @@ follows a #+DATE:, #+AUTHOR: or #+EMAIL: keyword." "Face for #+TITLE:, #+AUTHOR:, #+EMAIL: and #+DATE: keywords." :group 'org-faces) -(defface org-block '((t :inherit shadow)) +(defface org-block `((t ,(org--extended-face '(:inherit shadow)))) "Face text in #+begin ... #+end blocks. For source-blocks `org-src-block-faces' takes precedence." :group 'org-faces diff --git a/lisp/org.el b/lisp/org.el index ee8be256d..d66977dd4 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -4904,7 +4904,11 @@ The following commands are available: ;; Try to set `org-hide' face correctly. (let ((foreground (org-find-invisible-foreground))) (when foreground - (set-face-foreground 'org-hide foreground)))) + (set-face-foreground 'org-hide foreground))) + ;; Set face extension as requested. + (org--set-faces-extend '(org-block-begin-line org-block-end-line) + org-fontify-whole-block-delimiter-line) + (org--set-faces-extend org-level-faces org-fontify-whole-heading-line)) ;; Update `customize-package-emacs-version-alist' (add-to-list 'customize-package-emacs-version-alist -- 2.28.0