alphapapa / alphapapa/prism.el

prism-after-theme advice broken on terminal

Aberta
#32 3 comentários 0 reações 1 responsável Reivindicada por @alphapapa Ver no GitHub
bug help wanted
Linguagem predominante
Emacs Lisp
Estrelas
334
Forks
5
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

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.

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.