Subject: bug#45068: [PATCH] 28.0.50; Update Modus themes 1.0.2 (backward-incompatible)

From: Protesilaos Stavrou <[email-masked]>
Date: Sun, 28 Feb 2021 14:45:59 +0200

On 2021-02-28, 08:41 -0300, Mauro Aranda <[email-masked]> wrote:

> Hi Protesilaos,

Hello Mauro and thank you for the valuable feedback!

I have written the function anew based on your suggestions.  I also
added a featurep check to ensure that the same file is not loaded
repeatedly.  Furthermore, I streamlined the type of THEME to always be a
symbol.

    (defun require-theme (theme &optional directories)
      "Load THEME stored in `custom-theme-load-path'.

    THEME is a symbol that corresponds to the file name without its file
    type extension.  That is assumed to be either '.el' or '.elc'.

    If THEME names an element of `custom-available-themes', load it asking
    for confirmation if it is not considered safe by `custom-safe-themes'.
    Otherwise load the file, if present.  In the latter case, the file is
    intended to work as the basis of a theme declared with `deftheme'.

    With optional DIRECTORIES as a list of filesystem paths, search
    for THEME file in those locations instead and load it, if
    present."
      (cond
       ((member theme (member theme (custom-available-themes)))
        (load-theme theme))
       ((let* ((theme-dirs (custom-theme--load-path))
               (custom-dirs (when (and directories (listp directories))
                              directories))
               (dirs (or custom-dirs theme-dirs))
               (file (locate-file (symbol-name theme) dirs '(".el" ".elc"))))
          (when (and file (not (featurep theme)))
            (load-file file))))))

Please feel welcome to suggest any further changes/refinements.  This is
not my area of expertise, so apologies for taking so long to get it
right.

-- 
Protesilaos Stavrou
protesilaos.com