alphapapa / alphapapa/prism.el

prism-after-theme advice broken on terminal

Open
#32 3 comments 0 reactions 1 assignee Claimed by @alphapapa View on GitHub
bug help wanted
Dominant language
Emacs Lisp
Stars
334
Forks
5
PR merge metrics
No merged PRs in 30d

Description

The `prism-after-theme` advice is broken when it is called after `disable-theme` on a terminal. The advice calls `prism-set-colors` which in turn calls `prism-blend`.

`disable-theme` calls:

```lisp
(set-frame-parameter frame 'background-color
(custom--frame-color-default
frame :background "background" "Background"
"unspecified-bg" "white"))
```

On a terminal, this will set the frame background color to `unspecified-bg`.` prism-set-colors` would retrieve the background color for the `parens-fn` parameter:

```lisp
(parens-fn (lambda (color)
(prism-blend color (face-attribute 'default :background nil 'default) 0.5)))
```

This results in the following backtrace:

```
Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p nil)
(#f(compiled-function (a b alpha) #) 0.6784313725490196 nil 0.5)
(prism-blend "#ade5ad" "unspecified-bg" 0.5)
(#f(compiled-function (color) #) "#ade5ad")
(#f(compiled-function (arg1 &rest rest) #) ("#ade5ad" "#a0c8e1" "#32cbcc" "#e4ab94" "#c1e6c1" "#b3cfe0" "#49c2c2" "#e2b9a9") "parens" #f(compiled-function (color) #))
(prism-set-colors)
(prism-after-theme modus-operandi-tinted)
(apply prism-after-theme modus-operandi-tinted)
(disable-theme modus-operandi-tinted)
(#f(compiled-function (theme &optional no-confirm no-enable) "Load Custom theme named THEME from its file and possibly enable it.\nThe theme file is named THEME-theme.el, in one of the directories\nspecified by `custom-theme-load-path'.\n\nIf the theme is not considered safe by `custom-safe-themes',\nprompt the user for confirmation before loading it. But if\noptional arg NO-CONFIRM is non-nil, load the theme without\nprompting.\n\nNormally, this function also enables THEME. If optional arg\nNO-ENABLE is non-nil, load the theme but don't enable it, unless\nthe theme was already enabled.\n\nNote that enabling THEME does not disable any other\nalready-enabled themes. If THEME is enabled, it has the highest\nprecedence (after `user') among enabled themes. To disable other\nthemes, use `disable-theme'.\n\nThis function is normally called through Customize when setting\n`custom-enabled-themes'. If used directly in your init file, it\nshould be called with a non-nil NO-CONFIRM argument, or after\n`custom-safe-themes' has been loaded.\n\nReturn t if THEME was successfully loaded, nil otherwise." (interactive #f(compiled-function () #)) #) modus-operandi-tinted :no-confirm)
(apply #f(compiled-function (theme &optional no-confirm no-enable) "Load Custom theme named THEME from its file and possibly enable it.\nThe theme file is named THEME-theme.el, in one of the directories\nspecified by `custom-theme-load-path'.\n\nIf the theme is not considered safe by `custom-safe-themes',\nprompt the user for confirmation before loading it. But if\noptional arg NO-CONFIRM is non-nil, load the theme without\nprompting.\n\nNormally, this function also enables THEME. If optional arg\nNO-ENABLE is non-nil, load the theme but don't enable it, unless\nthe theme was already enabled.\n\nNote that enabling THEME does not disable any other\nalready-enabled themes. If THEME is enabled, it has the highest\nprecedence (after `user') among enabled themes. To disable other\nthemes, use `disable-theme'.\n\nThis function is normally called through Customize when setting\n`custom-enabled-themes'. If used directly in your init file, it\nshould be called with a non-nil NO-CONFIRM argument, or after\n`custom-safe-themes' has been loaded.\n\nReturn t if THEME was successfully loaded, nil otherwise." (interactive #f(compiled-function () #)) #) (modus-operandi-tinted :no-confirm))
(load-theme modus-operandi-tinted :no-confirm)
(modus-themes-load-theme modus-operandi-tinted)
(modus-themes-toggle)
(funcall-interactively modus-themes-toggle)
(call-interactively modus-themes-toggle record nil)
(command-execute modus-themes-toggle record)
(execute-extended-command nil "modus-themes-toggle" nil)
(funcall-interactively execute-extended-command nil "modus-themes-toggle" nil)
(call-interactively execute-extended-command nil nil)
(command-execute execute-extended-command)

```

I created a workaround to add an advice to `prism-blend` and intercept any unspecified colors:

```lisp
(defun bram85-prism-blend-advice (f a b alpha)
(let ((a_ (if (string-prefix-p "unspecified-" a) "white" a))
(b_ (if (string-prefix-p "unspecified-" b) "white" b)))
(funcall f a_ b_ alpha)))

(advice-add #'prism-blend :around #'bram85-prism-blend-advice)
```

Personally I only encounter this issue when calling `modus-themes-toggle`, which is roughly a sequence of `disable-theme` and `load-theme`. Therefore the workaround is sufficient for me, as I wouldn't observe the blending result with the *white* dummy color. But it wouldn't generalize well for those who run `disable-theme` in isolation.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.