* How do I use a var as a string?
@ 2016-07-28 16:42 Tom Browder
2016-07-28 16:47 ` Drew Adams
` (2 more replies)
0 siblings, 3 replies; 13+ messages in thread
From: Tom Browder @ 2016-07-28 16:42 UTC (permalink / raw)
To: help-gnu-emacs
I want to bind a string to a variable and then use the variable name as the
string when a string is expected. I have tried variations of this:
(defvar my-str (concat "my " "string"))
(print my-str)
and get an error about void symbol my-str.
I have tried putting an apostrophe in front of various places but haven't
yet found a working solution. So how can I define a variable whose value
is a string and then access the actual string value by using the variable
name?
Thanks.
Best regards,
-Tom
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: How do I use a var as a string?
[not found] <mailman.2209.1469724157.26859.help-gnu-emacs@gnu.org>
@ 2016-07-28 16:46 ` Emanuel Berg
0 siblings, 0 replies; 13+ messages in thread
From: Emanuel Berg @ 2016-07-28 16:46 UTC (permalink / raw)
To: help-gnu-emacs
Tom Browder wrote:
> So how can I define a variable whose value is
> a string and then access the actual string
> value by using the variable name?
For example like this:
(defun print-string (s)
(insert "The string is: " s) )
(setq sail-ho-string "True sailing is dead!")
(print-string sail-ho-string)
--
underground experts united .... http://user.it.uu.se/~embe8573
Emacs Gnus Blogomatic ......... http://user.it.uu.se/~embe8573/blogomatic
- so far: 58 Blogomatic articles -
^ permalink raw reply [flat|nested] 13+ messages in thread
* RE: How do I use a var as a string?
2016-07-28 16:42 How do I use a var as a string? Tom Browder
@ 2016-07-28 16:47 ` Drew Adams
2016-07-28 17:11 ` Tom Browder
[not found] ` <mailman.2218.1469725870.26859.help-gnu-emacs@gnu.org>
2016-07-29 14:50 ` Tom Browder
2016-07-29 16:52 ` Tom Browder
2 siblings, 2 replies; 13+ messages in thread
From: Drew Adams @ 2016-07-28 16:47 UTC (permalink / raw)
To: Tom Browder, help-gnu-emacs
> (defvar my-str (concat "my " "string"))
> (print my-str)
>
> and get an error about void symbol my-str.
It works for me. Did you evaluate the `defvar', before trying to
evaluate the `print' - it sounds like you did not.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: How do I use a var as a string?
2016-07-28 16:47 ` Drew Adams
@ 2016-07-28 17:11 ` Tom Browder
[not found] ` <mailman.2218.1469725870.26859.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 13+ messages in thread
From: Tom Browder @ 2016-07-28 17:11 UTC (permalink / raw)
To: Drew Adams; +Cc: help-gnu-emacs@gnu.org
On Thursday, July 28, 2016, Drew Adams <drew.adams@oracle.com> wrote:
> > (defvar my-str (concat "my " "string"))
> > (print my-str)
> >
> > and get an error about void symbol my-str.
>
> It works for me. Did you evaluate the `defvar', before trying to
> evaluate the `print' - it sounds like you did not.
>
Duh, no I didn't! Then it does work! (I should be evaling the buffer for
the experimenting I'm doing.)
Thanks, Drew.
-Tom
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: How do I use a var as a string?
[not found] ` <mailman.2218.1469725870.26859.help-gnu-emacs@gnu.org>
@ 2016-07-29 2:39 ` Emanuel Berg
0 siblings, 0 replies; 13+ messages in thread
From: Emanuel Berg @ 2016-07-29 2:39 UTC (permalink / raw)
To: help-gnu-emacs
Tom Browder wrote:
> Duh, no I didn't! Then it does work! (I
> should be evaling the buffer for the
> experimenting I'm doing.)
You can, with `load-file' and then RET (no
input data implies the current buffer), but it
is more to the point to use either
`eval-last-sexp' (C-x C-e) or `eval-defun'
which I have C-m.
--
underground experts united .... http://user.it.uu.se/~embe8573
Emacs Gnus Blogomatic ......... http://user.it.uu.se/~embe8573/blogomatic
- so far: 58 Blogomatic articles -
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: How do I use a var as a string?
2016-07-28 16:42 How do I use a var as a string? Tom Browder
2016-07-28 16:47 ` Drew Adams
@ 2016-07-29 14:50 ` Tom Browder
2016-07-29 14:59 ` Drew Adams
2016-07-29 16:52 ` Tom Browder
2 siblings, 1 reply; 13+ messages in thread
From: Tom Browder @ 2016-07-29 14:50 UTC (permalink / raw)
To: help-gnu-emacs@gnu.org
On Thursday, July 28, 2016, Tom Browder <tom.browder@gmail.com> wrote:
> I want to bind a string to a variable and then use the variable name as
> the string when a string is expected. I have tried variations of this:
>
> (defvar my-str (concat "my " "string"))
>
My next experiment will be to use "(defconst ...)" which I'm hoping will
solve the problem.
-Tom
^ permalink raw reply [flat|nested] 13+ messages in thread
* RE: How do I use a var as a string?
2016-07-29 14:50 ` Tom Browder
@ 2016-07-29 14:59 ` Drew Adams
2016-07-29 15:06 ` Tom Browder
0 siblings, 1 reply; 13+ messages in thread
From: Drew Adams @ 2016-07-29 14:59 UTC (permalink / raw)
To: Tom Browder, help-gnu-emacs
> > I want to bind a string to a variable and then use the variable name as
> > the string when a string is expected. I have tried variations of this:
> > (defvar my-str (concat "my " "string"))
>
> My next experiment will be to use "(defconst ...)" which I'm hoping will
> solve the problem.
What problem? It's not clear (to me) what you are trying to do.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: How do I use a var as a string?
2016-07-29 14:59 ` Drew Adams
@ 2016-07-29 15:06 ` Tom Browder
0 siblings, 0 replies; 13+ messages in thread
From: Tom Browder @ 2016-07-29 15:06 UTC (permalink / raw)
To: Drew Adams; +Cc: help-gnu-emacs@gnu.org
On Friday, July 29, 2016, Drew Adams <drew.adams@oracle.com> wrote:
> > > I want to bind a string to a variable and then use the variable name as
> > > the string when a string is expected. I have tried variations of this:
> > > (defvar my-str (concat "my " "string"))
...
> > My next experiment will be to use "(defconst ...)" which I'm hoping will
> > solve the problem.
>
> What problem? It's not clear (to me) what you are trying to do.
>
In the beginning of this thread I mentioned I was getting an error when
trying to use the var in another definition.
-Tom
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: How do I use a var as a string?
2016-07-28 16:42 How do I use a var as a string? Tom Browder
2016-07-28 16:47 ` Drew Adams
2016-07-29 14:50 ` Tom Browder
@ 2016-07-29 16:52 ` Tom Browder
2016-07-29 17:20 ` John Mastro
2 siblings, 1 reply; 13+ messages in thread
From: Tom Browder @ 2016-07-29 16:52 UTC (permalink / raw)
To: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 1286 bytes --]
On Thu, Jul 28, 2016 at 11:42 AM, Tom Browder <tom.browder@gmail.com> wrote:
> I want to bind a string to a variable and then use the variable name as the
> string when a string is expected. I have tried variations of this:
>
> (defvar my-str (concat "my " "string"))
Here is the best I can do for the moment to show my actual problem.
The code is from an attempt at modifying the following code chunk
which is part of the file "perl6-imenu.el" (branch "my-branch") found
at my github account at:
https://github.com/tbrowder/perl6-mode
The working code chunk is at:
https://gist.github.com/tbrowder/effb3ed0540591506015846b0511a045
and the chunk I'm trying to replace it with is here:
https://gist.github.com/tbrowder/7959e77fcf5aee4be3edb342503cc282
The substitution of the explicit regex with the string var doesn't
work. It may be because of some problem with the scope of the
variables, and that is WAY beyond my elisp understanding at the
moment.
If someone can show me a short, complete example that shows a var
replacing an explicit regex that works I would greatly appreciate it.
I have attached a short Perl 6 test file for testing the perl6-mode if
anyone is interested (file 'test-imenu.p6'; it does NOT require Perl 6
to be installed).
Best regards,
-Tom
[-- Attachment #2: test-imenu.p6 --]
[-- Type: application/octet-stream, Size: 284 bytes --]
# file: test-imenu.p6
# Perl 6 syntax file for testing perl6-mode with imenu support, which is located at:
#
# https://github.com/tbrowder/perl6-mode [branch: "my-branch"]
my $a;
my @b;
our %c;
sub a(){my @ze}
multi sub x() {}
method d() {}
my multi method z() {}
multi c() {}
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: How do I use a var as a string?
2016-07-29 16:52 ` Tom Browder
@ 2016-07-29 17:20 ` John Mastro
2016-07-29 17:24 ` John Mastro
0 siblings, 1 reply; 13+ messages in thread
From: John Mastro @ 2016-07-29 17:20 UTC (permalink / raw)
To: help-gnu-emacs@gnu.org; +Cc: Tom Browder
Tom Browder <tom.browder@gmail.com> wrote:
> Here is the best I can do for the moment to show my actual problem.
> The code is from an attempt at modifying the following code chunk
> which is part of the file "perl6-imenu.el" (branch "my-branch") found
> at my github account at:
>
> https://github.com/tbrowder/perl6-mode
>
> The working code chunk is at:
>
> https://gist.github.com/tbrowder/effb3ed0540591506015846b0511a045
>
> and the chunk I'm trying to replace it with is here:
>
> https://gist.github.com/tbrowder/7959e77fcf5aee4be3edb342503cc282
>
> The substitution of the explicit regex with the string var doesn't
> work. It may be because of some problem with the scope of the
> variables, and that is WAY beyond my elisp understanding at the
> moment.
I haven't followed this discussion in detail, but try this[1].
You used a quoted list in your definition of
perl6-imenu-generic-expression, meaning the list isn't evaluated,
meaning it contained the symbol `perl6-vars' rather than the value bound
to that symbol (the regular expression you constructed). Instead, you
probably want to use backquote.
This is all a bit difficult to explain succinctly in an email, but this
is a common point of confusion so there's plenty of material on "quote"
and "backquote" (or sometimes "quasiquote") in Lisp out there. In
Emacs's Elisp manual, check out the node "(elisp) Backquote".
[1] https://gist.github.com/johnmastro/53535e8cbddf7c669788bc2a9105f70e
Hope that helps
John
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: How do I use a var as a string?
2016-07-29 17:20 ` John Mastro
@ 2016-07-29 17:24 ` John Mastro
2016-07-29 17:56 ` Tom Browder
0 siblings, 1 reply; 13+ messages in thread
From: John Mastro @ 2016-07-29 17:24 UTC (permalink / raw)
To: help-gnu-emacs@gnu.org; +Cc: Tom Browder
John Mastro <john.b.mastro@gmail.com> wrote:
> I haven't followed this discussion in detail, but try this[1].
One thing I can say with confidence is that the issue is not related to
`defvar' vs. `defconst' :)
John
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: How do I use a var as a string?
2016-07-29 17:24 ` John Mastro
@ 2016-07-29 17:56 ` Tom Browder
2016-07-29 18:39 ` Tom Browder
0 siblings, 1 reply; 13+ messages in thread
From: Tom Browder @ 2016-07-29 17:56 UTC (permalink / raw)
To: John Mastro; +Cc: help-gnu-emacs@gnu.org
On Friday, July 29, 2016, John Mastro <john.b.mastro@gmail.com> wrote:
> John Mastro <john.b.mastro@gmail.com <javascript:;>> wrote:
> > I haven't followed this discussion in detail, but try this[1].
That looks like an excellent lead, John (and not easy to find for a noob
without help from old heads). I read the entries in the elisp manual and
am anxious to try it.
One thing I can say with confidence is that the issue is not related to
> `defvar' vs. `defconst' :)
Well I can confirm that now, too!
Thanks so much--I'll report back after I get back to my PC.
Best regards,
-Tom
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: How do I use a var as a string?
2016-07-29 17:56 ` Tom Browder
@ 2016-07-29 18:39 ` Tom Browder
0 siblings, 0 replies; 13+ messages in thread
From: Tom Browder @ 2016-07-29 18:39 UTC (permalink / raw)
To: John Mastro; +Cc: help-gnu-emacs@gnu.org
On Fri, Jul 29, 2016 at 12:56 PM, Tom Browder <tom.browder@gmail.com> wrote:
> On Friday, July 29, 2016, John Mastro <john.b.mastro@gmail.com> wrote:
>> John Mastro <john.b.mastro@gmail.com> wrote:
>> > I haven't followed this discussion in detail, but try this[1].
...
> Thanks so much--I'll report back after I get back to my PC.
Okay, it worked!!!! I changed this def:
(defvar perl6-imenu-generic-expression
'( ; <= note quote (') instead of backquote (`)
; note explicit regex string below as second list item:
("Variables"
"^\\s-*\\(?:my\\|our\\)\\s-+\\(\\(?:\\$\\|@\\|%\\)\\(?:[_[:alnum:]]+\\)\\)"
1)
))
to this:
(defvar perl6-imenu-generic-expression
`( ; <= note backquote (`) instead of quote (')
; note regex string variable below (perl6-vars) as
second list item:
("Variables" ,perl6-vars 1) ; <= note comma immediately before the
regex var name (perl6-vars)
))
Thank you John! You da man!!
Best regards, and happy elisping,
-Tom
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2016-07-29 18:39 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-28 16:42 How do I use a var as a string? Tom Browder
2016-07-28 16:47 ` Drew Adams
2016-07-28 17:11 ` Tom Browder
[not found] ` <mailman.2218.1469725870.26859.help-gnu-emacs@gnu.org>
2016-07-29 2:39 ` Emanuel Berg
2016-07-29 14:50 ` Tom Browder
2016-07-29 14:59 ` Drew Adams
2016-07-29 15:06 ` Tom Browder
2016-07-29 16:52 ` Tom Browder
2016-07-29 17:20 ` John Mastro
2016-07-29 17:24 ` John Mastro
2016-07-29 17:56 ` Tom Browder
2016-07-29 18:39 ` Tom Browder
[not found] <mailman.2209.1469724157.26859.help-gnu-emacs@gnu.org>
2016-07-28 16:46 ` Emanuel Berg
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.