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

Few macro questions

Expand Messages
  • Jeremy Cowgar
    Greetings. I have made a macro which inserts a line of text: arch-tag: into my source code files. I do have a few problems with
    Message 1 of 2 , Feb 17, 2004
    • 0 Attachment
      Greetings.

      I have made a macro which inserts a line of text:

      arch-tag: <output of uuidgen program>

      into my source code files. I do have a few problems with this and
      was wondering if anyone could help me out with it.

      Here is the macro for reference

      define-macro uuidgen-mac
      set-variable #l0 $buffer-bname
      1 pipe-shell-command "uuidgen"
      beginning-of-buffer
      3 forward-line
      set-mark
      end-of-line
      copy-region

      0 delete-buffer "*command*"
      0 find-buffer #l0

      beginning-of-buffer
      insert-string "/* arch-tag: "
      1 yank
      insert-string " */\n\n"
      !emacro

      (it probably does not look very pretty, but it's the first macro I
      really wrote)


      1. When I use pipe-shell-command, a new command window is opened and
      the output of the pipe-shell-command is put there. You see that I
      delete the buffer "*command* which works just fine, however, it splits
      the window. Problem: I do not know if the window was split prior to
      running this macro, so I cannot automatically make it 1 window again.
      Question: How can I return the window configuration back to the setup
      they had before? For instance, what if the top window was hi.c and the
      bottom bye.c ... at the end of this macro, both would be hi.c. Another
      example would be, what if they only had 1 window open. At the end of
      this macro, they now have 2 windows, both hi.c.

      2. This macro outputs C comments only, therefore I have to edit the
      resulting text when I am editing other files such as Lua or Makefile.
      How can I retrieve the current mode's comment scheme and utilize it?

      3. This only needs to be done upon the creation of a new file, therefore
      I would like to allow the placement of arch-tag: in the template files
      and then do a search. If it's found, then fill it in with the uuidgen
      output. I know how to do the search, filling in, etc... but how can I
      trigger my macro to be run upon creating a new file of any type?

      Thanks,

      Jeremy
    • Jon Green
      ... There is no need to split the window or run with the *command* buffer. If you do your own buffer management then it is easier. i.e. Remember the name of
      Message 2 of 2 , Feb 17, 2004
      • 0 Attachment
        Jeremy Cowgar wrote:
        > Greetings.
        >
        > I have made a macro which inserts a line of text:
        >
        > arch-tag: <output of uuidgen program>
        >
        > into my source code files. I do have a few problems with this and
        > was wondering if anyone could help me out with it.
        >
        > Here is the macro for reference
        >
        > define-macro uuidgen-mac
        > set-variable #l0 $buffer-bname
        > 1 pipe-shell-command "uuidgen"
        > beginning-of-buffer
        > 3 forward-line
        > set-mark
        > end-of-line
        > copy-region
        >
        > 0 delete-buffer "*command*"
        > 0 find-buffer #l0
        >
        > beginning-of-buffer
        > insert-string "/* arch-tag: "
        > 1 yank
        > insert-string " */\n\n"
        > !emacro
        >
        > (it probably does not look very pretty, but it's the first macro I
        > really wrote)
        >
        >
        > 1. When I use pipe-shell-command, a new command window is opened and
        > the output of the pipe-shell-command is put there. You see that I
        > delete the buffer "*command* which works just fine, however, it splits
        > the window. Problem: I do not know if the window was split prior to
        > running this macro, so I cannot automatically make it 1 window again.
        > Question: How can I return the window configuration back to the setup
        > they had before? For instance, what if the top window was hi.c and the
        > bottom bye.c ... at the end of this macro, both would be hi.c. Another
        > example would be, what if they only had 1 window open. At the end of
        > this macro, they now have 2 windows, both hi.c.
        >

        There is no need to split the window or
        run with the *command* buffer. If you do your
        own buffer management then it is easier. i.e.

        Remember the name of the current buffer.
        i.e.

        set-variable #l0 $buffer-bname

        Create a new buffer for the results
        and delte any old one.
        i.e.

        !force 0 delete-buffer "*mybuffer*"
        find-buffer "*mybuffer*"

        Control the pipe and buffer
        i.e.

        2 pipe-shell-command "command" "*mybuffer*"

        Return to the previous buffer
        i.e.

        find-buffer #l0


        > 2. This macro outputs C comments only, therefore I have to edit the
        > resulting text when I am editing other files such as Lua or Makefile.
        > How can I retrieve the current mode's comment scheme and utilize it?

        Use "$buffer-fhook" value.

        The comment is defined by:-

        $buffer-fhook.comment

        See the help page for buffer-init(2) for details
        of the comment structure and how you get the
        fields out.

        >
        > 3. This only needs to be done upon the creation of a new file, therefore
        > I would like to allow the placement of arch-tag: in the template files
        > and then do a search. If it's found, then fill it in with the uuidgen
        > output. I know how to do the search, filling in, etc... but how can I
        > trigger my macro to be run upon creating a new file of any type?
        >

        Put it in the "my-fhook-xxx" of myxxx.emf. I suggest that
        your macro determines if the arch information is not filled
        in, if it is not then run the pipe stuff.

        Jon.


        > Thanks,
        >
        > Jeremy
        >
        >
        >
        >
        > __________________________________________________________________________
        >
        > This is an unmoderated list. JASSPA is not responsible for the content of
        > any material posted to this list.
        >
        > To unsubscribe, send a mail message to
        >
        > mailto:jasspa-unsubscribe@yahoogroups.com
        >
        > or visit http://groups.yahoo.com/group/jasspa and
        > modify your account settings manually.
        >
        >
        >
        > Yahoo! Groups Links
        >
        >
        >
        >
        >
        >
      Your message has been successfully submitted and would be delivered to recipients shortly.