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

From: Protesilaos Stavrou <[email-masked]>
Date: Mon, 01 Mar 2021 17:35:54 +0200

On 2021-03-01, 12:16 -0300, Mauro Aranda <[email-masked]> wrote:

> Since there's agreement about this, could you send it as a patch?

Please find it attached.  I did not know how to mention you as
co-authors, so please do so.

As for the original topic of this bug report, I will prepare a new
version for the themes within the next few days (version 1.2.0).  Then I
will update this thread with a new patch.

Thank you for your help and patience!

-- 
Protesilaos Stavrou
protesilaos.com
>From c3f0ee0ed8e79f9496a6cec1c9d3282b3231a6dc Mon Sep 17 00:00:00 2001
Message-Id: <[email-masked]>
From: Protesilaos Stavrou <[email-masked]>
Date: Mon, 1 Mar 2021 17:31:44 +0200
Subject: [PATCH] Add 'require-theme' function

* etc/NEWS: Document new function.
* lisp/custom.el (require-theme): Add function.

This follows from the discussion on bug#45068 where it became apparent
that there was no equivalent mechanism to 'require' that read through
the 'custom-theme-load-path'.
---
 etc/NEWS       |  6 ++++++
 lisp/custom.el | 24 ++++++++++++++++++++++++
 2 files changed, 30 insertions(+)

diff --git a/etc/NEWS b/etc/NEWS
index f8f41e21e2..c2bb0820af 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2495,6 +2495,12 @@ region's (or buffer's) end.
 This function can be used by modes to add elements to the
 'choice' customization type of a variable.
 
+---
+** New function 'require-theme'.
+This function is used to load a theme or library stored in the
+'custom-theme-load-path'.  It is intended to work as a substitute for
+'require' in those cases where that cannot be used.
+
 +++
 ** New function 'file-modes-number-to-symbolic' to convert a numeric
 file mode specification into symbolic form.
diff --git a/lisp/custom.el b/lisp/custom.el
index 833810718b..35ac4d8564 100644
--- a/lisp/custom.el
+++ b/lisp/custom.el
@@ -1200,6 +1200,30 @@ provide-theme
   (custom-check-theme theme)
   (provide (get theme 'theme-feature)))
 
+(defun require-theme (theme &optional path)
+  "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'.
+
+When THEME is an element of `custom-available-themes', load it and ask
+for confirmation if it is not considered safe by `custom-safe-themes'.
+Otherwise load the file indicated by THEME, if present.  In the latter
+case, the file is intended to work as the basis of a theme declared
+with `deftheme'.
+
+If optional PATH is non-nil, it should be a list of directories
+to search for THEME in, instead of `custom-theme-load-path'.
+PATH should have the same form as `load-path' or `exec-path'."
+  (cond
+   ((memq theme (custom-available-themes))
+    (load-theme theme))
+   ((let* ((dirs (or path (custom-theme--load-path)))
+           (file (unless (featurep theme)
+                   (locate-file (symbol-name theme) dirs '(".el" ".elc")))))
+      (when file
+        (load-file file))))))
+
 (defcustom custom-safe-themes '(default)
   "Themes that are considered safe to load.
 If the value is a list, each element should be either the SHA-256
-- 
2.30.1