help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Changing buffer-local variables to cycle emacs options


From: steve-humphreys
Subject: Changing buffer-local variables to cycle emacs options
Date: Tue, 29 Dec 2020 06:13:51 +0100

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)







reply via email to

[Prev in Thread] Current Thread [Next in Thread]