[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Printing alist pairs to a dedicated buffur
From: |
Heime |
Subject: |
Re: Printing alist pairs to a dedicated buffur |
Date: |
Thu, 25 Apr 2024 11:13:15 +0000 |
Sent with Proton Mail secure email.
On Thursday, April 25th, 2024 at 6:48 PM, Emanuel Berg <incal@dataswamp.org>
wrote:
> Manuel Giraud via Users list for the GNU Emacs text editor wrote:
>
> > > This is how I am filling my alist named tema-lugar
> > >
> > > (defun tema-mark (kfrz)
> > > "Associate line number at cursor position with key phrase KFRZ."
> > > (interactive "sString: ")
> > >
> > > (let ( (lnum (line-number-at-pos)) )
> > >
> > > (setq-local tema-lugar
> > > (append tema-lugar
> > > (list (cons kfrz lnum)))) ))
> >
> > Maybe your error comes from this `setq-local'. I have used` defvar' which
> > 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.
>
>
> Don't use `defvar' if it can be avoided as that creates global
> dynamic/special 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.
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
> so much is dependent on the situation while the commands look the
> same. Anyway here is an interesting case, a combination of a for
> 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.
>
> (defun count-list (lst)
> (cl-loop
> with res = ()
> 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 #'>= :key #'car) ))
>
>
> ;; (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
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
fuss not to use global variables.
- Printing alist pairs to a dedicated buffur, Heime, 2024/04/19
- Re: Printing alist pairs to a dedicated buffur, Manuel Giraud, 2024/04/19
- Re: Printing alist pairs to a dedicated buffur, Heime, 2024/04/19
- Re: Printing alist pairs to a dedicated buffur, Heime, 2024/04/19
- Re: Printing alist pairs to a dedicated buffur, Manuel Giraud, 2024/04/20
- Re: Printing alist pairs to a dedicated buffur, Heime, 2024/04/20
- Re: Printing alist pairs to a dedicated buffur, Heime, 2024/04/20
- Re: Printing alist pairs to a dedicated buffur, Yuri Khan, 2024/04/20
- Re: Printing alist pairs to a dedicated buffur, Emanuel Berg, 2024/04/25
- Re: Printing alist pairs to a dedicated buffur,
Heime <=
- Re: Printing alist pairs to a dedicated buffur, Emanuel Berg, 2024/04/26
- RE: [External] : Re: Printing alist pairs to a dedicated buffur, Drew Adams, 2024/04/25
- RE: [External] : Re: Printing alist pairs to a dedicated buffur, Heime, 2024/04/25
- Re: [External] : Re: Printing alist pairs to a dedicated buffur, Emanuel Berg, 2024/04/25
- Re: [External] : Re: Printing alist pairs to a dedicated buffur, Emanuel Berg, 2024/04/25
- RE: [External] : Re: Printing alist pairs to a dedicated buffur, Drew Adams, 2024/04/25
- Re: [External] : Re: Printing alist pairs to a dedicated buffur, Emanuel Berg, 2024/04/26
- RE: [External] : Re: Printing alist pairs to a dedicated buffur, Drew Adams, 2024/04/26
- RE: [External] : Re: Printing alist pairs to a dedicated buffur, Heime, 2024/04/26
- Re: [External] : Re: Printing alist pairs to a dedicated buffur, Yuri Khan, 2024/04/26