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

2387Re: [jasspa] find-buffer docsbugs? and copy-filename function encl

Expand Messages
  • Steven Phillips
    Jul 21, 2009
    • 0 Attachment
      Yes we really should create a new release, there is so much good stuff in the latest version - sessions work properly and there's a new macro based find and grep command which is so incredibly useful and that's not to over shadow the new file-tools which mean I hardly use explorer any more.

      @y does set the yank buffer, makes what you are trying to do trivial (although use with care because as it is set via a variable its length is limited to 1024 bytes). Without this feature I suggest you do something like the following:

          set-position "\x82"
          !force 0 delete-buffer "*copy-filename*"
          find-buffer "*copy-filename*"
          ....
          delete-buffer "*copy-filename*"
          goto-position "\x82"

      Steve

      Tom Hundt wrote:
       

      Oh, yeah, I've had problems with the buffers before, just as you describe... mind you I haven't extensively tested that bit of code, just came up with it this afternoon.  Will try some more, tomorrow.  (Yeah, set-position, I've used that before, too...)


      Does @y copy things to the clipboard??
      Mine complains, "Cannot set variable @y".  
      Guess it's time to upgrade.  I've been waiting for an official release ;-)

      Thanks!

      -Tom



      On Mon, Jul 20, 2009 at 6:40 PM, Steven Phillips <bill@jasspa. com> wrote:


      Tom,

      Playing with temp buffers is always tricky to get right, the typical worst case is if the current buffer (before to run your macro) is displayed in more than one window, in which case simply deleting the temp buffer  (or hiding it) wont work properly as the replacement buffer chosen will not be the original buffer as its already displayed (this then tends to break other macros which use your macro and strange things start to happen). Best to avoid temp buffers if you can and the version below does and should work in your version:

      define-macro copy-filename
          set-variable @y $buffer-fname
      !emacro

      For backward compatibility reasons an arg of -1 to find-buffer is converted to 0x8 and an arg of <-1 (e.g. -8 or -9) is converted to 0x18 this was done when additions like bit 0x04 were made, bit 0x10 forces the hiding of all instances of the given buffer , so:

           0x18 find-buffer "*copy-filename*"

      Really should work (in my version, yours may not have bit 0x10) but hunter through the macros I can't find a single use (probably because of the double window problem mentioned above) so I would stick to the non-temp buffer approach or start researching set-position!

      Steve


      Tom Hundt wrote:
       
      Hi,

      I wanted to write a function to copy the path and filename of the currently-open file.  (In termcap or console mode, I could copy at least the visible part of the filename to the clipboard by selecting the text in the modeline.  But, I couldn't figure out how to do it in the GUI version.)

      I came up with this hack (below), which works.  (BTW I'm using ME 2006/09/09. )

      ;----------- --------- --------- --------- --------- --------- ----
      ; copy-filename: copy file name to clipboard
      ; (copies entire path + filename)
      ;----------- --------- --------- --------- --------- --------- ----
      define-macro copy-filename
          set-variable #l0 $buffer-fname
          1 find-buffer "*copy-filename*"
          set-mark
          insert-string #l0
          end-of-line
          kill-region  ; copies to clipboard
          delete-buffer "*copy-filename*"
      !emacro


      In writing this, I had some trouble with find-buffer.
      I wanted the switch to the buffer and the paste/kill actions not to be seen by the user.
      A "hidden" buffer sounded like just the ticket.
      The manpage says if the param to find-buffer is negative, the buffer is "hidden". 
      And then it also says if bit 0x8 is set, the buffer is hidden.
      So there might be a docsbug here.
      Also, when I tried both of these things (individually and together) they caused my code not to work. Values -1, -8, -9 caused errors outright, and 9 caused it not to switch buffers.

      And it turns out the buffer switch isn't visible after all, so leaving it as "1" seems to be okay.

      Thanks

      -Th


      --
      Thomas Hundt <tom@...> +1-415-867-6698







      --
      Thomas Hundt <tom@...> +1-415-867-6698


    • Show all 4 messages in this topic