polymode / poly-org

Polymode for org-mode
55 stars 12 forks source link

How to disable Variable Pitch Mode #30

Open SPFabGerman opened 3 years ago

SPFabGerman commented 3 years ago

Hi, I use Org Mode with the Variable Pitch Mode enabled. I have configured the org-block face, so that it inherits the fixed-pitch face, so that the font in the source blocks is still a monospace font. However this setup stoped working, when I enable poly-org, since now the org-block face is not applied (As far as I can tell.) and the innermodes still have the variable pitch mode enabled for some reason. I can move into a block manually and disable the variable-pitch mode manually there; or I can use the switch buffer hooks that polymode provides in order to disable the variable pitch mode, whenever I enter a source block. But this solution starts out with the variable pitch mode enabled for the inner buffers, which is really ugly and I havn't found a way to disable the Variable Pitch Mode only in the innermodes when opening a new org-file. How would I do that?

vspinu commented 3 years ago

I think polymode-init-inner-hook is what you are looking for. It runs in all innermodes after the initialization.

nmccarty commented 3 years ago

I'm also getting this issue, and i attemed setting:

(add-hook 'polymode-init-inner-hook
              (lambda () (variable-pitch-mode -1)))

And the code inside blocks is still in my variable-pitch font

shtwzrd commented 2 years ago

I encounter the same issue when trying to remap faces:

(add-hook 'polymode-init-inner-hook
            (lambda ()
              (let ((fix-pitch (face-attribute 'fixed-pitch :family))
                    (fix-font (face-attribute 'fixed-pitch :font))
                    (fix-height (face-attribute 'fixed-pitch :height)))
                (face-remap-set-base 'default
                                     :font fix-font :family fix-pitch :height fix-height))))

I also tried with face-remap-add-relative, and also tried defining a custom face and setting that via buffer-face-set, but no luck.

Is there any way to modify faces within the inner modes?

vspinu commented 2 years ago

But can you make it work from within an inner mode? Whatever works manually should be working from the inner hook.

shtwzrd commented 2 years ago

Hi @vspinu :) Thank you for your work on polymode. Multi-mode org buffers are amazing. :)

When you say make it work within an inner-mode, how do you mean? If I eval the face-remap-set-base expression within the org buffer (point is inside the source block), it remaps the face, but to the entire buffer, including the surrounding host-mode sections of the org file.

vspinu commented 2 years ago

I see. But that's how emacs works. You cannot have a face remap only on part of the buffer. It will always take effect on the entire buffer. Polymode moves face-remapping-alist between its buffers, so if you make a change in one buffer it should propagate to other buffers. Otherwise you will have a very jerky experience when moving between inner modes. Does this make sense?

shtwzrd commented 2 years ago

Ah, when you put it that way, it makes sense. Thanks for explaining. :)

I'm still a bit confused why the polymode-init-inner-hook code does not result in setting the entire buffer to the fixed-pitch font in that case, but I think I'm approaching this the wrong way regardless.

Maybe it would be better for me to explain what I'm trying to accomplish.

I want to have the 'regular' contents of the org buffer displayed in a variable-pitch font, but have the org source blocks displayed in a fixed-pitch font, similar to what is achieved with something like mixed-pitch-mode.

The problem as I understand it is, mixed-pitch mode takes advantage of the fact that org source blocks have a distinct face, org-code, and it changes that face to use a fixed-pitch font, so it's separately addressable from the default face. With poly-mode, the code blocks are using the faces of the actual major mode for that block, right? Which generally inherit from default. Is there any way for me to address the face used by the inner polymode?

vspinu commented 2 years ago

I am not expert on emacs fonts but if mixed-pitch can do it that mean we can also do it here. Unfortunately this issue is a bit low prio as I am working on bigger usuablity enhancements ATM. But if you can figure out how to make a face in a region of a buffer be of different pitch then we we figure how to do it on code spans.

Particularly, if pitch can be configured as part of a face then you can plug that configuration into adjust-face slot of your polymodes. Currently code spans are highlighted with a slight background change but anything else should be possible.

shtwzrd commented 2 years ago

Thank you so much for the hint about adjust-face slot, that's exactly what I needed!

image

Not sure if the way I'm doing it here is actually the smartest, but it's definitely getting the job done. :) So if anybody stumbles across this issue later looking to accomplish the same thing, the code is here:

(Edit -- fixed a problem with this snippet)

(use-package polymode
  :after org
  :config
  (add-hook 'polymode-init-inner-hook
            (lambda ()
              (let* ((fix-pitch (face-attribute 'fixed-pitch :family))
                     (fix-font (face-attribute 'fixed-pitch :font))
                     (fix-height (face-attribute 'fixed-pitch :height))
                     (bg (face-attribute 'org-block-begin-line :background))
                     (props `(:background ,bg
                              :extend t
                              :height ,fix-height
                              :family ,fix-pitch
                              :font ,fix-font)))
                (oset pm/chunkmode adjust-face props)))))
jdm204 commented 2 years ago

Thanks @shtwzrd, this fixes the pitch issue for me.

Not the end of the world, but it does breaks ligatures for me also (they work in a dedicated buffer as in org-edit-src-code).