Subject: bug#57639: [PATCH] Add new command 'toggle-theme'

From: Philip Kaludercic <[email-masked]>
Date: Thu, 20 Oct 2022 17:42:52 +0000

Stefan Monnier <[email-masked]> writes:

>>>>> We could arrange for `autoload/loaddefs-gen` to recognize `deftheme` and
>>>>> add the directory containing the file containing this `deftheme` to the
>>>>> `custom-theme-load-path`.
>>>> If this is possible I think this would be a nice idea.
>>> It should be easy to do.
>> Sadly I am stumped on how this could be done, as I have little
>> experience with the bootstrapping process.  Could you give me a few pointers?
>
> I was thinking of something like the patch below.
>
>
>         Stefan
>
>
> diff --git a/lisp/emacs-lisp/loaddefs-gen.el b/lisp/emacs-lisp/loaddefs-gen.el
> index ecc5f7e47bd..a07d0e9ad61 100644
> --- a/lisp/emacs-lisp/loaddefs-gen.el
> +++ b/lisp/emacs-lisp/loaddefs-gen.el
> @@ -286,8 +286,16 @@ loaddefs-generate--make-autoload
>       ;; Extract theme properties.
>       ((eq car 'deftheme)
>        (let* ((name (car-safe (cdr-safe form)))
> -	     (props (nthcdr 3 form)))
> -	`(put ',name 'theme-properties (list ,@props))))
> +	     (props (nthcdr 3 form))
> +	     (dir (file-name-directory file)))
> +	`(progn
> +	   (add-to-list 'custom-theme-load-path
> +	                ,(if dir 
> +	                     `(expand-file-name ,dir
> +	                                        (file-name-directory
> +	                                         (macroexp-file-name)))
> +	                   `(file-name-directory (macroexp-file-name))))
> +	   (put ',name 'theme-properties (list ,@props)))))
>  
>       ((eq car 'defgroup)
>        ;; In Emacs this is normally handled separately by cus-dep.el, but for

Ah, I see.  Initially my assumption was that you were talking about the
automatic scraping of unannotated (deftheme ...) forms.  I'll try this
patch out, see how it works and report back.