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

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

Expand Messages
  • Steven Phillips
    Jul 20, 2009
    • 0 Attachment
      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


    • Show all 4 messages in this topic