reddit / emacs

How to enable variable-pitch-mode for markdown-mode, but not when markdown-mode is loaded by lsp-mode

bhrgunatha · 2022-04-17 15:06
I use `markdown-mode` for viewing and editing markdown files, typically with the .md extension. I recently changed my `markdown-mode` config to also use `variable-pitch-mode`. It seems that some part of `lsp-mode` is loading `markdown-mode` for rendering and in that case I don't want to use `variable-pitch-mode`. I tried: (use-package markdown-mode :mode (("\\.md$" . gfm-mode) ("\\.mkd$" . gfm-mode)) :diminish markdown-live-preview-mode :config (setq markdown-command "multimarkdown") (unless (bound-and-true-p lsp-mode) (variable-pitch-mode 1))) Sadly this doesn't work. I guess at the spot in `lsp-mode` that calls `(require 'markdown-mode)` that `lsp-mode` is not yet fully loaded so the `unless` expression is not preventing the call to `(variable-pitch-mode 1)`. So how can I make `markdown-mode` use `variable-pitch-mode` but not when it's loaded by `lsp-mode`.
bhrgunatha · 2022-04-17 15:17
After struggling with this for a while now, including digging and investigating the problem in order to post it here. I find my own solution within minutes of posting it. That is to use the `gfm-mode-hook` (github style markdown) to load `variable-pitch-mode` and turn it off when `lsp-mode` is active. (use-package markdown-mode :mode (("\\.md$" . gfm-mode) ("\\.mkd$" . gfm-mode)) :hook (gfm-mode . variable-pitch-mode) :diminish markdown-live-preview-mode :config (setq markdown-command "multimarkdown") (when (bound-and-true-p lsp-mode) (variable-pitch-mode -1)))
macnube · 2022-04-17 15:18
I think you've got it mostly right, but you'll probably need to put the conditional logic inside of a function and have it run on by either `markdown-mode-hook` or `lsp-mode-hook`. Try this and let me know if it works: (use-package markdown-mode :mode (("\\.md$" . gfm-mode) ("\\.mkd$" . gfm-mode)) :diminish markdown-live-preview-mode :hook ((markdown-mode . my-markdown-hook)) :init (defun my-markdown-hook () (when (bound-and-true-p lsp-mode) (variable-pitch-mode -1))) :config (setq markdown-command "multimarkdown") (variable-pitch-mode 1))
bhrgunatha · 2022-04-17 15:21
I appreciate the quick reply. I found essentially the same solution as you expressed slightly differently almost immediately after posting.