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

Help with a macro

Expand Messages
  • Salman Khilji
    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
    Message 1 of 3 , Oct 8, 2004
    • 0 Attachment
      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




      __________________________________
      Do you Yahoo!?
      Yahoo! Mail - Helps protect you from nasty viruses.
      http://promotions.yahoo.com/new_mail
    • 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 2 of 3 , Oct 8, 2004
      • 0 Attachment
        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 3 of 3 , Oct 8, 2004
        • 0 Attachment
          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.