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

[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: Sat, 20 Apr 2024 17:23:56 +0000

On Sunday, April 21st, 2024 at 4:37 AM, Heime <heimeborgia@protonmail.com> 
wrote:

> On Saturday, April 20th, 2024 at 9:55 PM, Manuel Giraud manuel@ledu-giraud.fr 
> wrote:
> 
> > Heime heimeborgia@protonmail.com writes:
> > 
> > > 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)))) ))
> > 
> > Hi,
> > 
> > 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.
> > 
> > In your previous command, the first thing you did was to switch to
> > another buffer that knows nothing about tema-lugar. I suggest you to
> > read "(elisp) Buffer-Local Variables". -> Manuel Giraud
> 
> Correct, the alist was defined with setq-local for information about the 
> current
> buffer. And I want to print the contents of the alist to a buffer named 
> "tema".

Have come up with the following solution using an intermediate function that
passes the alist as argument.  Can I do this in a more straightforward manner ?

(defun tema-catapult (lugar)
  "Display the content of the association list LUGAR to the tema
buffer.  Because `tema-lugar' was defined with `defvar-local'."

  (with-current-buffer (get-buffer-create "tema")
    (insert (format "%s\n" "tema-lugar:"))
    (dolist (pair lugar)
      (insert (format  "%s %d\n" (car pair) (cdr pair))))) )

(defun tema-alist ()
  "Display the content of the association list tema-lugar."
  (interactive)
  (tema-catapult tema-lugar))




reply via email to

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