unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Changing buffer-local variables to cycle emacs options
@ 2020-12-29  5:13 steve-humphreys
  2020-12-29  6:28 ` steve-humphreys
  2020-12-29 14:17 ` Yuri Khan
  0 siblings, 2 replies; 3+ messages in thread
From: steve-humphreys @ 2020-12-29  5:13 UTC (permalink / raw)
  To: Help Gnu Emacs

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)







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

end of thread, other threads:[~2020-12-29 14:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-12-29  5:13 Changing buffer-local variables to cycle emacs options steve-humphreys
2020-12-29  6:28 ` steve-humphreys
2020-12-29 14:17 ` Yuri Khan

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).