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

MARK problem

Expand Messages
  • Christof Boeckler
    Hi all, I ran into a strange problem! Given the following macro define-macro latex-test-yank !force kill-region !if $status ; should work, but is buggy, ; if
    Message 1 of 2 , Nov 8, 2005
    • 0 Attachment
      Hi all,

      I ran into a strange problem! Given the following macro

      define-macro latex-test-yank
      !force kill-region
      !if $status
      ; should work, but is buggy,
      ; if region was marked by mouse or by shift-motion
      set-variable #l1 @y
      !else
      set-variable #l1 ""
      !endif

      ; if no region is visibly marked then
      ; nothing should be cut or inserted, right?
      insert-string "("
      insert-string #l1
      insert-string ")"
      !emacro

      Run this piece of code and look for yourself at the following constellations:
      - mark a region with C-space, all works fine
      - mark a region with Shift-Right (cursor motion), then you get the
      already reported "double the region" behaviour
      - but now something new: if nothing seems to be marked (C-g), then still
      something is cut and yanked back. Why?

      My goal was to write a macro that could either be used when having a
      region marked (then incorporate the region) but also without any marked
      stuff (then insert a new and empty construct).

      Any ideas how to do that?

      Gruß / Regards
      Christof

      --
      http://home.in.tum.de/~boeckler/ http://www.spiegel.de/zwiebelfisch
      Da sie sich für weise hielten, sind sie zu Narren geworden. Rö 1,22
    • Phillips, Steven
      ... This is because the last thing the shift region macro does is copy the region i.e. consider the shift region to be equivalent to calling copy-region. Try
      Message 2 of 2 , Nov 8, 2005
      • 0 Attachment
        >
        > Run this piece of code and look for yourself at the following
        > constellations:
        > - mark a region with C-space, all works fine
        > - mark a region with Shift-Right (cursor motion), then you get the
        > already reported "double the region" behaviour

        This is because the last thing the shift region macro does is copy the region i.e. consider the shift region to be equivalent to calling copy-region. Try doing:

        set-mark
        4 forward-line
        copy-region
        latex-test-yank

        And you get the same problem. The reason for this behaviour is because your macro calls kill-region first and a copy-region followed by a kill-region will always lead to 2 copies of the text in the yank buffer.

        You could fix this issue by tricking ME into thinking the last command was NOT a copy or kill command, i.e. try:

        define-macro latex-test-yank
        set-variable @cl void
        !force kill-region
        .
        .

        However there is another more serious issue with this macro, try selecting a large region and then calling this macro - make sure you have undo enabled!
        you will find that only the first 1024 bytes of the region remains, the rest has been removed due to the limit in the size of an ME variable which is 1024 chars - the yank buffer has no limit. A fix to this issue could be:

        define-macro latex-test-yank
        set-variable @cl void
        !force kill-region
        !if $status
        insert-string ")"
        yank
        insert-string "("
        !else
        insert-string "()"
        !endif
        !emacro

        but ...

        > - but now something new: if nothing seems to be marked (C-g), then still
        > something is cut and yanked back. Why?

        There seems to be some confusion here between the use of a set-mark region and the visible region which is understandable as this is a rather grey area, consider:

        - Once you have set a mark in a buffer that buffer will always have a mark, i.e. copy-region will always 'work' even if the region is empty, the 'mark' region does not need to be visible for the copy-region command to work which is exactly how you macro is currently working. Try calling kill-region instead of latex-test-yank and you will see the same behaviour.

        - Try searching for a string, if found the string is now shown as a visible region, try calling your macro now - it does not wrap the search string in brackets because the search function does not (and must not) set the mark position.

        The mark region and shown region are only the same immediately after a copy-region.

        You need to decide which region you want your macro to use and if its the shown region then you will need to use the show-region command, look in the standard macro release for examples of its use.

        Steve

        >
        > My goal was to write a macro that could either be used when having a
        > region marked (then incorporate the region) but also without any marked
        > stuff (then insert a new and empty construct).
        >
        > Any ideas how to do that?
        >
        > Gruß / Regards
        > Christof
        >
        > --
        > http://home.in.tum.de/~boeckler/ http://www.spiegel.de/zwiebelfisch
        > Da sie sich für weise hielten, sind sie zu Narren geworden. Rö 1,22
        >
        >
        >
        > __________________________________________________________________________
        >
        > 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.