Hello,
I am having trouble getting a symbol from a string. I _think_ I should be
using (setq src-tags (intern "cperl-tempo-tags")) or something like that.
I am playing with building a menu from a tempo tags list. I have the code
in a hardcoded format:
(defun set-cperl-templates-menu ()
"Setup a menu for cperl template insertion"
(interactive)
(let* ((tags cperl-tempo-tags))
(while tags
(let* ((tag (car tags))
(tag-name (car tag))
(tag-func (cdr tag)))
(add-menu-button '("CPerl")
(vector tag-name tag-func))
(setq tags (cdr tags))
))))
Can anyone point me to how I can abstract this to something like:
(defun set-templates-menu ()
"Setup a menu for current mode template insertion"
(interactive)
(let* ((tags-src (concat (downcase mode-name) "-tempo-tags"))
(tags (intern tags-src)))
(print tags-src (get-buffer "*scratch*"))
(while tags
(let* ((tag (car tags))
(tag-name (car tag))
(tag-func (cdr tag)))
(add-menu-button '("CPerl")
(vector tag-name tag-func))
(setq tags (cdr tags))
))))
I'm getting a listp error, which seems to be due to my 'interned' tags is
just coming back as a string. I can pretty much guarantee that I
misunderstanding some basic lisp syntax, but I can't tell where. I have
tried different approaches with intern, including hardcoded strings:
lisp-tempo-tags
LISP-TEMPO-TAGS
and even
(tags (car (intern "LISP-TEMPO-TAGS"))))
Someone with a clue out there could probably just point me to the 'Right
Thing", which I am missing.
TIA,
Sean
In article <······························@stewthecat.org>,
Sean O'C <······@stewthecat.org> wrote:
>Hello,
> I am having trouble getting a symbol from a string. I _think_ I should be
>using (setq src-tags (intern "cperl-tempo-tags")) or something like that.
Yes, that's the correct way to get the symbol. If you then want the
symbol's value, you need to use (symbol-value src-tags).
--
Barry Margolin, ··············@level3.com
Genuity Managed Services, a Level(3) Company, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
Thanks for your help.
I think I'm still missing something. Hopefully the following code will
show my error:
(let* ((src-name "lisp-tempo-tags")
(src-tags (intern src-name))
(tags (symbol-value 'src-tags))
; (tag-name (car tags))
; (tag-name (car 'tags))
(tag-name (car lisp-tempo-tags))
(msg (format "src tags(%s) tag name(%s)" src-tags tag-name))
)
(print msg (get-buffer "*scratch*"))
)
The first two commented (tag-name (car ...)) fail with type errors
(looking for a list).
The third, uncommented line seems to work. I am trying to figure out how
to get the list according to the current mode, ie:
lisp-tempo-tags
cperl-tempo-tags
php-tempo-tags
...
In php or perl I believe this can be done with variable indirection:
$src-name = "lisp-tempo-tags";
$src-tags = $$src-name;
Is there something (else) I am missing in lisp?
Thanks in advance,
Sean
On Mon, 12 May 2003 20:34:52 +0000, Barry Margolin wrote:
> In article <······························@stewthecat.org>,
> Sean O'C <······@stewthecat.org> wrote:
>>Hello,
>> I am having trouble getting a symbol from a string. I _think_ I should be
>>using (setq src-tags (intern "cperl-tempo-tags")) or something like that.
>
> Yes, that's the correct way to get the symbol. If you then want the
> symbol's value, you need to use (symbol-value src-tags).
In article <······························@stewthecat.org>,
Sean O'C <······@stewthecat.org> wrote:
>Thanks for your help.
>
>I think I'm still missing something. Hopefully the following code will
>show my error:
>(let* ((src-name "lisp-tempo-tags")
> (src-tags (intern src-name))
> (tags (symbol-value 'src-tags))
If you want the value of lisp-tempo-tags, don't quote src-tags there.
--
Barry Margolin, ··············@level3.com
Genuity Managed Services, a Level(3) Company, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Thomas A. Russ
Subject: Re: elisp: getting SYMBOL from a string? intern?
Date:
Message-ID: <ymiwugrn82u.fsf@sevak.isi.edu>
"Sean O'C" <······@stewthecat.org> writes:
Emacs Lisp:
> I think I'm still missing something. Hopefully the following code will
> show my error:
> (let* ((src-name "lisp-tempo-tags")
> (src-tags (intern src-name))
> (tags (symbol-value 'src-tags))
^^^^^^^^^
By quoting this, you are telling Lisp that you want the
symbol value of the symbol SRC-TAGS. Instead, what you
really want is the symbol value of the symbol that src-tags
is bound to. You should eliminate the ' from this code.
That way Lisp will evaluate SRC-TAGS to get the symbol it is
bound to and then return the symbol value of that symbol.
The original code suggestion below correctly omitted the quote
> ; (tag-name (car tags))
> ; (tag-name (car 'tags))
> (tag-name (car lisp-tempo-tags))
> (msg (format "src tags(%s) tag name(%s)" src-tags tag-name))
> )
> (print msg (get-buffer "*scratch*"))
> )
...
> >>Hello,
> >> I am having trouble getting a symbol from a string. I _think_ I should be
> >>using (setq src-tags (intern "cperl-tempo-tags")) or something like that.
> >
> > Yes, that's the correct way to get the symbol. If you then want the
> > symbol's value, you need to use (symbol-value src-tags).
--
Thomas A. Russ, USC/Information Sciences Institute ···@isi.edu
From: Kalle Olavi Niemitalo
Subject: Re: elisp: getting SYMBOL from a string? intern?
Date:
Message-ID: <87vfwf7u3n.fsf@Astalo.kon.iki.fi>
"Sean O'C" <······@stewthecat.org> writes:
> I'm getting a listp error, which seems to be due to my 'interned' tags is
> just coming back as a string.
No, it is coming back as a symbol. I.e.
(car (intern "cperl-tempo-tags"))
is equivalent to
(car 'cperl-tempo-tags)
which signals an error because the symbol is not a list.
You presumably want the effect of
(car cperl-tempo-tags)
which in Emacs Lisp is equivalent to
(car (symbol-value 'cperl-tempo-tags))
and thus
(car (symbol-value (intern "cperl-tempo-tags")))
.
Thanks to those who answered my question (Barry Margolin, Kalle Olavi
Niemitalo). With their help, I was able to get what I was looking for:
;; --- Start snippet -------
(defun set-templates-menu ()
"Setup a menu for current mode template insertion
TODO: better processing of mode-name, could had problems with 'Lisp Interactive' mode...
"
(interactive)
(let* (
(mmode-name (subseq mode-name 0 (search "-" mode-name)))
(src-name (downcase (concat mmode-name "-tempo-tags") ))
(tags (symbol-value (intern src-name)))
(msg (format "src name(%s) tags type(%s) major mode(%s)"
src-name (type-of tags) mmode-name))
)
(print msg (get-buffer "*scratch*"))
(while tags
(let* ((tag (car tags))
(tag-name (car tag))
(tag-func (cdr tag)))
(add-menu-button '("Templates")
(vector tag-name tag-func))
(setq tags (cdr tags))
))
))
;; ------ End snippet --------
As it turns out, it was mostly keeping track of the details. I believe
during my debugging process, I switched to calling 'cperl-tempo-tags'
which had been unloaded in a restart, and generally missing the proper use
of symbol-value.
My next goal is to get a better handle on debugging lisp (primarily easily seeing
the contents of variables, whatever their type (string, cons, vector,...)
Cheers,
Sean
On Mon, 12 May 2003 20:30:03 +0000, Sean O'C wrote:
> Hello,
> I am having trouble getting a symbol from a string. I _think_ I should be
> using (setq src-tags (intern "cperl-tempo-tags")) or something like that.
>
> I am playing with building a menu from a tempo tags list. I have the code
> in a hardcoded format:
>
> (defun set-cperl-templates-menu ()
> "Setup a menu for cperl template insertion"
> (interactive)
> (let* ((tags cperl-tempo-tags))
> (while tags
> (let* ((tag (car tags))
> (tag-name (car tag))
> (tag-func (cdr tag)))
> (add-menu-button '("CPerl")
> (vector tag-name tag-func))
> (setq tags (cdr tags))
> ))))
>
> Can anyone point me to how I can abstract this to something like:
>
> (defun set-templates-menu ()
> "Setup a menu for current mode template insertion"
> (interactive)
> (let* ((tags-src (concat (downcase mode-name) "-tempo-tags"))
> (tags (intern tags-src)))
> (print tags-src (get-buffer "*scratch*"))
> (while tags
> (let* ((tag (car tags))
> (tag-name (car tag))
> (tag-func (cdr tag)))
> (add-menu-button '("CPerl")
> (vector tag-name tag-func))
> (setq tags (cdr tags))
> ))))
>
> I'm getting a listp error, which seems to be due to my 'interned' tags is
> just coming back as a string. I can pretty much guarantee that I
> misunderstanding some basic lisp syntax, but I can't tell where. I have
> tried different approaches with intern, including hardcoded strings:
> lisp-tempo-tags
> LISP-TEMPO-TAGS
> and even
> (tags (car (intern "LISP-TEMPO-TAGS"))))
>
> Someone with a clue out there could probably just point me to the 'Right
> Thing", which I am missing.
> TIA,
>
> Sean