Detect keyword in ctags

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Detect keyword in ctags

Jussi Hirvi-2
Been wondering about this for a long time.

How can I detect in a ctag if a keyword is present? Here is an example
tag definition:

define_tag('mytag',
         -optional='myparam',
         -optional='mykeyword',
         -encodeNone);

For named parameters I do

   ! local_defined('myparam') ? local('myparam') = whatever;
   ...

But for keywords this does not work. Local_defined('mykeyword') is
always untrue, even if the keyword is present in the function call:

        mytag(-mykeyword)

- Jussi

#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Detect keyword in ctags

Brad Lindsay
Have you tried something like:

params >> 'mykeyword'

(I haven’t tried it either. I would have guessed local_defined would have worked, but looking at the params array might be useful.)

Brad

On August 6, 2015 at 7:41:22 AM, Jussi Hirvi ([hidden email]) wrote:

> Been wondering about this for a long time.
>  
> How can I detect in a ctag if a keyword is present? Here is an example
> tag definition:
>  
> define_tag('mytag',
> -optional='myparam',
> -optional='mykeyword',
> -encodeNone);
>  
> For named parameters I do
>  
> ! local_defined('myparam') ? local('myparam') = whatever;
> ...
>  
> But for keywords this does not work. Local_defined('mykeyword') is
> always untrue, even if the keyword is present in the function call:
>  
> mytag(-mykeyword)
>  
> - Jussi
>  
> #############################################################
>  
> This message is sent to you because you are subscribed to
> the mailing list Lasso [hidden email]
> Official list archives available at http://www.lassotalk.com
> To unsubscribe, E-mail to:  
> Send administrative queries to  
>  


#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Detect keyword in ctags

Jussi Hirvi-2
I made a logical mistake. Local_defined *does* work, only I have used it
in a wrong way. With a keyword I cannot simply init the params like I
usually do with named params:

   ! local_defined('myparam') ? local('myparam') = string;

...because that way myparam will always be an empty string. Instead I
have to do something like:

   local_defined('mykeyword') ? #mykeyword = true | local('mykeyword') =
false;

I don't know why I didn't come to think about this earlier. Maybe this
is too basic to be called a Pilsonism. :-)

- Jussi


On 6.8.2015 17.31, Brad Lindsay wrote:
> Have you tried something like:
>
> params >> 'mykeyword'
>
> (I haven’t tried it either. I would have guessed local_defined would
> have worked, but looking at the params array might be useful.)


#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Detect keyword in ctags

jasonhuck
If you don't mind using a different variable name for the keyword, you can
simplify that to this:

[//lasso
    define_tag('foo', -opt='kwd');
        local('mykwd') = local_defined('kwd');
        return(string(#mykwd));
    /define_tag;

    foo;
    '<br>';
    foo( -kwd);
]


It's probably better to test the params array, as suggested. You just have
to include the dash in the test, e.g.:

[//lasso
    define_tag('foo', -opt='kwd');
        local('kwd') = (params >> '-kwd');
        return(#kwd);
    /define_tag;

    foo;
    '<br>';
    foo( -kwd);
]


- jason





On Thu, Aug 6, 2015 at 11:07 AM, Jussi Hirvi <[hidden email]>
wrote:

> I made a logical mistake. Local_defined *does* work, only I have used it
> in a wrong way. With a keyword I cannot simply init the params like I
> usually do with named params:
>
>   ! local_defined('myparam') ? local('myparam') = string;
>
> ...because that way myparam will always be an empty string. Instead I
> have to do something like:
>
>   local_defined('mykeyword') ? #mykeyword = true | local('mykeyword') =
> false;
>
> I don't know why I didn't come to think about this earlier. Maybe this
> is too basic to be called a Pilsonism. :-)
>
> - Jussi
>
>
> On 6.8.2015 17.31, Brad Lindsay wrote:
>
>> Have you tried something like:
>>
>> params >> 'mykeyword'
>>
>> (I haven’t tried it either. I would have guessed local_defined would
>> have worked, but looking at the params array might be useful.)
>>
>
>
> #############################################################
>
> This message is sent to you because you are subscribed to
>  the mailing list Lasso [hidden email]
> Official list archives available at http://www.lassotalk.com
> To unsubscribe, E-mail to: <[hidden email]>
> Send administrative queries to  <[hidden email]>
>

#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Detect keyword in ctags

Jussi Hirvi-2
Thanks Jason, that's two neat ways. Yes, the second way might be better
because the same name can be used throughout.

- Jussi

On 6.8.2015 18.27, Jason Huck wrote:

> If you don't mind using a different variable name for the keyword, you can
> simplify that to this:
>
> [//lasso
>      define_tag('foo', -opt='kwd');
>          local('mykwd') = local_defined('kwd');
>          return(string(#mykwd));
>      /define_tag;
>
>      foo;
>      '<br>';
>      foo( -kwd);
> ]
>
>
> It's probably better to test the params array, as suggested. You just have
> to include the dash in the test, e.g.:
>
> [//lasso
>      define_tag('foo', -opt='kwd');
>          local('kwd') = (params >> '-kwd');
>          return(#kwd);
>      /define_tag;
>
>      foo;
>      '<br>';
>      foo( -kwd);
> ]
>
>
> - jason


#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>