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

RE: [jasspa] Easy way to get exact position in buffer? (Motivation: get region size?)

Expand Messages
  • Steven Phillips
    How about: define-macro my-copy-region copy-region !if &seq @y -1 yank ml-write Dooh! !endif !emacro The only issue that may arise from this is if it
    Message 1 of 4 , Dec 5, 2001
      How about:

      define-macro my-copy-region
      copy-region
      !if &seq @y ""
      -1 yank
      ml-write "Dooh!"
      !endif
      !emacro

      The only issue that may arise from this is if it happens to be the very
      first copy-region the yank-buffer may be empty and so it may still crash but
      how likely is that??

      Steve

      P.S. The show-region is visible but not fixed when you first set the mark
      (set-mark), so when you move the cursor the region shown changes with it.
      Once you use copy-region the region is 'fixed' and thats what 0x2 of the
      region flag is telling you, clear as mud.
      > -----Original Message-----
      > From: thundt [mailto:thundt@...]
      > Sent: 05 December 2001 21:34
      > To: jasspa@yahoogroups.com
      > Subject: [jasspa] Easy way to get exact position in buffer? (Motivation:
      > get region size?)
      >
      >
      > What's an easy way to get the cursor's exact position (char #) within
      > a buffer?
      >
      > The hard and messy way is to use buffer-info and then parse the
      > $result string to pull out the char number:
      >
      > Line 1845/3955 Col 0.0 Char 78267/167172 (46%) Win Line 99/48 Col/0/0
      > char = 0xA
      > here----^^^^^
      >
      > Or, how about an easy way to get the region's size?
      > This is not reliable: (not even sure what it does -- 0x02 tells if
      > the region is "fixed" -- what does that mean?)
      > 0 show-region
      > !if ¬ &band $result 0x02
      > ml-write "[No region selected]"
      > !bell
      > !else
      > [...]
      >
      >
      > What I'm trying to do is write a safety wrapper around copy-region
      > (and kill-region) to prevent them from copying empty regions (which
      > crashes the Exceed X server application when it's set to auto-paste
      > the clipboard -- yes, I believe it's a bug -- this is v6.2).
      >
      > Something along the lines of:
      >
      > define-macro my-copy-region
      > set $x <get current location>
      > exchange-point-and-mark
      > set $y <get other location>
      > !if &equal $x $y
      > <complain and abort>
      > !else
      > copy-region
      > !end
      >
      > Thanks for any ideas,
      >
      > -Tom Hundt
      >
      >
      >
      >
      > __________________________________________________________________________
      >
      > 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.
      >
      >
      >
      >
      > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
      >
      >
      >
    • thundt@slack.net
      Ahh yes, problem with this is as SOON as the copy-region is done, its contents (or lack thereof) are stuck in the clipboard, and Exceed sees that and crashes,
      Message 2 of 4 , Dec 5, 2001
        Ahh yes, problem with this is as SOON as the copy-region is done,
        its contents (or lack thereof) are stuck in the clipboard, and
        Exceed sees that and crashes, stupid thing. I would like to check
        it BEFORE the copy-region is done.

        Thanks for the explanation of fixed region.

        -Tom

        | How about:
        |
        | define-macro my-copy-region
        | copy-region
        | !if &seq @y ""
        | -1 yank
        | ml-write "Dooh!"
        | !endif
        | !emacro
        |
        | The only issue that may arise from this is if it happens to be the very
        | first copy-region the yank-buffer may be empty and so it may still crash but
        | how likely is that??
        |
        | Steve
        |
        | P.S. The show-region is visible but not fixed when you first set the mark
        | (set-mark), so when you move the cursor the region shown changes with it.
        | Once you use copy-region the region is 'fixed' and thats what 0x2 of the
        | region flag is telling you, clear as mud.
        | > -----Original Message-----
        | > From: thundt [mailto:thundt@...]
        | > Sent: 05 December 2001 21:34
        | > To: jasspa@yahoogroups.com
        | > Subject: [jasspa] Easy way to get exact position in buffer? (Motivation:
        | > get region size?)
        | >
        | >
        | > What's an easy way to get the cursor's exact position (char #) within
        | > a buffer?
        | >
        | > The hard and messy way is to use buffer-info and then parse the
        | > $result string to pull out the char number:
        | >
        | > Line 1845/3955 Col 0.0 Char 78267/167172 (46%) Win Line 99/48 Col/0/0
        | > char = 0xA
        | > here----^^^^^
        | >
        | > Or, how about an easy way to get the region's size?
        | > This is not reliable: (not even sure what it does -- 0x02 tells if
        | > the region is "fixed" -- what does that mean?)
        | > 0 show-region
        | > !if ¬ &band $result 0x02
        | > ml-write "[No region selected]"
        | > !bell
        | > !else
        | > [...]
        | >
        | >
        | > What I'm trying to do is write a safety wrapper around copy-region
        | > (and kill-region) to prevent them from copying empty regions (which
        | > crashes the Exceed X server application when it's set to auto-paste
        | > the clipboard -- yes, I believe it's a bug -- this is v6.2).
        | >
        | > Something along the lines of:
        | >
        | > define-macro my-copy-region
        | > set $x <get current location>
        | > exchange-point-and-mark
        | > set $y <get other location>
        | > !if &equal $x $y
        | > <complain and abort>
        | > !else
        | > copy-region
        | > !end
        | >
        | > Thanks for any ideas,
        | >
        | > -Tom Hundt
        |
        __________
        Thomas Hundt <thundt@...> +1-415-643-3595
      • thundt@slack.net
        Steven! Awesome. Works great. (BTW for some reason the mouse selection works correctly , i.e., won t copy an empty selection. ... And let me add: DOH!! Forgot
        Message 3 of 4 , Dec 6, 2001
          Steven! Awesome. Works great. (BTW for some reason the mouse
          selection works "correctly", i.e., won't copy an empty selection.
          :-)

          And let me add: DOH!! Forgot $window-line and $window-col. For
          some reason I was mentally stuck on the concept "character number
          within buffer" (like file position).

          Thank you very much!

          -Tom


          | Tom,
          |
          | Sorry for the slower response, I'd nearly got this working and ME blew up!
          | (Don't use $debug when you have a macro bound to pick-idle - fixed now). The
          | version below should do what you want,
          |
          | Steve
          |
          |
          | define-macro my-copy-region
          | set-position "\x81"
          | exchange-point-and-mark
          | set-variable #l0 $window-line
          | set-variable #l1 $window-col
          | exchange-point-and-mark
          | goto-position "\x81"
          | !if &or &sub #l0 $window-line &sub #l1 $window-col
          | copy-region
          | !else
          | ml-write "Dooh 2!"
          | !endif
          | !emacro
          |
          | > Subject: Re: [jasspa] Easy way to get exact position in buffer? (Motivation: get region size?)
          | > From: thundt@...
          | > Date: Wed, 5 Dec 2001 16:09:39 -0500 (EST)
          | > To: jasspa@yahoogroups.com
          | >
          | > Ahh yes, problem with this is as SOON as the copy-region is done,
          | > its contents (or lack thereof) are stuck in the clipboard, and
          | > Exceed sees that and crashes, stupid thing. I would like to check
          | > it BEFORE the copy-region is done.
          | >
          | > Thanks for the explanation of fixed region.
          | >
          | > -Tom
          | >
          | > | How about:
          | > |
          | > | define-macro my-copy-region
          | > | copy-region
          | > | !if &seq @y ""
          | > | -1 yank
          | > | ml-write "Dooh!"
          | > | !endif
          | > | !emacro
          | > |
          | > | The only issue that may arise from this is if it happens to be the very
          | > | first copy-region the yank-buffer may be empty and so it may still crash but
          | > | how likely is that??
          | > |
          | > | Steve
          | > |
          | > | P.S. The show-region is visible but not fixed when you first set the mark
          | > | (set-mark), so when you move the cursor the region shown changes with it.
          | > | Once you use copy-region the region is 'fixed' and thats what 0x2 of the
          | > | region flag is telling you, clear as mud.
          | > | > -----Original Message-----
          | > | > From: thundt [mailto:thundt@...]
          | > | > Sent: 05 December 2001 21:34
          | > | > To: jasspa@yahoogroups.com
          | > | > Subject: [jasspa] Easy way to get exact position in buffer? (Motivation:
          | > | > get region size?)
          | > | >
          | > | >
          | > | > What's an easy way to get the cursor's exact position (char #) within
          | > | > a buffer?
          | > | >
          | > | > The hard and messy way is to use buffer-info and then parse the
          | > | > $result string to pull out the char number:
          | > | >
          | > | > Line 1845/3955 Col 0.0 Char 78267/167172 (46%) Win Line 99/48 Col/0/0
          | > | > char = 0xA
          | > | > here----^^^^^
          | > | >
          | > | > Or, how about an easy way to get the region's size?
          | > | > This is not reliable: (not even sure what it does -- 0x02 tells if
          | > | > the region is "fixed" -- what does that mean?)
          | > | > 0 show-region
          | > | > !if ¬ &band $result 0x02
          | > | > ml-write "[No region selected]"
          | > | > !bell
          | > | > !else
          | > | > [...]
          | > | >
          | > | >
          | > | > What I'm trying to do is write a safety wrapper around copy-region
          | > | > (and kill-region) to prevent them from copying empty regions (which
          | > | > crashes the Exceed X server application when it's set to auto-paste
          | > | > the clipboard -- yes, I believe it's a bug -- this is v6.2).
          | > | >
          | > | > Something along the lines of:
          | > | >
          | > | > define-macro my-copy-region
          | > | > set $x <get current location>
          | > | > exchange-point-and-mark
          | > | > set $y <get other location>
          | > | > !if &equal $x $y
          | > | > <complain and abort>
          | > | > !else
          | > | > copy-region
          | > | > !end
          | > | >
          | > | > Thanks for any ideas,
          | > | >
          | > | > -Tom Hundt

          __________
          Thomas Hundt <thundt@...> +1-415-643-3595
        Your message has been successfully submitted and would be delivered to recipients shortly.