Author Topic: Macro function to display text in the status line?  (Read 6496 times)

timur

  • Senior Community Member
  • Posts: 204
  • Hero Points: 3
Macro function to display text in the status line?
« on: March 07, 2013, 12:20:52 AM »
Is there a macro function that displays some text in the status line?

shadowbane

  • Community Member
  • Posts: 85
  • Hero Points: 4
Re: Macro function to display text in the status line?
« Reply #1 on: March 07, 2013, 12:29:53 AM »
message() and messageNwait() do the trick.

IanG

  • Community Member
  • Posts: 18
  • Hero Points: 0
Re: Macro function to display text in the status line?
« Reply #2 on: March 14, 2014, 01:28:13 PM »
I am trying to use this to debug macro code but it doesn't actually pause the text. Should the following code work?

Code: [Select]
   _str r_vlx = _config_path() :+ FILESEP :+ R1_LEXER_NAME :+ ".vlx";
   if (file_exists(r_vlx)) {
      messageNwait("Loaded lexer: " :+ r_vlx);
      cload(r_vlx);
   }
   else {
      messageNwait("Missing file: " :+ r_vlx);
   }

The file doesn't exist, or rather, the filename is wrong, possibly because FILESEP is set wrongly on my linux system. But either case should show a text until I press a key, I think. Another possibility is that it's not really reloading the macro and is executing an old version.

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: Macro function to display text in the status line?
« Reply #3 on: March 14, 2014, 03:58:43 PM »
messageNwait shows the message, repaints the screen, and waits for a key.

If that's not happening, I'm going to go out on a limb and say the code isn't being reached.

IanG

  • Community Member
  • Posts: 18
  • Hero Points: 0
Re: Macro function to display text in the status line?
« Reply #4 on: March 14, 2014, 05:24:26 PM »
I've tried moving the code to the top of my function; not sure if that made any difference but if I watch really closely when I run it, the message "Missing file: "... flashes past on the status bar at the bottom. I also tried changing the text to confirm the new code is being run; it is.

Very strange.

IanG

  • Community Member
  • Posts: 18
  • Hero Points: 0
Re: Macro function to display text in the status line?
« Reply #5 on: March 14, 2014, 06:17:10 PM »
Some additional insight. When I take the code out and make a simple command like this, it works from the command line by say_hello:
Code: [Select]
#pragma option(strict,on)
#include "slick.sh"

_command void say_hello() name_info(',')
{
   messageNwait("Hello World. Hit a key.");
}

However it does not work when I put the same code inside the defload() function of my language definition:
Code: [Select]
#pragma option(strict,on)
#include "slick.sh"

#define R1_MODE_NAME  "R1"              // appears in "Select Mode" pane
#define R1_LEXER_NAME "R1"              // name of file. Assumed name of lexer.
#define R1_EXTENSION1 "r"               // canonical extension
#define R1_EXTENSION2 "R"               // alternative extension
#define R1_LANGUAGE_ID R1_EXTENSION1    // internal use only?

///////////////////////////////////////////////////////////////////////////////
// This function is called when the module is loaded.  It configures the
// "R" and "r" file extensions, sets up the language ID, line numbers, etc.

defload()
{
   messageNwait("Hello World. Hit a key.");

   // This is not traditionally at the top here. I've put it here just to
   // make sure that the code is executed.

   _str r_vlx = _config_path() :+ FILESEP :+ R1_LEXER_NAME :+ ".vlx";
   if (file_exists(r_vlx)) {
      messageNwait("Loaded lexer: " :+ r_vlx);
      cload(r_vlx);
   }
   else {
      messageNwait("Missing file: " :+ r_vlx);
   }

   // We set some parameters and leave others out. Inside _CreateLanguage() these
   // actually get [re-]packaged as a setup_info string anyway.

   _str compile_info   = "";                        // no compiling for you!
   _str syntax_info    = "4 1 3";                   // Whiskey Tango Foxtrot?
   _str be_info        = "";                        // Begin/End pairs
   _str include_info   = "";
   _str word_chars     = "";
   _str lexer_name     = R1_LEXER_NAME;             // color coding lexer name
   _str color_flags    = "1";                       // color flags

   _str setup_info     = "MN="R1_MODE_NAME",":+    // mode name
                         "TABS=+4,":+              // tabs
                         "MA=1 74 1,":+            // margins
                         "KEYTAB=ext-keys,":+      // key table
                         "WW=1,":+                 // word wrap
                         "IWT=0,":+                // indent with tabs OFF
                         "ST=8,":+                 // show special characters
                         "IN=2,":+                 // indent style
                         "WC="word_chars",":+      // word chars
                         "LN="lexer_name",":+      // lexer name
                         "CF="color_flags",":+     // color flags
                         "LNL=6,":+                // line numbering ON
                         "TL=0,":+                 // truncate length
                         "BNDS=,";                 // bounds

   // OK, got all our things
   _CreateLanguage( R1_LANGUAGE_ID, R1_MODE_NAME, setup_info, compile_info, syntax_info, be_info);
   _CreateExtension( R1_EXTENSION1, R1_EXTENSION1 );
   _CreateExtension( R1_EXTENSION2, R1_EXTENSION1 );

}

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: Macro function to display text in the status line?
« Reply #6 on: March 14, 2014, 11:40:56 PM »
Maybe defload() occurs before the input engine has been initialized, thus the wait for keypress fails and the macro continues.

If this is for debugging purposes, consider using say() to do printf-style debugging.

IanG

  • Community Member
  • Posts: 18
  • Hero Points: 0
Re: Macro function to display text in the status line?
« Reply #7 on: March 15, 2014, 03:04:18 AM »
If this is for debugging purposes, consider using say() to do printf-style debugging.

Thanks, I tried this and it works. Thanks for the suggestion. Also _message_box() works nicely. So I am actually using that - inside a language parser (which might be loaded by someone else) a popup box is probably nicer than a debug window.