Author Topic: Invoking an alias  (Read 1341 times)

jporkkahtc

  • Senior Community Member
  • Posts: 1684
  • Hero Points: 162
  • Text
Invoking an alias
« on: August 26, 2014, 07:02:31 pm »
Dumb question: How do I invoke the "include_once" alias?


Graeme

  • Senior Community Member
  • Posts: 2233
  • Hero Points: 278
Re: Invoking an alias
« Reply #1 on: August 27, 2014, 12:16:34 pm »
Dumb question: How do I invoke the "include_once" alias?
Looks like you need to click the plus icon down by the parameters window and add an entry that allows you to enter the name of the relevant preprocessor symbol i.e.
name = macro
prompt = Enter macro name
initial value  =


jporkkahtc

  • Senior Community Member
  • Posts: 1684
  • Hero Points: 162
  • Text
Re: Invoking an alias
« Reply #2 on: August 27, 2014, 09:00:26 pm »
It already has that.


So, normally I'd expect that just typing "include_once<space>" would invoke this alias, but it doesn't.


I haven't figured out what the explicit command is either.


For most things, it "just works".


What I'd like is an alias that would auto-magically add #ifdef guards in a header, like
#ifndef FOO_H
#define FOO_H
#endif // FOO_H


Where "FOO_H" is derived from the filename, "Foo.h"


I was able to create a global alias that mostly works:

 
#ifndef %\f%\mlinewrap_rubout%%\mlinewrap_rubout%%\mupcase_word%%\mlinewrap_rubout%_H #define %\f%\mlinewrap_rubout%%\mlinewrap_rubout%%\mupcase_word%%\mlinewrap_rubout%_H #endif // %\f%\mlinewrap_rubout%%\mlinewrap_rubout%%\mupcase_word%%\mlinewrap_rubout%_H %\l 
Though, it seems kind of ugly, and it doesn't put the #endif at the bottom of the file.
Surely, there is a better way?
Maybe it simply need to be a macro, and not an alias?
Possible bug: Note the extra mlinewrap_rubout after the upper-casing.
[/size]This is needed because without it, the upper-casing inserts a "0" - zero.
[/pre]
[/size]Wierd.
[/pre]
[/size]
[/pre]

Graeme

  • Senior Community Member
  • Posts: 2233
  • Hero Points: 278
Re: Invoking an alias
« Reply #3 on: August 28, 2014, 01:38:54 pm »
I suspect the inserted zero character is because upcase_word returns a zero which the alias handler converts to a string.
I think you're right, a macro is better so I wrote one  - my_header_guards.  I've added a gui-id onto the end of the header guard string- you can delete if you don't want.  I've added some code for a popup menu that lets you invoke the macro.  I have a menu of my favourite commands bound to Ctrl M.


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

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


 
_command void my_header_guards() name_info(','VSARG2_REQUIRES_EDITORCTL)
{
   typeless p;
   _str xyz = upcase(strip_filename(p_buf_name, "PDE")) :+ "_H_" :+ guid_create_string("N");
   insert_line("#ifndef " :+ xyz);
   insert_line("#define " :+ xyz);
   insert_line("");
   save_pos(p);

   bottom();
   insert_line("#endif //" :+ xyz);
   restore_pos(p);
}
 
 
 
_command show_my_fave_cmds4()
{
   mou_show_menu('fave_cmds4');
}
 
 
_menu fave_cmds4 {
   //"favourite commands #4","","","","";
   submenu "More","","","" {
      "complete-prev-no-dup","complete_prev_no_dup","","","";
      "complete-next-no-dup","complete_next_no_dup","","","";
      "complete-prev","complete_prev","","","";
      "complete-next","complete_next","","","";
      "complete-list","complete_list","","","";
      "complete-more","complete_more","","","";
      "--","","","","";
      "select-code-block","select_code_block","","","";
      "hide-code-block","hide_code_block","","","";
      "hide-selection","hide_selection","","","";
      "hide-comments","hide_all_comments","","","";
      "select-paren","select_paren_block","","","";
      "show-all","show-all","","","";
   }

   submenu "&Case conversion","","","" {
      "lowcase selection","lowcase-selection","","","";
      "upcase selection","upcase-selection","","","";
      "&Lowcase word","lowcase-word","","","";
      "&Upcase word","upcase-word","","","";
      "Upcase &char","upcase-char","","","";
      "Cap &selection","cap-selection", "","","";
   }
   "&Transpose chars (ctrl T)","transpose-chars","","","";
   "transpose words (C S T)","transpose-words","","","";
   "transpose lines  (alt T)","transpose-lines","","","";
   "-","","","","";
   "&Header guards","my_header_guards","","","";
}
« Last Edit: August 28, 2014, 01:42:11 pm by Graeme »