[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: when you gotta have a variable value for a symbol name

From: Pascal J. Bourguignon
Subject: Re: when you gotta have a variable value for a symbol name
Date: Thu, 24 Jul 2014 00:12:28 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Drew Adams <address@hidden> writes:

>> I want to evaluate (kmacro-name-last-macro variable), where I want the
>> value of "variable" passed as the symbol name. Despite years of trying,
>> I don't think I ever really conceptually "got" the distinction between
>> symbols and variables and that seems to be critical here. I'm working
>> with the code below, but it is not suceeding in naming the macros (no
>> error messages, however). Of course (kmacro-name-last-macro 'my-macro)
>> works just fine.
>> (defun name-my-macro-sequentially ()
>>    "Names the last recorded macro as my-macro#, where # is a number
>> sequentially incremented"
>>     (interactive)
>>     (unless (boundp 'my-macro-counter) (setq my-macro-counter 0))
>>     (setq my-macro-counter (1+ my-macro-counter))
>>     (let ((macro-name (format "my-macro-%d" my-macro-counter)))
>>        (kmacro-name-last-macro (make-symbol macro-name))
>                                   ^^^^^^^^^^^
>>        (message "named keyboard macro %s" macro-name)))
> Change `make-symbol' to `intern' and you're good to go.  `make-symbol'
> returns an uninterned symbol.

And use:

   (defvar my-macro-counter 0)
   (defun …

instead of:

   (defun …
      (unless (boundp 'my-macro-counter) (setq my-macro-counter 0))

__Pascal Bourguignon__       
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk

reply via email to

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