emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Protesilaos Stavrou <info@protesilaos.com>
To: emacs-orgmode@gnu.org
Subject: [PATCH] Fixed-pitch tables and code blocks that do not break variable-pitch-mode
Date: Wed, 09 Sep 2020 17:18:18 +0300	[thread overview]
Message-ID: <875z8njaol.fsf@protesilaos.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 2802 bytes --]

Hello everyone,

Please see the attached diff.  An explanation is offered below.  I have
already assigned copyright to the FSF.


The problem
-----------

Running 'M-x variable-pitch-mode' in an Org buffer will make all
space-sensitive constructs lose their alignment.  This is particularly
problematic for (1) tables, whose tabular looks are functionally
significant, and (2) for code blocks that are meant to display
programming code where the visual effects of indentation can have
important implications.

Note that 'variable-pitch-mode' effectively remaps the 'default' face to
'variable-pitch', meaning that the former inherits the font family of
the latter.


A possible solution (scope of this patch)
-----------------------------------------

Emacs provides the generic 'fixed-pitch' face.  The idea with this is to
always define it as having a monospaced font family (its default state).
Other faces may thus inherit from it.  We can apply this face to all
constructs that we always want to keep in fixed width spacing.  Tables,
code blocks, and faces related to them are the obvious candidates,
covered by this patch, though the principle could be extended to other
items as well (see ANNEX 1).

By making some faces inherit from fixed-pitch, we guarantee that users
who activate 'variable-pitch-mode' will get variable width fonts for
their main text and also retain the necessary fixed width proportions of
some constructs that make Org look good and work well.

The attached screenshot shows how this would appear.

We may consider this a "mixed typeface" or "mixed font" scenario (see
ANNEX 2).


ANNEX 1: other candidates for fixed-pitch inheritance
-----------------------------------------------------

I tried to keep my patch limited to the essentials, though we could
expand it a bit to make the experience as consistent as possible.  Other
faces that can be monospaced in a mixed typeface scenario:

+ org-code
+ org-hide (org-indent inherits from it)
+ org-verbatim


ANNEX 2: mixed typeface configurations
--------------------------------------

Perhaps we would like to also offer some documentation on how users
could specify their desired font families for fixed/variable width
constructs (not strictly limited to Org).  We should also explain how
relative font heights behave.

I can already provide such a document, if you want, as I have written
the relevant instructions in the manual of the Modus themes ("Modus
Operandi" and "Modus Vivendi", which are in the Emacs 'master' branch):
https://protesilaos.com/modus-themes/#h:defcf4fc-8fa8-4c29-b12e-7119582cc929

NOTE: The manual is not distributed with Emacs yet.  It will happen at
the next tagged release of the themes.

Best regards,
Prot

P.S. Feel free to adapt this patch.

-- 
Protesilaos Stavrou
protesilaos.com

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: org-faces-fixed-pitch.diff --]
[-- Type: text/x-patch, Size: 2859 bytes --]

 lisp/org-faces.el | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/lisp/org-faces.el b/lisp/org-faces.el
index 8b0e387e6..637d32c30 100644
--- a/lisp/org-faces.el
+++ b/lisp/org-faces.el
@@ -179,7 +179,9 @@ set the properties in the `org-column' face.  For example, set
   :group 'org-faces)
 
 (defface org-date
-  '((((class color) (background light)) (:foreground "Purple" :underline t))
+  ;; NOTE: `fixed-pitch' ensures compatibility with `variable-pitch-mode'
+  '((default :inherit fixed-pitch)
+    (((class color) (background light)) (:foreground "Purple" :underline t))
     (((class color) (background dark)) (:foreground "Cyan" :underline t))
     (t (:underline t)))
   "Face for date/time stamps."
@@ -355,7 +357,9 @@ changes."
 		   (sexp :tag "Face")))))
 
 (defface org-table	   ;Copied from `font-lock-function-name-face'
-  '((((class color) (min-colors 88) (background light)) (:foreground "Blue1"))
+  ;; NOTE: `fixed-pitch' ensures compatibility with `variable-pitch-mode'
+  '((default :inherit fixed-pitch)
+    (((class color) (min-colors 88) (background light)) (:foreground "Blue1"))
     (((class color) (min-colors 88) (background dark)) (:foreground "LightSkyBlue"))
     (((class color) (min-colors 16) (background light)) (:foreground "Blue"))
     (((class color) (min-colors 16) (background dark)) (:foreground "LightSkyBlue"))
@@ -371,7 +375,9 @@ changes."
   :group 'org-faces)
 
 (defface org-formula
-  '((((class color) (min-colors 88) (background light)) (:foreground "Firebrick"))
+  ;; NOTE: `fixed-pitch' ensures compatibility with `variable-pitch-mode'
+  '((default :inherit fixed-pitch)
+    (((class color) (min-colors 88) (background light)) (:foreground "Firebrick"))
     (((class color) (min-colors 88) (background dark)) (:foreground "chocolate1"))
     (((class color) (min-colors 8)  (background light)) (:foreground "red"))
     (((class color) (min-colors 8)  (background dark)) (:foreground "red"))
@@ -384,7 +390,8 @@ changes."
   :group 'org-faces
   :version "22.1")
 
-(defface org-meta-line '((t :inherit font-lock-comment-face))
+;; NOTE: `fixed-pitch' ensures compatibility with `variable-pitch-mode'
+(defface org-meta-line '((t :inherit (fixed-pitch font-lock-comment-face)))
   "Face for meta lines starting with \"#+\"."
   :group 'org-faces
   :version "22.1")
@@ -408,7 +415,8 @@ follows a #+DATE:, #+AUTHOR: or #+EMAIL: keyword."
   "Face for #+TITLE:, #+AUTHOR:, #+EMAIL: and #+DATE: keywords."
   :group 'org-faces)
 
-(defface org-block `((t :inherit shadow
+;; NOTE: `fixed-pitch' ensures compatibility with `variable-pitch-mode'
+(defface org-block `((t :inherit (fixed-pitch shadow)
 			,@(and (>= emacs-major-version 27) '(:extend t))))
   "Face text in #+begin ... #+end blocks.
 For source-blocks, `org-src-block-faces' takes precedence."

[-- Attachment #3: org-faces-fixed-pitch.png --]
[-- Type: image/png, Size: 317899 bytes --]

             reply	other threads:[~2020-09-09 14:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-09 14:18 Protesilaos Stavrou [this message]
2020-10-24 12:25 ` [PATCH] Fixed-pitch tables and code blocks that do not break variable-pitch-mode Bastien
2021-04-27 19:28 ` Bastien
2021-04-28 18:55   ` Protesilaos Stavrou

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=875z8njaol.fsf@protesilaos.com \
    --to=info@protesilaos.com \
    --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).