From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Heime Newsgroups: gmane.emacs.help Subject: Re: Printing alist pairs to a dedicated buffur Date: Thu, 25 Apr 2024 11:13:15 +0000 Message-ID: References: <87bk65fpsz.fsf@ledu-giraud.fr> <87plukbbod.fsf@ledu-giraud.fr> <87jzkss5w8.fsf@dataswamp.org> 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="2752"; mail-complaints-to="usenet@ciao.gmane.io" Cc: help-gnu-emacs@gnu.org To: Emanuel Berg Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Thu Apr 25 13:14:14 2024 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 1rzx3O-0000ZT-8y for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 25 Apr 2024 13:14:14 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rzx2o-0001af-2z; Thu, 25 Apr 2024 07:13:38 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rzx2j-0001ZW-BN for help-gnu-emacs@gnu.org; Thu, 25 Apr 2024 07:13:33 -0400 Original-Received: from mail-40135.protonmail.ch ([185.70.40.135]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rzx2f-00052K-NP for help-gnu-emacs@gnu.org; Thu, 25 Apr 2024 07:13:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1714043603; x=1714302803; bh=gm18zQ6gLz7AKGxnpKt5/0P5wzbRIKUkIZd4Vpwh1wo=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=Nt5E7GD3wXpTzbpF4uil8XkvyZVO7hCCZnDdIsX910omCfL3Lir2LPHXSrKxzie6O 9yoJfJ9sGYjquJ0gISzCLS/wGHRXIhcJLja7OwVNeO0NyXxFYj7gbJFQGorNdV2ABl ewtViMJYbPd/oIhckX2cylP5tVMKWo2kotgJXfFg+j9r4iMKI1vHzFC+kf9pkqVfWi aH3dO6PC5CLSWB+zkvOJBLh24Jn5uV3A5R+o+YU8lkuVKRlsuSj9Z3JVZA09XtFO2Z raKxNAsvsvIW3TXm8ySE/knGiMjSVZPDqyPSZBZirTCG6w9SqBKLybqaoPJyB/yOjY ouXloNgRJeyxQ== In-Reply-To: <87jzkss5w8.fsf@dataswamp.org> Feedback-ID: 57735886:user:proton X-Pm-Message-ID: 5d7fdecf665b47b6a2f7c525dd2292c761b88017 Received-SPF: pass client-ip=185.70.40.135; envelope-from=heimeborgia@protonmail.com; helo=mail-40135.protonmail.ch X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-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.29 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-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:146472 Archived-At: Sent with Proton Mail secure email. On Thursday, April 25th, 2024 at 6:48 PM, Emanuel Berg wrote: > Manuel Giraud via Users list for the GNU Emacs text editor wrote: >=20 > > > This is how I am filling my alist named tema-lugar > > >=20 > > > (defun tema-mark (kfrz) > > > "Associate line number at cursor position with key phrase KFRZ." > > > (interactive "sString: ") > > >=20 > > > (let ( (lnum (line-number-at-pos)) ) > > >=20 > > > (setq-local tema-lugar > > > (append tema-lugar > > > (list (cons kfrz lnum)))) )) > >=20 > > Maybe your error comes from this `setq-local'. I have used` defvar' whi= ch will create a global (i.e. visible everywhere > > in Emacs) variable. `setq-local' or` defvar-local' are used > > for buffer-local variables. Buffer-local variables are > > visible only from the buffer they were created. >=20 >=20 > Don't use `defvar' if it can be avoided as that creates global dynamic/sp= ecial variables,` setq' creates global > static/lexical variables which isn't much better - unless > there is a variable by that name present, then that is used > instead. That kind of `setq' use is not wrong, actually it is good.=20 So it is actually good, but then still make a commotion about it. This way of commenting in not productive at all. > But yes, variables in Emacs are complicated and one problem is that=20 > so much is dependent on the situation while the commands look the=20 > same. Anyway here is an interesting case, a combination of a for=20 > and while loop, and we see the kind of good` setq' use I mean, > which do not create a global variable but sets an existing > one, "lst", instead. >=20 > (defun count-list (lst) > (cl-loop > with res =3D () > for l in lst while lst do > (push (list (cl-count l lst) l) res) > (setq lst (cl-remove l lst)) > finally return (cl-sort res #'>=3D :key #'car) )) >=20 >=20 > ;; (count-list '(a b c d e a b c d a b c a b a)) > ;; -> ((5 a) (4 b) (3 c) (2 d) (1 e)) My defvar is used to store values that I need to access=20 when I am working on a buffer. I can add to it as I modify the buffer, or delete from it. I cannot see why all this=20 fuss not to use global variables.