Once in a while I manually set the font-family and size different from the default, and I use buffer-face-mode to do it. (To be exact I use the mouse & pick one from the dialog box.) Once I set it, I'd like it to stay set for that buffer, even if I change modes, so I tried a customization. The idea was to add a change-major-mode-hook (which runs just before buffer-locals get killed) that would save the buffer face, if it is set, in a function to be called later- that much seems to work. But then that function seems to be called too soon, and when the mode change is over, buffer-face-mode is not active.
Here's the customization I cam up with so far
(defun my-preserve-bufface-cmmh ()
"Keep the state of buffer-face-mode between major-mode changes"
(if (and (local-variable-p 'buffer-face-mode) buffer-face-mode)
(delay-mode-hooks
(message "face is %s" buffer-face-mode-face) ; Just to show me it has the right face
(let ((my-inner-face buffer-face-mode-face))
(run-mode-hooks
(message "inner %s" my-inner-face) ; it still has the right face here
(setq buffer-face-mode-face my-inner-face)
(buffer-face-mode))))))
(add-hook 'change-major-mode-hook
'my-preserve-bufface-cmmh)
The messages both run and show a custom face, as they should, when I'm changing major-mode in a buffer with the minor-mode buffer-face-mode set. I had thought the combination of delay-mode-hooks ... run-mode-hooks would make setq buffer-face-mode-face ... (buffer-face-mode) run after the new mode was set up, but apparently not.
Is this customization "close"/salvageable for my wants? Is there a cleaner way?
run-mode-hookscall which looks very weird. You could useadd-hookonafter-change-major-mode-hookinstead. - Stefanrun-mode-hooksis that it pushes something to be run once onto a stack, as opposed to having another function sitting around even when it isn't needed. Still, would rather have something working- broken code isn't elegant! (@phils put therun-mode-hooksidea in my head from his answer to my prior question, about dir-locals when switching major modes! I am going to put adebugin therun-mode-hooksbody in a last attempt to understand what's going on.) - Yaryrun-mode-hooksis not a bad idea, but its argument are symbols, not Elisp code. So you need to create a symbol, assign a function to it, and then pass it torun-mode-hooks. - Stefan