From: steve-humphreys@gmx.com
To: Help Gnu Emacs <help-gnu-emacs@gnu.org>
Subject: Changing buffer-local variables to cycle emacs options
Date: Tue, 29 Dec 2020 06:13:51 +0100 [thread overview]
Message-ID: <trinity-8284d63c-135a-4770-894e-a4db06e86e07-1609218831254@3c-app-mailcom-bs13> (raw)
I am getting the following Lisp error
Debugger entered--Lisp error: (void-variable gstate)
(let ((n gstate)) (cond ((eql n 1) (set (make-local-variable 'gstate) 2) (message "%s" "gstate 1")) ((eql n 2) (set (make-local-variable 'gstate) 3) (message "%s" "gstate 2")) (t (set (make-local-variable 'gstate) 1) (message "%s" "gstate _"))))
gstate-cycle()
funcall-interactively(gstate-cycle)
call-interactively(gstate-cycle nil nil)
command-execute(gstate-cycle)
I am using the function below. The problem occurs when I comment out
"(defvar gstate 0)". When I introduce the variable, the Lisp Error is
not reported.
One confusion that exists is that I want gstate buffer-local. But I think
that using defvar is a mistake. Another think is to avoid defining gstate
before calling the function. My plan was to have "pcase" do to the "(_"
part if the buffer-local variable "gstate" is not defined, and then define
it using "(setq-local gstate 1)".
How can I code this properly?
-------- code --------
;;(defvar gstate 0)
(defun gstate-cycle ()
(interactive)
(let ((n gstate))
(pcase n
(1 (setq-local gstate 2)
(message "%s" "gstate 1"))
(2 (setq-local gstate 3)
(message "%s" "gstate 2"))
(_ (setq-local gstate 1)
(message "%s" "gstate _")) )))
(global-set-key (kbd "H-1") #'gstate-cycle)
next reply other threads:[~2020-12-29 5:13 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-29 5:13 steve-humphreys [this message]
2020-12-29 6:28 ` Changing buffer-local variables to cycle emacs options steve-humphreys
2020-12-29 14:17 ` Yuri Khan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=trinity-8284d63c-135a-4770-894e-a4db06e86e07-1609218831254@3c-app-mailcom-bs13 \
--to=steve-humphreys@gmx.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.