Author Topic: Make a custom command  (Read 5853 times)

Dan112123

  • Community Member
  • Posts: 44
  • Hero Points: 2
Make a custom command
« on: June 13, 2008, 06:01:35 pm »
Can someone point me to the doc that shows how to make a custom command? I want to create a few custom commands so that, for example, I could press Esc (to show the command line), x, Enter to exit SE.

PS, BTW SE docs are really really hard to navigate and finding stuff is almost impossible.

Lisa

  • Senior Community Member
  • Posts: 238
  • Hero Points: 24
  • User-friendly geek-speak translator extraordinaire
Re: Make a custom command
« Reply #1 on: June 13, 2008, 06:42:28 pm »
Hi Dan. To get to the docs you need, from the main menu, Help > Index, and type in "commands", select "defining with Slick-C":

Defining a Command
The _command primitive is used to define a new command with argument completion. A command can be invoked by typing its name on the SlickEdit® command line, selecting it from a menu item definition, pressing a key, calling it in a Slick-C® function, or typing its name followed by arguments in parentheses in a Slick-C expression. Command procedures always have global scope and can be bound to a key with the Key Bindings option screen (Tools > Options > Keyboard > Key Bindings).

The syntax for defining a command is:
Code: [Select]
_command [TypeName | void] name1[,name2 [,name3... ]( [ArgDecl1, ArgDecl2, ...] )
[name_info(const_exp)]
{
statements
}
[snip]

You can also look in the contents of the Slick-C Macro Programming Guide (Help > Contents, expand "Slick-C Macro Programming") you'll see as the second topic "Four Ways to Use Slick-C". In that topic there is a subsection called "Key Bindable Command" that you also may find useful.

Key Bindable Command
A key bindable command is the most common way to extend the editor. Command macros can be bound to keys or invoked from a menu. To create a Slick-C® command named hello, complete the following steps:

1. Place the macro code below into a new file named test.e:
Code: [Select]
_command void hello()
{
message("Hello World");
}

2. With the file still open, press F12 or use the load command to compile and load the macro. Or, from the main menu, click Macro > Load Module, then browse and select the macro to load.

Now you can type hello in the command line and the message "Hello World" is displayed.
[snip]

Can you be a bit more specific as to what you mean by the docs being hard to navigate? Also we are open to any suggestions for better index terms to help you find what you need. Feel free to send any suggestions and feedback to docs@slickedit.com. I also read every post on these forums and try to respond here as well when there is a doc issue.

Dan112123

  • Community Member
  • Posts: 44
  • Hero Points: 2
Re: Make a custom command
« Reply #2 on: June 15, 2008, 03:50:44 am »
Lisa thatnks for pointing this out. I can't give you an exmple right now but it seems like every time I go searching for something I can't find it. For example "command Line parameters" turns out I need to search for "Invokation Options" or something like that. It doesn't make sense at all.

Anyway the example from the help file can not even be loaded. So I create a file called test.e and put this in there

_command void test(_str filename="") name_info(FILE_ARG)
{
    if (filename=="")
    {
       _message_box("No filename specified");
    }
    message("filename="filename);
}


then I try to load it Macro\Load and Slick Edit gives me this error: "Expecting Constant Expression". How do you debug this error? How do I know what it is expecting.

hs2

  • Senior Community Member
  • Posts: 2754
  • Hero Points: 291
Re: Make a custom command
« Reply #3 on: June 15, 2008, 10:32:46 am »
Hi Dan,
you've to specify (note the required quoted comma)
Code: [Select]
name_info(','FILE_ARG)
Quote
How do I know what it is expecting.
Use the source Dan ;)
IMHO the best resp. fastest method to create a custom macro is to derive it from the stock/product macros.

Regarding the difficulties to find the 'Invocation Options' have a look at this thread for some further details ...

Good luck,
HS2
« Last Edit: June 15, 2008, 10:39:46 am by hs2 »

Lisa

  • Senior Community Member
  • Posts: 238
  • Hero Points: 24
  • User-friendly geek-speak translator extraordinaire
Re: Make a custom command
« Reply #4 on: June 16, 2008, 01:30:40 pm »
Lisa thatnks for pointing this out. I can't give you an exmple right now but it seems like every time I go searching for something I can't find it. For example "command Line parameters" turns out I need to search for "Invokation Options" or something like that. It doesn't make sense at all.

Well, if you were in my head it would make sense :) I can set an index marker called "command line parameters". Thank you for the suggestion. I want to improve the Help and make it easy for you so suggestions like this really help me out. Keep them coming.

Lisa