From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: steve-humphreys@gmx.com Newsgroups: gmane.emacs.help Subject: Re: Changing buffer-local variables to cycle emacs options Date: Tue, 29 Dec 2020 07:28:51 +0100 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40316"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Help Gnu Emacs To: steve-humphreys@gmx.com Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Tue Dec 29 07:29:29 2020 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ku8Vd-000AP6-8U for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 29 Dec 2020 07:29:29 +0100 Original-Received: from localhost ([::1]:54058 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ku8Vc-0008C8-B2 for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 29 Dec 2020 01:29:28 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52704) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ku8V5-0008Bp-CK for help-gnu-emacs@gnu.org; Tue, 29 Dec 2020 01:28:55 -0500 Original-Received: from mout.gmx.net ([212.227.17.21]:53389) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ku8V3-0004Uh-Ci for help-gnu-emacs@gnu.org; Tue, 29 Dec 2020 01:28:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1609223331; bh=AcowwIPcgmeEtDgJjognlSHLLVdIsLpM2i4dYcQophw=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=dg+XiAhXzSYvv1btPCGN8i49PLBiFXtFutkz/AJa/YadP/tNex5kbSpErDRVog5Z6 yKbiM/2VqkB4oPljvrErFwsPd+jItQTounEfhEqHu1A/MH/SsuGmwZ+avsj9bADL8f EKx6+L1zdGxhvifqFIHmoFb5ic8VDWkfnsaj6wro= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Original-Received: from [213.165.168.94] ([213.165.168.94]) by web-mail.gmx.net (3c-app-mailcom-bs13.server.lan [172.19.170.181]) (via HTTP); Tue, 29 Dec 2020 07:28:51 +0100 Importance: normal Sensitivity: Normal In-Reply-To: X-UI-Message-Type: mail X-Priority: 3 X-Provags-ID: V03:K1:FiWw7pcOR8TDJf+EOWKzuuY6zjnepc0kT03d9G7+WdMfL6DJKTwbfcm5uzIPb2Atv86Er J4/t9J/q4wNKHmYxuYqjR7e8rycmH9S3wObqsyYeqF/tOqhpB2LlcMbcTRIOgXOQ/hpscL+k92DQ Mrt232GatfrYFPRhI2+RFaKmR/RmKfukjDAycOWen/o1gGM7bEJog6Jomxl/qLYb0N4dQ0B8Gq0+ MgoREmy9GZ01J0jM1QKl7rtCILAGb+PE/0+21VA634YrnCO/NHnXGYUNCUnQqh0h9XgJKwwhMsfg BQ= X-UI-Out-Filterresults: notjunk:1;V03:K0:3o7BrJJ42CM=:eCysGV7x4neI+sUSMKqsMa tBJegnDYAwxJkomm4Tq5tEZxemmwZyHDC15Ft507kAqXXgx56RnvBV7fuv5KAsi4K4SwhY/ym WX+13jm+BwGvy0mA02rwNEuzaNCe8PzjqCSTMdfA5iwk498mCkzTdBNjHQBQF1sCD6DHrx/jq 9JSNq051ZrujGWko6OGB4uVHigOYYgw2Y8JCapWYWdhtIvWoPhQ72s+j/hbCUXSaH/GFyEy3Z 76TeGtfiE7MorulUaJpAuFjC29SJAaQPpZrW3gkwBO4lMSp3CBL1BIzLL/pF6cdwnbTlyck9L nZgWTGIO0ouvigedodqqRG47iVAJVafey5D6qUPXYgG03rBPK4F+FgPBaLEvp3Dl333Ns9uQR BcKC1mzS8vLsWeRwGgET7PUGzvnA2sJpg1j0bSbv1s+dY9nDu0lvtmE6s6ZruE6c8kaYgL6+R K1goISFu/MNSZ5fz8jGNS+2LXg4+o5/ml3JWmWzgT0ToSQo69e9EGjkmG0d3Hfhhg6gh+l2GE 5VwQlFBxn1iz+LdnEEdnbkK4Jm3nBwa94ZcSh5jaEXew1sjpOGW9pnmJIcxiW8VpkFz29paYj qwUIYqJC8UNfs= Received-SPF: pass client-ip=212.227.17.21; envelope-from=steve-humphreys@gmx.com; helo=mout.gmx.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:126893 Archived-At: ;;(defvar gstate 0) (defun gstate-cycle () "Toggle Display-Line-Numbers mode in all buffers." (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) > Sent: Tuesday, December 29, 2020 at 10:43 AM > From: steve-humphreys@gmx.com > To: "Help Gnu Emacs" > Subject: Changing buffer-local variables to cycle emacs options > > 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 thi= nk > that using defvar is a mistake. Another think is to avoid defining gsta= te > 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 defi= ne > 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) > > > > > >