Author Topic: Using system environment variables  (Read 3353 times)

gglezman

  • Junior Community Member
  • Posts: 4
  • Hero Points: 0
Using system environment variables
« on: June 30, 2009, 03:32:44 pm »
I would like to reference system environment variables from within
slick edit.  For example, I have a windows environment variable TMP
which is set to c:\Documents and Settings\mylogin\Local Settings\Temp.

I would like to be able to edit a file in TMP without typing the entire
string. 

In xemacs (under Linux) I would edit
     $TMP/fileName

Is there a way to reference a system environment variable when executing
a slick edit command?

Thanks
Greg

Graeme

  • Senior Community Member
  • Posts: 1921
  • Hero Points: 221
Re: Using system environment variables
« Reply #1 on: July 01, 2009, 11:35:03 am »
The following code might give you an idea.  Copy it into a file e.g. test.e and load it using the load module command on the macro menu.

If you then type myev mym TMP on the slick command line, it should show the content of the system environment variable on the command line.  The command myev gets called and the parameter passed to it is 'mym TMP'.  The parse command assigns 'TMP' to s2 and get_env gets the value of environment variable TMP.

See also the "directory aliases" topic in the help.  To expand an alias on the slick command line, use Ctrl+Shift+O.  You can embed an environment variable in an alias using e.g. %TMP%.  (tools -> options -> editing -> global aliases).

Graeme


Code: [Select]
#include "slick.sh"

#pragma option(strictsemicolons,on)
#pragma option(strict,on)
#pragma option(autodecl,off)
#pragma option(strictparens,on)

_command void myev(_str cmd = '') name_info(',')
{
   _str s1,s2;
   parse cmd with s1 s2;
   int index = find_index(s1);
   if (!index_callable(index) ) {
     message('command not found : ' :+ s1);
   } else {
     call_index(get_env(s2),index);
   }
}


_command void mym(_str st = '') name_info(',')
{
   message(st);
}


« Last Edit: July 01, 2009, 11:42:14 am by Graeme »

Matthew

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 990
  • Hero Points: 44
Re: Using system environment variables
« Reply #2 on: July 01, 2009, 03:25:06 pm »
Here's a less complete approach, but should meet your specific needs.

Code: [Select]
_command void envedit(_str filenameArg='') name_info(FILE_MAYBE_LIST_BINARIES_ARG'*,'VSARG2_CMDLINE|VSARG2_REQUIRES_MDI|VSARG2_NOEXIT_SCROLL)
{
   _str filename=prompt(filenameArg);
   filename = _replace_envvars(filename);
   edit(filename);
}

gglezman

  • Junior Community Member
  • Posts: 4
  • Hero Points: 0
Re: Using system environment variables
« Reply #3 on: July 02, 2009, 01:40:18 pm »
Graeme,
Thanks for the response.  You've given me plenty to work with.
Greg

gglezman

  • Junior Community Member
  • Posts: 4
  • Hero Points: 0
Re: Using system environment variables
« Reply #4 on: July 02, 2009, 01:50:20 pm »
Matthew,
Thanks for taking time out to respond. 
I ran into a problem when I loaded the command :
     Identifier 'FILES-MAYBE-LIST-BINARY-ARG' not declared
I'm running version 11.0.1.  Maybe that's the problem.  I
removed the identifier, reloaded and ran the command.  Unfortunately
it didn't do the replacement. To see what it was doing, I replaced
    edit(filename)   with
    message(filename)
No translation/substitution was done. 
Also, I can't find a reference to _replace_envvars().  Maybe it
was introduced after version 11.0.1?

Thanks
Greg

Matthew

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 990
  • Hero Points: 44
Re: Using system environment variables
« Reply #5 on: July 02, 2009, 02:16:18 pm »
That function was there in 11.0.x (in stdprocs.e), and it doesn't look like it's changed much in the past few years. Perhaps assign the return value to a temp variable rather than overwriting the original.
Since you're on Windows, you'll need to use the %VARNAME% format, rather than the Unix-y $VARNAME style.

gglezman

  • Junior Community Member
  • Posts: 4
  • Hero Points: 0
Re: Using system environment variables
« Reply #6 on: July 02, 2009, 06:03:58 pm »
Matthew,
Got it working.  The reference to stdprocs.e made the difference.

Graeme,

I settled on aliases.  I found that after expanding an alias on the edit line,
slickedit responds to the space bar (ie expands current string, prompts for
next part of path,...). 

Thanks guys
Greg