Skip to content

Commit

Permalink
Avoid squashing markdown-code-face customizations
Browse files Browse the repository at this point in the history
The downside is that this approach does not work as well when
switching from a light to dark theme, or vice versa.

Closes GH-241
  • Loading branch information
jrblevin committed Aug 29, 2017
1 parent 735fe6d commit 7bf0736
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions markdown-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -2493,6 +2493,20 @@ See `markdown-hide-markup' for additional details."
"Face for blockquote sections."
:group 'markdown-faces)

(defface markdown-code-face
(let* ((default-bg (or (face-background 'default) "unspecified-bg"))
(light-bg (if (equal default-bg "unspecified-bg")
"unspecified-bg"
(color-darken-name default-bg 3)))
(dark-bg (if (equal default-bg "unspecified-bg")
"unspecified-bg"
(color-lighten-name default-bg 3))))
`((default :inherit fixed-pitch)
(((type graphic) (class color) (background dark)) (:background ,dark-bg))
(((type graphic) (class color) (background light)) (:background ,light-bg))))
"Face for inline code, pre blocks, and fenced code blocks."
:group 'markdown-faces)

(defface markdown-code-face
`((t (:inherit fixed-pitch)))
"Face for inline code, pre blocks, and fenced code blocks."
Expand Down Expand Up @@ -2668,22 +2682,6 @@ size of `markdown-header-face'."
(unless (get face-name 'saved-face) ; Don't update customized faces
(set-face-attribute face-name nil :height scale)))))

(defun markdown-update-code-face ()
"Generate `markdown-code-face' for code block backgrounds.
When using a light-background theme, darken the background slightly for
code blocks. Similarly, when using a dark-background theme, lighten it
slightly. If the face has been customized already, leave it alone."
;; Don't update customized faces
(unless (get 'markdown-code-face 'saved-face)
(let ((bg (face-background 'default)))
(when (and bg (not (equal bg "unspecified-bg")))
(set-face-attribute
'markdown-code-face nil
:background
(cl-case (cdr (assq 'background-mode (frame-parameters)))
('light (color-darken-name bg 3))
('dark (color-lighten-name bg 3))))))))

(defun markdown-syntactic-face (state)
"Return font-lock face for characters with given STATE.
See `font-lock-syntactic-face-function' for details."
Expand Down Expand Up @@ -8869,7 +8867,6 @@ position."
(if markdown-hide-markup
(add-to-invisibility-spec 'markdown-markup)
(remove-from-invisibility-spec 'markdown-markup))
(markdown-update-code-face)
;; Reload extensions
(markdown-reload-extensions)
;; Add a buffer-local hook to reload after file-local variables are read
Expand Down

0 comments on commit 7bf0736

Please sign in to comment.