unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Elisp newbie string to symbol help
@ 2019-03-07 16:36 Thomas Ingram
  2019-03-07 17:08 ` Michael Heerdegen
  2019-03-08  5:40 ` Stefan Monnier
  0 siblings, 2 replies; 4+ messages in thread
From: Thomas Ingram @ 2019-03-07 16:36 UTC (permalink / raw)
  To: help-gnu-emacs

I'm looking for some help with a simple function I am trying to write. 
I'm a long time Emacs user but I have little experience with Emacs lisp. 
The issue I am having is with the load-theme lines.

(defun my/theme-toggle ()
   "Toggle between light to dark theme."
   (interactive)
   (require 'custom)
   (let* ((current-theme (symbol-name (car custom-enabled-themes)))
      (theme (substring current-theme 0
                (- (length current-theme)
                   ; Probably a better way to do this with regex?
                   (if (string-suffix-p "dark" current-theme)
                   (length "-dark")
                 (length "-light"))))))
   (if (string-suffix-p "dark" current-theme)
       (load-theme (concat theme "-light"))
     (load-theme (concat theme "-dark"))))
   ;; (spaceline-emacs-theme)
   (start-process "toggle Gtk theme" nil "~/bin/change-theme" "toggle"))

I get the message "load-theme: Invalid theme name ‘spacemacs-dark’" 
which doesn't make sense as that is a theme I have installed.  I've 
tried quoting those lines but then it doesn't evaluate. How can I 
properly pass this concatenated string to load-theme?

I vaguely understand that it is expecting a symbol not a string and I've 
tried passing the string to make-symbol but that just changed the error 
to "Undefined Custom theme spacemacs-dark"

Any help is appreciated.

Thanks,

Thomas Ingram




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Elisp newbie string to symbol help
  2019-03-07 16:36 Elisp newbie string to symbol help Thomas Ingram
@ 2019-03-07 17:08 ` Michael Heerdegen
  2019-03-07 17:22   ` Thomas Ingram
  2019-03-08  5:40 ` Stefan Monnier
  1 sibling, 1 reply; 4+ messages in thread
From: Michael Heerdegen @ 2019-03-07 17:08 UTC (permalink / raw)
  To: Thomas Ingram; +Cc: help-gnu-emacs

Thomas Ingram <taingram@mtu.edu> writes:

> I vaguely understand that it is expecting a symbol not a string and
> I've tried passing the string to make-symbol but that just changed the
> error to "Undefined Custom theme spacemacs-dark"

`make-symbol' returns an uninterned symbol which is different from the
symbol you want (though it has the same name).  You want `intern' or
`intern-soft'.  For the details see the manual.

Michael.



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Elisp newbie string to symbol help
  2019-03-07 17:08 ` Michael Heerdegen
@ 2019-03-07 17:22   ` Thomas Ingram
  0 siblings, 0 replies; 4+ messages in thread
From: Thomas Ingram @ 2019-03-07 17:22 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: help-gnu-emacs

Thank you, that's exactly what I was looking for!

On 3/7/19 12:08 PM, Michael Heerdegen wrote:
> Thomas Ingram <taingram@mtu.edu> writes:
>
>> I vaguely understand that it is expecting a symbol not a string and
>> I've tried passing the string to make-symbol but that just changed the
>> error to "Undefined Custom theme spacemacs-dark"
> `make-symbol' returns an uninterned symbol which is different from the
> symbol you want (though it has the same name).  You want `intern' or
> `intern-soft'.  For the details see the manual.
>
> Michael.



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Elisp newbie string to symbol help
  2019-03-07 16:36 Elisp newbie string to symbol help Thomas Ingram
  2019-03-07 17:08 ` Michael Heerdegen
@ 2019-03-08  5:40 ` Stefan Monnier
  1 sibling, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2019-03-08  5:40 UTC (permalink / raw)
  To: help-gnu-emacs

>   (if (string-suffix-p "dark" current-theme)
>       (load-theme (concat theme "-light"))
>     (load-theme (concat theme "-dark"))))

Aka

    (load-theme (concat theme (if (string-suffix-p "dark" current-theme)
                                  "-light" "-dark")))

-- Stefan




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-03-08  5:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-03-07 16:36 Elisp newbie string to symbol help Thomas Ingram
2019-03-07 17:08 ` Michael Heerdegen
2019-03-07 17:22   ` Thomas Ingram
2019-03-08  5:40 ` Stefan Monnier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).