Loading ...
Sorry, an error occurred while loading the content.
 

Re: [jasspa] Help with a macro

Expand Messages
  • Jon Green
    ... A couple of mistakes, I think you want this:- define-macro function_separator set-variable %index &sin . $buffer-bname !if &equal %index 0 set-variable
    Message 1 of 3 , Oct 8, 2004
      Salman Khilji wrote:
      > I am trying to write a macro that does the following:
      >
      > Given the name of a buffer such as GraphView.cpp,
      > strip it off the extension and insert in the buffer
      > the following string at the current position:
      >
      > GraphView::
      >
      > So I search in the buffer name of a '.' character.
      > The problem is that the &sin function always returns
      > 0.
      >
      > Here it is
      >
      > define-macro function_separator
      > set-variable %index &sin $buffer-bname "."
      > !if &equal %index 0
      > set-variable %classname $buffer-bname
      > !else
      > set-variable %classname &lef $buffer-bname
      > %index
      > !endif
      > insert-string %classname
      > insert-string "::"
      > !emacro
      >

      A couple of mistakes, I think you want this:-

      define-macro function_separator
      set-variable %index &sin "." $buffer-bname
      !if &equal %index 0
      set-variable %classname $buffer-bname
      !else
      set-variable %classname &lef $buffer-bname &sub %index 1
      !endif
      insert-string %classname
      insert-string "::"
      !emacro

      Rather than use %index and %classname which are variables
      (slow and expensive) better to use the macro register
      variables. So would re-write as follows:-

      define-macro function_separator
      ; #l0 The index into the string.
      ; #l1 The class name.
      set-variable #l0 &sin "." $buffer-bname
      !if &equ #l0 0
      set-variable #l1 $buffer-bname
      !else
      set-variable #l1 &lef $buffer-bname &sub #l0 1
      !endif
      insert-string #l1
      insert-string "::"
      !emacro

      Jon.
    • Thomas Hundt
      It s &sin not the other way around! ... -- Thomas Hundt
      Message 2 of 3 , Oct 8, 2004
        It's

        &sin <string you're looking for> <string you're searching>

        not the other way around!



        Salman Khilji wrote:

        > I am trying to write a macro that does the following:
        >
        > Given the name of a buffer such as GraphView.cpp,
        > strip it off the extension and insert in the buffer
        > the following string at the current position:
        >
        > GraphView::
        >
        > So I search in the buffer name of a '.' character.
        > The problem is that the &sin function always returns
        > 0.
        >
        > Here it is
        >
        > define-macro function_separator
        > set-variable %index &sin $buffer-bname "."
        > !if &equal %index 0
        > set-variable %classname $buffer-bname
        > !else
        > set-variable %classname &lef $buffer-bname
        > %index
        > !endif
        > insert-string %classname
        > insert-string "::"
        > !emacro


        --
        Thomas Hundt
      Your message has been successfully submitted and would be delivered to recipients shortly.