From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "Basil L. Contovounesios" Newsgroups: gmane.emacs.bugs Subject: bug#45068: [PATCH] 28.0.50; Update Modus themes 1.0.2 (backward-incompatible) Date: Wed, 03 Mar 2021 16:31:28 +0000 Message-ID: <87o8g0ryfz.fsf@tcd.ie> References: <87im9fgm27.fsf@protesilaos.com> <83lfe4192f.fsf@gnu.org> <83im9814oh.fsf@gnu.org> <87sg6po0yd.fsf_-_@protesilaos.com> <83czxt2fpd.fsf@gnu.org> <87h7m0n0em.fsf@protesilaos.com> <83v9agryuz.fsf@gnu.org> <87tupyw83e.fsf@protesilaos.com> <83zgzqncxx.fsf@gnu.org> <874khwn1qf.fsf@protesilaos.com> <603b8171.1c69fb81.aa664.7f40@mx.google.com> <87mtvoxsvs.fsf@protesilaos.com> <603b9b9d.1c69fb81.f37aa.cb7c@mx.google.com> <83eegz7xcx.fsf@gnu.org> <87o8g3exjv.fsf@protesilaos.com> <603d053a.1c69fb81.f4cb8.fb14@mx.google.com> <87h7luga3p.fsf@protesilaos.com> <87o8g2bg89.fsf@tcd.ie> <87r1kyrtrl.fsf@protesilaos.com> <878s75x2uk.fsf@tcd.ie> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="4158"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: Mauro Aranda , 45068@debbugs.gnu.org To: Protesilaos Stavrou Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Mar 03 17:35:59 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lHUTe-0000uu-VZ for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 03 Mar 2021 17:35:59 +0100 Original-Received: from localhost ([::1]:56976 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lHUTe-0000AL-10 for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 03 Mar 2021 11:35:58 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47176) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lHUPq-0006pG-JV for bug-gnu-emacs@gnu.org; Wed, 03 Mar 2021 11:32:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:45228) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lHUPq-0004Lp-Bx for bug-gnu-emacs@gnu.org; Wed, 03 Mar 2021 11:32:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lHUPq-0004nW-7r for bug-gnu-emacs@gnu.org; Wed, 03 Mar 2021 11:32:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: "Basil L. Contovounesios" Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 03 Mar 2021 16:32:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 45068 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 45068-submit@debbugs.gnu.org id=B45068.161478910018413 (code B ref 45068); Wed, 03 Mar 2021 16:32:02 +0000 Original-Received: (at 45068) by debbugs.gnu.org; 3 Mar 2021 16:31:40 +0000 Original-Received: from localhost ([127.0.0.1]:56774 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lHUPT-0004mu-IH for submit@debbugs.gnu.org; Wed, 03 Mar 2021 11:31:40 -0500 Original-Received: from mail-wm1-f49.google.com ([209.85.128.49]:56192) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lHUPR-0004mh-J0 for 45068@debbugs.gnu.org; Wed, 03 Mar 2021 11:31:38 -0500 Original-Received: by mail-wm1-f49.google.com with SMTP id w7so5670536wmb.5 for <45068@debbugs.gnu.org>; Wed, 03 Mar 2021 08:31:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tcd.ie; s=google21; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=W1D6Al7E66EZggOkuuUADv3k5o6ZzXDA7qBoL4/KVuE=; b=dSxElR5tZuFSHTA95o7pryVdFKzuYduq1oLjXIyfGnPC/jqIAzJC+Bcjh6UxnbfzIO 09nn+NZlaYxBBYS+FM6vfqONO7nM3DJLmloCKXfWRFTHvyikseLrL1muoZeUVx7QLGqF xpazhAQXOFjV/zm9E9UO9ydYD9vGrX1pW78qVCY+tWXBn5/fWTizFNVFqCueOPKLdi7U +eTalJyaGLvcyeUtrMDlF4BGjTA6o3Mtwm9SUV3GpXGPJVOaEA2dAaqorFgIQ4maQV+M G/EyyM1tQUyeOf4D6QYWM76dfiJgexiRO9UHivc9htElvxJxb++NZTm1iHYhhhJ0A+gT FMZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=W1D6Al7E66EZggOkuuUADv3k5o6ZzXDA7qBoL4/KVuE=; b=IthO3bncideBtX4e8Twj+U5tlWOb2R8DdO40kqikPoIiZJ5sWus7SHHrWjERsMpBjX fXGl7M/Ht0jnQNiZwf+53eQamUeJX+iD63vjGrS9QURwELA/iRXZ8RC44sS6gQZwAhQV j3B+wXsQ1dzT1NcWndqy6CNOQne+cTv2Nhsb6lRKsEd4MtPgf+pnUozoDzznaEoV4b7x qGmzeXOlTChQCFiWWKjFcPp81cPDxwuvBhfCFhB5FSa7x/GJNgxM8h5pPiMfQEGCi4OR Sb8EUlKs2RHh7ntxf6bGYdL6dAcCia3fdTDNPb5N0+o6aE1rDOJNSl9XiWPdTKhhIUPp Z4aw== X-Gm-Message-State: AOAM533C0/3cUwlIePYk5dc/UiHwGcHopv7blWxchp/1pWDTu2ErSFlo 5RRpCzcvkUUBQjEUuMD8wow9EA== X-Google-Smtp-Source: ABdhPJzXwC4T5g8Mem7ZGL1JPIBo3o49f9/WCDlK3U9NKPjGN11m2IULXniJ1y+qa9Oo7vs4F/y0OA== X-Received: by 2002:a7b:ca50:: with SMTP id m16mr9541370wml.113.1614789091479; Wed, 03 Mar 2021 08:31:31 -0800 (PST) Original-Received: from localhost ([2a02:8084:20e2:c380:f410:82e8:3a21:eedf]) by smtp.gmail.com with ESMTPSA id z21sm6501111wma.29.2021.03.03.08.31.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Mar 2021 08:31:30 -0800 (PST) In-Reply-To: <878s75x2uk.fsf@tcd.ie> (Basil L. Contovounesios's message of "Tue, 02 Mar 2021 10:32:51 +0000") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:201292 Archived-At: --=-=-= Content-Type: text/plain "Basil L. Contovounesios" writes: > I'll suggest a patch soon to help the discussion. How's the attached? Thanks, -- Basil --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Decouple-require-theme-from-load-theme.patch >From 89c356e0ae18fd265a0992a6767289e267410a26 Mon Sep 17 00:00:00 2001 From: "Basil L. Contovounesios" Date: Tue, 2 Mar 2021 14:35:50 +0000 Subject: [PATCH] Decouple require-theme from load-theme * lisp/custom.el (require-theme): Refashion after 'require', as a function for loading only named features. Do not call load-theme (bug#45068). * etc/NEWS: Update its announcement accordingly. * doc/lispref/customize.texi (Custom Themes): Document it. * etc/themes/modus-operandi-theme.el: * etc/themes/modus-vivendi-theme.el: Remove redundant calls to 'provide'. * test/lisp/custom-tests.el (custom-tests--with-temp-dir): New macro. (custom-theme--load-path): Use it. (custom-tests-require-theme): New test. --- doc/lispref/customize.texi | 26 ++++- etc/NEWS | 8 +- etc/themes/modus-operandi-theme.el | 2 - etc/themes/modus-vivendi-theme.el | 2 - lisp/custom.el | 40 ++++---- test/lisp/custom-tests.el | 150 ++++++++++++++++++----------- 6 files changed, 144 insertions(+), 84 deletions(-) diff --git a/doc/lispref/customize.texi b/doc/lispref/customize.texi index 8fd12f7902..bc35982c17 100644 --- a/doc/lispref/customize.texi +++ b/doc/lispref/customize.texi @@ -1474,7 +1474,7 @@ Custom Themes displays the source file and asks for confirmation from the user before loading any non-built-in theme for the first time. As such, themes are not ordinarily byte-compiled, and source files -always take precedence when Emacs is looking for a theme to load. +usually take precedence when Emacs is looking for a theme to load. The following functions are useful for programmatically enabling and disabling themes: @@ -1508,6 +1508,30 @@ Custom Themes @var{no-confirm} is non-@code{nil}. @end deffn +@defun require-theme feature &optional noerror +This function searches @code{custom-theme-load-path} for a file that +provides @var{feature} and then loads it. This is like the function +@code{require} (@pxref{Named Features}), except it searches +@code{custom-theme-load-path} instead of @code{load-path} +(@pxref{Library Search}). This can be useful in Custom themes that +need to load supporting Lisp files when @code{require} is unsuitable +for that. + +If @var{feature}, which should be a symbol, is not already present in +the current Emacs session according to @code{featurep}, then +@code{require-theme} searches for a file named @var{feature} with an +added @samp{.elc} or @samp{.el} suffix, in that order, in the +directories specified by @code{custom-theme-load-path}. + +If a file providing @var{feature} is successfully found and loaded, +then @code{require-theme} returns @var{feature}. The optional +argument @var{noerror} determines what happens if the search or +loading fails. If it is @code{nil}, the function signals an error; +otherwise, it returns @code{nil}. If the file loads successfully but +does not provide @var{feature}, then @code{require-theme} signals an +error; this cannot be suppressed. +@end defun + @deffn Command enable-theme theme This function enables the Custom theme named @var{theme}. It signals an error if no such theme has been loaded. diff --git a/etc/NEWS b/etc/NEWS index 73f136cfa7..c794597de5 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -2511,11 +2511,11 @@ 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. +This function is like 'require', but searches 'custom-theme-load-path' +instead of 'load-path'. It can be used by Custom themes to load +supporting Lisp files when 'require' is unsuitable. +++ ** New function 'file-modes-number-to-symbolic' to convert a numeric diff --git a/etc/themes/modus-operandi-theme.el b/etc/themes/modus-operandi-theme.el index 346000a093..9d6e9ad50f 100644 --- a/etc/themes/modus-operandi-theme.el +++ b/etc/themes/modus-operandi-theme.el @@ -4661,6 +4661,4 @@ modus-operandi-theme-scale (provide-theme 'modus-operandi) -(provide 'modus-operandi-theme) - ;;; modus-operandi-theme.el ends here diff --git a/etc/themes/modus-vivendi-theme.el b/etc/themes/modus-vivendi-theme.el index 73f07d644b..171313244b 100644 --- a/etc/themes/modus-vivendi-theme.el +++ b/etc/themes/modus-vivendi-theme.el @@ -4661,6 +4661,4 @@ modus-vivendi-theme-scale (provide-theme 'modus-vivendi) -(provide 'modus-vivendi-theme) - ;;; modus-vivendi-theme.el ends here diff --git a/lisp/custom.el b/lisp/custom.el index 35ac4d8564..b9fccce583 100644 --- a/lisp/custom.el +++ b/lisp/custom.el @@ -1200,29 +1200,31 @@ 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'. +(defun require-theme (feature &optional noerror) + "Load FEATURE from a file along `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'. +This function is like `require', but searches along +`custom-theme-load-path' instead of `load-path'. It can be used +by Custom themes to load supporting Lisp files when `require' is +unsuitable. -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 FEATURE is not already loaded, search for a file named FEATURE +with an added `.elc' or `.el' suffix, in that order, in the +directories specified by `custom-theme-load-path'. -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'." +Return FEATURE if the file is successfully found and loaded, or +if FEATURE was already loaded. If the file fails to load, signal +an error. If optional argument NOERROR is non-nil, return nil +instead of signaling an error. If the file loads but does not +provide FEATURE, signal an error. This cannot be suppressed." (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)))))) + ((featurep feature) feature) + ((let* ((path (custom-theme--load-path)) + (file (locate-file (symbol-name feature) path '(".elc" ".el")))) + (and file (require feature (file-name-sans-extension file) noerror)))) + ((not noerror) + (let (load-path) + (require feature))))) (defcustom custom-safe-themes '(default) "Themes that are considered safe to load. diff --git a/test/lisp/custom-tests.el b/test/lisp/custom-tests.el index 09f79c1a08..02a9239824 100644 --- a/test/lisp/custom-tests.el +++ b/test/lisp/custom-tests.el @@ -24,70 +24,108 @@ (require 'wid-edit) (require 'cus-edit) -(require 'seq) ; For `seq-find'. + +(defmacro custom-tests--with-temp-dir (&rest body) + "Eval BODY with `temporary-file-directory' bound to a fresh directory. +Ensure the directory is recursively deleted after the fact." + (declare (debug t) (indent 0)) + (let ((dir (make-symbol "dir"))) + `(let ((,dir (file-name-as-directory (make-temp-file "custom-tests-" t)))) + (unwind-protect + (let ((temporary-file-directory ,dir)) + ,@body) + (delete-directory ,dir t))))) (ert-deftest custom-theme--load-path () "Test `custom-theme--load-path' behavior." - (let ((tmpdir (file-name-as-directory (make-temp-file "custom-tests-" t)))) - (unwind-protect - ;; Create all temporary files under the same deletable parent. - (let ((temporary-file-directory tmpdir)) - ;; Path is empty. - (let ((custom-theme-load-path ())) - (should (null (custom-theme--load-path)))) + (custom-tests--with-temp-dir + ;; Path is empty. + (let ((custom-theme-load-path ())) + (should (null (custom-theme--load-path)))) - ;; Path comprises non-existent file. - (let* ((name (make-temp-name tmpdir)) - (custom-theme-load-path (list name))) - (should (not (file-exists-p name))) - (should (null (custom-theme--load-path)))) + ;; Path comprises non-existent file. + (let* ((name (make-temp-name temporary-file-directory)) + (custom-theme-load-path (list name))) + (should (not (file-exists-p name))) + (should (null (custom-theme--load-path)))) - ;; Path comprises existing file. - (let* ((file (make-temp-file "file")) - (custom-theme-load-path (list file))) - (should (file-exists-p file)) - (should (not (file-directory-p file))) - (should (null (custom-theme--load-path)))) + ;; Path comprises existing file. + (let* ((file (make-temp-file "file")) + (custom-theme-load-path (list file))) + (should (file-exists-p file)) + (should (not (file-directory-p file))) + (should (null (custom-theme--load-path)))) - ;; Path comprises existing directory. - (let* ((dir (make-temp-file "dir" t)) - (custom-theme-load-path (list dir))) - (should (file-directory-p dir)) - (should (equal (custom-theme--load-path) custom-theme-load-path))) + ;; Path comprises existing directory. + (let* ((dir (make-temp-file "dir" t)) + (custom-theme-load-path (list dir))) + (should (file-directory-p dir)) + (should (equal (custom-theme--load-path) custom-theme-load-path))) - ;; Expand `custom-theme-directory' path element. - (let ((custom-theme-load-path '(custom-theme-directory))) - (let ((custom-theme-directory (make-temp-name tmpdir))) - (should (not (file-exists-p custom-theme-directory))) - (should (null (custom-theme--load-path)))) - (let ((custom-theme-directory (make-temp-file "file"))) - (should (file-exists-p custom-theme-directory)) - (should (not (file-directory-p custom-theme-directory))) - (should (null (custom-theme--load-path)))) - (let ((custom-theme-directory (make-temp-file "dir" t))) - (should (file-directory-p custom-theme-directory)) - (should (equal (custom-theme--load-path) - (list custom-theme-directory))))) + ;; Expand `custom-theme-directory' path element. + (let ((custom-theme-load-path '(custom-theme-directory))) + (let ((custom-theme-directory (make-temp-name temporary-file-directory))) + (should (not (file-exists-p custom-theme-directory))) + (should (null (custom-theme--load-path)))) + (let ((custom-theme-directory (make-temp-file "file"))) + (should (file-exists-p custom-theme-directory)) + (should (not (file-directory-p custom-theme-directory))) + (should (null (custom-theme--load-path)))) + (let ((custom-theme-directory (make-temp-file "dir" t))) + (should (file-directory-p custom-theme-directory)) + (should (equal (custom-theme--load-path) + (list custom-theme-directory))))) - ;; Expand t path element. - (let ((custom-theme-load-path '(t))) - (let ((data-directory (make-temp-name tmpdir))) - (should (not (file-exists-p data-directory))) - (should (null (custom-theme--load-path)))) - (let ((data-directory tmpdir) - (themedir (expand-file-name "themes" tmpdir))) - (should (not (file-exists-p themedir))) - (should (null (custom-theme--load-path))) - (with-temp-file themedir) - (should (file-exists-p themedir)) - (should (not (file-directory-p themedir))) - (should (null (custom-theme--load-path))) - (delete-file themedir) - (make-directory themedir) - (should (file-directory-p themedir)) - (should (equal (custom-theme--load-path) (list themedir)))))) - (when (file-directory-p tmpdir) - (delete-directory tmpdir t))))) + ;; Expand t path element. + (let ((custom-theme-load-path '(t))) + (let ((data-directory (make-temp-name temporary-file-directory))) + (should (not (file-exists-p data-directory))) + (should (null (custom-theme--load-path)))) + (let ((data-directory temporary-file-directory) + (themedir (expand-file-name "themes" temporary-file-directory))) + (should (not (file-exists-p themedir))) + (should (null (custom-theme--load-path))) + (with-temp-file themedir) + (should (file-exists-p themedir)) + (should (not (file-directory-p themedir))) + (should (null (custom-theme--load-path))) + (delete-file themedir) + (make-directory themedir) + (should (file-directory-p themedir)) + (should (equal (custom-theme--load-path) (list themedir))))))) + +(ert-deftest custom-tests-require-theme () + "Test `require-theme'." + (custom-tests--with-temp-dir + (let* ((default-directory temporary-file-directory) + (custom-theme-load-path (list default-directory)) + (load-path ())) + ;; Generate some `.el' and `.elc' files. + (with-temp-file "custom-tests--a.el" + (insert "(provide 'custom-tests--a)")) + (make-empty-file "custom-tests--b.el") + (with-temp-file "custom-tests--b.elc" + (byte-compile-insert-header nil (current-buffer)) + (insert "(provide 'custom-tests--b)")) + (make-empty-file "custom-tests--c.el") + (with-temp-file "custom-tests--d.elc" + (byte-compile-insert-header nil (current-buffer))) + ;; Load them. + (dolist (feature '(a b c d e)) + (should-not (featurep (intern (format "custom-tests--%s" feature))))) + (should (eq (require-theme 'custom-tests--a) 'custom-tests--a)) + (delete-file "custom-tests--a.el") + (dolist (feature '(custom-tests--a custom-tests--b)) + (should (eq (require-theme feature) feature)) + (should (featurep feature))) + (dolist (feature '(custom-tests--c custom-tests--d)) + (dolist (noerror '(nil t)) + (let ((err (should-error (require-theme feature noerror)))) + (should (string-search "failed to provide feature" (cadr err)))))) + (should-error (require-theme 'custom-tests--e) :type 'file-missing) + (should-not (require-theme 'custom-tests--e t)) + (dolist (feature '(custom-tests--c custom-tests--d custom-tests--e)) + (should-not (featurep feature)))))) (defcustom custom--test-user-option 'foo "User option for test." -- 2.30.1 --=-=-=--