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: Changing buffer-local variables to cycle emacs options Date: Tue, 29 Dec 2020 06:13:51 +0100 Message-ID: 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="14749"; mail-complaints-to="usenet@ciao.gmane.io" To: Help Gnu Emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Tue Dec 29 06:14:17 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 1ku7Kr-0003kQ-Bj for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 29 Dec 2020 06:14:17 +0100 Original-Received: from localhost ([::1]:55664 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ku7Kq-0001QY-Dv for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 29 Dec 2020 00:14:16 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:43978) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ku7KX-0001PD-4w for help-gnu-emacs@gnu.org; Tue, 29 Dec 2020 00:13:57 -0500 Original-Received: from mout.gmx.net ([212.227.15.15]:43319) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ku7KV-0002PY-66 for help-gnu-emacs@gnu.org; Tue, 29 Dec 2020 00:13:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1609218831; bh=EVdta4ExrxrINWLNP5S3uB1pxN8vFVlZulKevA6M3B8=; h=X-UI-Sender-Class:From:To:Subject:Date; b=c0UWrwdNxKzfWUPU6yTuOjwsErkfzBzLjqNTwjOJSosXitKWe8d8ElfjzLvoB2271 XLyR4ogKO1TqmkqOuzZqHbktMk2I4RBI6cDGzWOHk2UXyGVy3bcGTHCnw9gExo/gOf 2TLVdjCQVMVh5MfMrwzM1vsQY0Gq6WLyfcCf/Cd0= 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 06:13:51 +0100 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:aHZWdcxc97r6GRMmKvG//QDDNO5uyhYs0of9YtjUYfwJhcC24i4tITu0833bYiYZr53jE dsEuXeVZKoRWxUWe01sZcBrOzvBo/At+6+9BTQamxei8+X2PDJ7SrmY5IuVCTftI6/umYV1QO0w4 b2gXZZhllYLStdXYfs3owIoAOQZtPmSJM7TxuVP2o+DNU9cx9/1Vz6NlURpephD3iFL6OLjo3ELf +3YXr0JU3YpIlbGfKiucRTo84lk88EWdQb3VRCeTUIdT5TD6ihtGf+GBwNyNER0NPY04196AD1Xk F4= X-UI-Out-Filterresults: notjunk:1;V03:K0:Yg2ItyQJ9wI=:ajy5lokRIFs73hUOzYE08c vLXBbEd5rbwotBhq9VBMntYg7RVfLQ/NEmxEUimhpPSuWkOoWzmC1o9IrcU8OhX6vSB12ZARx 2JPN5aOFLZ7MUwuoKgK/x5ndQMcVbP2BUkmzRFwwv+RyPf+PJaFXsv4ivtLm3Y/mpkyTTgB3F uigNIw29DO2GI0igQYr6Uu9xMBxS+OXkfI72pquNOZal2XDaPobCLon2v3NCt9yRDd19EQNfk aukCTRWR1B4Rrbhl3aPMt/JpJYZMbOB+2gC3NsKII87N9IzBheRGM4Iglk0XD2zrDIHabDADN KcVkTgb9zQSyl6pcgA56wLeXOmRLQkOTz0/Ysb9X7PABHmXHiSLJwtw4IYXhqLX8QYZpVrIzD IajlIQR5mxiod0uexMwB/nOfSUoTb2IDUAHXukRKaqMO5Qf8ZrFEw/3HhVb3nfzYxFw0NFxB0 mejg7260Kz5cdIJ2fFpBsCt3V/xxCNi0IEMz+EEK7S4p+n1aJBIb1ddI3PuwjMWfjsI5X7a+P hJD35zSD83mn2M8fjmLxbq17UveADFtt2WwfKYD29MIdKRfhSLF1bs6vIq8htApCpEe/Vgs+3 nudFG6DiyxXgU= Received-SPF: pass client-ip=212.227.15.15; 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:126891 Archived-At: 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) (me= ssage "%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? =2D------- 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)