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

Align Character's macro

Expand Messages
  • Jeremy Cowgar
    Attached below is my align-character macro. It s function is: int rad = 10; int speed = 20; int drag = 3; Set the mark at int rad, move to int drag, Esc-x,
    Message 1 of 5 , Nov 29, 2006
    • 0 Attachment
      Attached below is my align-character macro. It's function is:

      int rad = 10;
      int speed = 20;
      int drag = 3;

      Set the mark at int rad, move to int drag, Esc-x, align-character,
      it'll prompt for a character, enter =... The result will be:

      int rad = 10;
      int speed = 20;
      int drag = 3;

      It aligned the = signs.

      Now, the macro has a few flaws:

      #1 If the character you want to align starts on the 1 column, it'll
      be over looked.
      #2 If you move too far down, say after int drag, and there is no =
      sign, it'll abort with a end of buffer error.
      #3 If you have:

      int rad = 10;
      int speed = 20;
      int drag = 3;

      and align, it'll align to the furthest = sign, so the result would be:

      int rad = 10;
      int speed = 20;
      int drag = 3;

      If anyone has any fixes for those items or can make the macro better
      in any way, I'd appriciate it! Oh! One more thing, I'd like to be
      able to wrap it in other macros and call it with a parameter but am
      unsure how to do that yet. i.e.

      define-macro align-equals
      align-character "="
      !emacro

      Jeremy Cowgar

      =====================================================

      define-macro align-character
      set-variable .align-char @ml "Align character"

      !if &great $window-line $window-mark-line
      exchange-point-and-mark
      !endif

      set-variable .start-line $window-line
      set-variable .to-line $window-mark-line
      set-variable .max 1

      !while &or &less $window-line .to-line &equal $window-line .to-line
      beginning-of-line

      !repeat
      forward-char
      !until &sequal @wc .align-char

      !if &great $window-col .max
      set-variable .max $window-col
      !endif

      forward-line
      !done

      goto-line .start-line

      !while &or &less $window-line .to-line &equal $window-line .to-line
      beginning-of-line

      !repeat
      forward-char
      !until &sequal @wc .align-char

      !if &less $window-col .max
      !repeat
      insert-string " "
      !until &equal $window-col .max
      !endif

      forward-line
      !done

      goto-line .start-line

      ml-write "Aligned!"
      !emacro

      =====================================================
    • Bryan Schofield
      You can pass arguments just as described: define-macro align-equals align-character = !emacro The following snippet changes the first portion of you macro to
      Message 2 of 5 , Nov 30, 2006
      • 0 Attachment
        You can pass arguments just as described:

        define-macro align-equals
           align-character "="
        !emacro


        The following snippet changes the first portion of you macro to look for an argument passed in, if not found, then prompt the user.

        define-macro align-character
            !force set-variable .align-char @1
            !if &not $status
                s set-variable .align-char @ml "Align character"
            !endif
            ...



        On 11/29/06, Jeremy Cowgar < jeremy@...> wrote:

        Attached below is my align-character macro. It's function is:

        int rad = 10;
        int speed = 20;
        int drag = 3;

        Set the mark at int rad, move to int drag, Esc-x, align-character,
        it'll prompt for a character, enter =... The result will be:

        int rad = 10;
        int speed = 20;
        int drag = 3;

        It aligned the = signs.

        Now, the macro has a few flaws:

        #1 If the character you want to align starts on the 1 column, it'll
        be over looked.
        #2 If you move too far down, say after int drag, and there is no =
        sign, it'll abort with a end of buffer error.
        #3 If you have:

        int rad = 10;
        int speed = 20;
        int drag = 3;

        and align, it'll align to the furthest = sign, so the result would be:

        int rad = 10;
        int speed = 20;
        int drag = 3;

        If anyone has any fixes for those items or can make the macro better
        in any way, I'd appriciate it! Oh! One more thing, I'd like to be
        able to wrap it in other macros and call it with a parameter but am
        unsure how to do that yet. i.e.

        define-macro align-equals
        align-character "="
        !emacro

        Jeremy Cowgar

        =====================================================

        define-macro align-character
        set-variable .align-char @ml "Align character"

        !if &great $window-line $window-mark-line
        exchange-point-and-mark
        !endif

        set-variable .start-line $window-line
        set-variable .to-line $window-mark-line
        set-variable .max 1

        !while &or &less $window-line .to-line &equal $window-line .to-line
        beginning-of-line

        !repeat
        forward-char
        !until &sequal @wc .align-char

        !if &great $window-col .max
        set-variable .max $window-col
        !endif

        forward-line
        !done

        goto-line .start-line

        !while &or &less $window-line .to-line &equal $window-line .to-line
        beginning-of-line

        !repeat
        forward-char
        !until &sequal @wc .align-char

        !if &less $window-col .max
        !repeat
        insert-string " "
        !until &equal $window-col .max
        !endif

        forward-line
        !done

        goto-line .start-line

        ml-write "Aligned!"
        !emacro

        ,___

      • Bryan Schofield
        oops, I see I have an extra s on one line... doh.
        Message 3 of 5 , Nov 30, 2006
        • 0 Attachment
          oops, I see I have an extra "s" on one line... doh.

          On 11/30/06, Bryan Schofield <schofield.bryan@...> wrote:
          > You can pass arguments just as described:
          >
          > define-macro align-equals
          > align-character "="
          > !emacro
          >
          >
          > The following snippet changes the first portion of you macro to look for an
          > argument passed in, if not found, then prompt the user.
          >
          > define-macro align-character
          > !force set-variable .align-char @1
          > !if ¬ $status
          > s set-variable .align-char @ml "Align character"
          > !endif
          > ...
          >
          >
          >
          >
          > On 11/29/06, Jeremy Cowgar < jeremy@...> wrote:
          > >
          > >
          > >
          > >
          > >
          > >
          > >
          > > Attached below is my align-character macro. It's function is:
          > >
          > > int rad = 10;
          > > int speed = 20;
          > > int drag = 3;
          > >
          > > Set the mark at int rad, move to int drag, Esc-x, align-character,
          > > it'll prompt for a character, enter =... The result will be:
          > >
          > > int rad = 10;
          > > int speed = 20;
          > > int drag = 3;
          > >
          > > It aligned the = signs.
          > >
          > > Now, the macro has a few flaws:
          > >
          > > #1 If the character you want to align starts on the 1 column, it'll
          > > be over looked.
          > > #2 If you move too far down, say after int drag, and there is no =
          > > sign, it'll abort with a end of buffer error.
          > > #3 If you have:
          > >
          > > int rad = 10;
          > > int speed = 20;
          > > int drag = 3;
          > >
          > > and align, it'll align to the furthest = sign, so the result would be:
          > >
          > > int rad = 10;
          > > int speed = 20;
          > > int drag = 3;
          > >
          > > If anyone has any fixes for those items or can make the macro better
          > > in any way, I'd appriciate it! Oh! One more thing, I'd like to be
          > > able to wrap it in other macros and call it with a parameter but am
          > > unsure how to do that yet. i.e.
          > >
          > > define-macro align-equals
          > > align-character "="
          > > !emacro
          > >
          > > Jeremy Cowgar
          > >
          > > =====================================================
          > >
          > > define-macro align-character
          > > set-variable .align-char @ml "Align character"
          > >
          > > !if &great $window-line $window-mark-line
          > > exchange-point-and-mark
          > > !endif
          > >
          > > set-variable .start-line $window-line
          > > set-variable .to-line $window-mark-line
          > > set-variable .max 1
          > >
          > > !while &or &less $window-line .to-line &equal $window-line .to-line
          > > beginning-of-line
          > >
          > > !repeat
          > > forward-char
          > > !until &sequal @wc .align-char
          > >
          > > !if &great $window-col .max
          > > set-variable .max $window-col
          > > !endif
          > >
          > > forward-line
          > > !done
          > >
          > > goto-line .start-line
          > >
          > > !while &or &less $window-line .to-line &equal $window-line .to-line
          > > beginning-of-line
          > >
          > > !repeat
          > > forward-char
          > > !until &sequal @wc .align-char
          > >
          > > !if &less $window-col .max
          > > !repeat
          > > insert-string " "
          > > !until &equal $window-col .max
          > > !endif
          > >
          > > forward-line
          > > !done
          > >
          > > goto-line .start-line
          > >
          > > ml-write "Aligned!"
          > > !emacro
          > > ,___
          >
          >
        • Jon Green
          ... Attached is a cleaned up version which handles regions properly. Not had time to wrap it up for macro calling yet. Note called align-char rather than
          Message 4 of 5 , Dec 1, 2006
          • 0 Attachment
            > If anyone has any fixes for those items or can make the macro better
            > in any way, I'd appriciate it! Oh! One more thing, I'd like to be
            > able to wrap it in other macros and call it with a parameter but am
            > unsure how to do that yet. i.e.

            Attached is a cleaned up version which handles regions properly.
            Not had time to wrap it up for macro calling yet.

            Note called "align-char" rather than "align-character" in keeping with
            the other "-char" commands. Also if you add multiple characters as the
            alignment then any of the characters are aligned vertically.

            Jon.
          • Jon Green
            ... Here http://www.jasspa.com/development/align.emf is a cleaned up version which handles regions properly. Not had time to wrap it up for macro calling yet.
            Message 5 of 5 , Dec 1, 2006
            • 0 Attachment
              Jeremy Cowgar wrote:
              > Attached below is my align-character macro. It's function is:
              >
              > int rad = 10;
              > int speed = 20;
              > int drag = 3;
              >
              > Set the mark at int rad, move to int drag, Esc-x, align-character,
              > it'll prompt for a character, enter =... The result will be:
              >
              > int rad = 10;
              > int speed = 20;
              > int drag = 3;
              >
              > It aligned the = signs.
              >
              > Now, the macro has a few flaws:
              >
              > #1 If the character you want to align starts on the 1 column, it'll
              > be over looked.
              > #2 If you move too far down, say after int drag, and there is no =
              > sign, it'll abort with a end of buffer error.
              > #3 If you have:
              >
              > int rad = 10;
              > int speed = 20;
              > int drag = 3;
              >
              > and align, it'll align to the furthest = sign, so the result would be:
              >
              > int rad = 10;
              > int speed = 20;
              > int drag = 3;
              >
              > If anyone has any fixes for those items or can make the macro better
              > in any way, I'd appriciate it! Oh! One more thing, I'd like to be
              > able to wrap it in other macros and call it with a parameter but am
              > unsure how to do that yet. i.e.
              >

              Here

              http://www.jasspa.com/development/align.emf

              is a cleaned up version which handles regions properly.
              Not had time to wrap it up for macro calling yet.

              Note called "align-char" rather than "align-character" in keeping with
              the other "-char" commands. Also if you add multiple characters as the
              alignment then any of the characters are aligned vertically.

              Jon.

              > define-macro align-equals
              > align-character "="
              > !emacro
              >
              > Jeremy Cowgar
            Your message has been successfully submitted and would be delivered to recipients shortly.