[PATCH] emms-browser.el: Fix bug in emms-browser-format-spec

Scarlett McAllister <[email protected]>
Newsgroups gmane.emacs.emms.user
Message-ID <[email protected]>
Sometimes, emms-browser-format-spec will throw an "Invalid format 
character" error, even when supplied a valid character format. This 
happens because the propertized string returned by 
emms-browser-format-line may contain an item with a car but no cdr 
(e.g.: ("y") instead of ("y" . 2023)). This patch fixes that by throwing 
the error only if the propertized string doesn't contain the key. Then, 
in circumstances where it does contain the key but the value is nil, it 
will supply an empty string to the text formatting procedure.

> diff --git a/emms-browser.el b/emms-browser.el
> index 6a75cdb..1769881 100644
> --- a/emms-browser.el
> +++ b/emms-browser.el
> @@ -1847,9 +1847,12 @@ the text that it generates."
>         ((looking-at "\\([-0-9.]*\\)\\([a-zA-Z]+\\)")
>          (let* ((num (match-string 1))
>                 (spec (match-string 2))
> -               (val (cdr (assoc spec specification))))
> -          (unless val
> +               (val-alist (assoc spec specification))
> +               (val (cdr val-alist)))
> +          (unless val-alist
>              (error "Invalid format character: %s" spec))
> +          ;; Value for a valid spec may not exist. Not an error, just 
> nothing to show.
> +          (unless val (setq val ""))
>            ;; Pad result to desired length.
>            (let ((text (format (concat "%" num "s") val)))
>              ;; Insert first, to preserve text properties.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.