Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable different header scaling in markdown-mode and markdown-view-mode #858

Open
mattiasb opened this issue Nov 16, 2024 · 0 comments
Open

Comments

@mattiasb
Copy link
Contributor

mattiasb commented Nov 16, 2024

Expected Behavior

I would like to have header scaling enabled in markdown-view-mode but
not in markdown-mode.

I have a local hack in my personal config that looks like this:

;;;###autoload
(define-minor-mode +markdown-scale-headers-mode
  "Scale `markdown-mode' headers."
  :lighter "M↑"
  (+markdown-update-header-faces +markdown-scale-headers-mode))

(defun +markdown-update-header-faces (&optional scaling scaling-values)
  "Update header faces, depending on if header SCALING is desired.
If so, use given list of SCALING-VALUES relative to the baseline
size of `markdown-header-face'.
Like `markdown-update-header-faces' but buffer local."
  (dotimes (num 6)
    (let* ((face-name (intern (format "markdown-header-face-%s" (1+ num))))
           (scale (cond ((not scaling) 1.0)
                        (scaling-values (float (nth num scaling-values)))
                        (t (float (nth num markdown-header-scaling-values))))))
      (unless (get face-name 'saved-face) ; Don't update customized faces
        (face-remap-add-relative face-name :height scale)))))

The important points in the code snippet above are:

  1. I add a buffer local minor mode for enabling or disabling header scaling
  2. I change markdown-update-header-faces like this:
    - (set-face-attribute face-name nil :height scale)
    + (face-remap-add-relative face-name :height scale)

Posting this hack in the issue itself is mostly to show that it can be done
but I realize there are several ways to do this and there might be downsides
I haven't considered.

Actual Behavior

Enabling markdown-header-scaling will toggle header scaling in all modes.

Steps to Reproduce

  1. Enable header scaling

Software Versions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant