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

RE: [jasspa] Macro Problem

Expand Messages
  • Phillips, Steven
    Gadrin, The macro will not terminate because any text insertion on the very last line will lead to another line being inserted so forward-line never fails. The
    Message 1 of 3 , Jan 23, 2006
    • 0 Attachment
      Gadrin,

      The macro will not terminate because any text insertion on the very last
      line will lead to another line being inserted so forward-line never
      fails. The best way of seeing this is to add the following line to the
      top of your macro:

      set-variable $debug 1

      This will enable the macro debugger and everything will become clear as
      you following the progress of the macro.

      The solution is simple, there are several safe ways to detect the end of
      the buffer (such as $window-eline) but my prefered is to simply check if
      the current char is a '\0' (only true when on the last line) i.e.:

      insert-string "/>"
      forward-line
      !until &seq @wc ""
      !emacro

      The !return is not required at the end of the macro as this will
      automatically happen. Anyway I guest the key thing to remember is the
      use of $debug, which makes understanding the cause of this type of issue
      trivial,

      Steve

      > -----Original Message-----
      > From: jasspa@yahoogroups.com [mailto:jasspa@yahoogroups.com]
      > On Behalf Of Gadrin
      > Sent: Sunday, January 22, 2006 9:50 PM
      > To: jasspa@yahoogroups.com
      > Subject: [jasspa] Macro Problem
      >
      > I haven't used MicroEMACS for a few months, but I tried to
      > write a macro today and it's throwing me for a loop.
      >
      > I have a buffer:
      >
      > "Anniston"
      > "Birmingham"
      > "Decatur"
      > "Dothan"
      > "Florence"
      > "Gadsden"
      > "Huntsville"
      > "Mobile"
      > "Montgomery"
      > "Tucaloosa"
      > "Columbus (Ala. portion)"
      > "Rural"
      >
      > and I wrote this macro:
      >
      > define-macro fs
      > beginning-of-buffer
      > set-variable %sn @ml "Enter State #"
      > !repeat
      > beginning-of-line
      > insert-string &sprintf "<city state=\"%d\" name=" %sn
      > end-of-line
      > insert-string "/>"
      > !force forward-line
      > !until ¬ $status
      > !return
      > !emacro
      >
      >
      > however it's running past the end of the buffer every time:
      >
      > <city state="1" name="Anniston"/>
      > <city state="1" name="Birmingham"/>
      > <city state="1" name="Decatur"/>
      > <city state="1" name="Dothan"/>
      > <city state="1" name="Florence"/>
      > <city state="1" name="Gadsden" />
      > <city state="1" name="Huntsville"/>
      > <city state="1" name="Mobile"/>
      > <city state="1" name="Montgomery"/>
      > <city state="1" name="Tucaloosa"/>
      > <city state="1" name="Columbus (Ala. portion)"/> <city
      > state="1" name="Rural"/> <city state="1" name=/> <city
      > state="1" name=/> <city state="1" name=/> <city state="1"
      > name=/> <city state="1" name=/> <city state="1" name=/> <city
      > state="1" name=/> <city state="1" name=/> <city state="1"
      > name=/> <city state="1" name=/> <city state="1" name=/> <city
      > state="1" name=/> <city state="1" name=/> <city state="1"
      > name=/> <city state="1" name=/> <city state="1" name=/> <city
      > state="1" name=/> <city state="1" name=/> <city state="1" name=/>
      >
      > I tried the forward-line on the last line in the buffer and
      > got the BELL, so I know there's no "phantom lines" hanging around.
      >
      > The !repeat/!until is cut & paste from the HTML manual.
      >
      >
      >
      >
      >
      >
      > ______________________________________________________________
      > ____________
      >
      > 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
      >
      >
      >
      >
      >
      >
    • Gadrin
      ... last ... ah, I never knew about this particular behavior. it seems counter-intuitive, but I appreciate your help.
      Message 2 of 3 , Jan 23, 2006
      • 0 Attachment
        --- In jasspa@yahoogroups.com, "Phillips, Steven" <sphillips@p...>
        wrote:
        >
        > Gadrin,
        >
        > The macro will not terminate because any text insertion on the very
        last
        > line will lead to another line being inserted so forward-line never
        > fails.

        ah, I never knew about this particular behavior.

        it seems counter-intuitive, but I appreciate your help.
      Your message has been successfully submitted and would be delivered to recipients shortly.