emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Fixed-pitch tables and code blocks that do not break variable-pitch-mode
@ 2020-09-09 14:18 Protesilaos Stavrou
  2020-10-24 12:25 ` Bastien
  2021-04-27 19:28 ` Bastien
  0 siblings, 2 replies; 4+ messages in thread
From: Protesilaos Stavrou @ 2020-09-09 14:18 UTC (permalink / raw)
  To: emacs-orgmode

[-- 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 --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fixed-pitch tables and code blocks that do not break variable-pitch-mode
  2020-09-09 14:18 [PATCH] Fixed-pitch tables and code blocks that do not break variable-pitch-mode Protesilaos Stavrou
@ 2020-10-24 12:25 ` Bastien
  2021-04-27 19:28 ` Bastien
  1 sibling, 0 replies; 4+ messages in thread
From: Bastien @ 2020-10-24 12:25 UTC (permalink / raw)
  To: Protesilaos Stavrou; +Cc: emacs-orgmode

Hi Protesilaos,

sorry for the delay in replying.

Protesilaos Stavrou <info@protesilaos.com> writes:

> Please see the attached diff.  An explanation is offered below.

This looks good to me -- is this enhancement compatible with older
versions of Emacs?  I'd like to keep Org compatible with Emacs 25.

If so, can you provide a proper patch?

Thanks,

-- 
 Bastien


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fixed-pitch tables and code blocks that do not break variable-pitch-mode
  2020-09-09 14:18 [PATCH] Fixed-pitch tables and code blocks that do not break variable-pitch-mode Protesilaos Stavrou
  2020-10-24 12:25 ` Bastien
@ 2021-04-27 19:28 ` Bastien
  2021-04-28 18:55   ` Protesilaos Stavrou
  1 sibling, 1 reply; 4+ messages in thread
From: Bastien @ 2021-04-27 19:28 UTC (permalink / raw)
  To: Protesilaos Stavrou; +Cc: emacs-orgmode

Hi Protesilaos,

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

Sorry it took so long to commit this, it is done in commit 667cb6f1a
in master, adding fixed-pitch for org-hide, org-verbatim and org-code
too.

Thanks!


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fixed-pitch tables and code blocks that do not break variable-pitch-mode
  2021-04-27 19:28 ` Bastien
@ 2021-04-28 18:55   ` Protesilaos Stavrou
  0 siblings, 0 replies; 4+ messages in thread
From: Protesilaos Stavrou @ 2021-04-28 18:55 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode

On 2021-04-27, 21:28 +0200, Bastien <bzg@gnu.org> wrote:

>> Please see the attached diff.  An explanation is offered below.  I have
>> already assigned copyright to the FSF.
>
> Sorry it took so long to commit this, it is done in commit 667cb6f1a
> in master, adding fixed-pitch for org-hide, org-verbatim and org-code
> too.
>
> Thanks!

Thank you Bastien for this and for every other contribution!

-- 
Protesilaos Stavrou
https://protesilaos.com


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-04-28 18:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-09 14:18 [PATCH] Fixed-pitch tables and code blocks that do not break variable-pitch-mode Protesilaos Stavrou
2020-10-24 12:25 ` Bastien
2021-04-27 19:28 ` Bastien
2021-04-28 18:55   ` Protesilaos Stavrou

Code repositories for project(s) associated with this 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).