Menu

Insert Filename and Macro

2008-03-11
2012-11-13
  • BillBurkett

    BillBurkett - 2008-03-11

    Hi - I want to insert the filename at the beginning of each line in a file.  I wrote a marco to do this and used the TextFX Insert Current Filename.  The macro, however, only inserts the first character of the filename when executed.  I've submitted this as a bug and I am wondering if there is another way to accomplish what I want.  (My current poor workaround is to insert the filename, cut it, and then run a macro to paste the contents of the clipboard at the beginning of each line.)

     
    • Greg Bullock

      Greg Bullock - 2008-03-13

      At present, the macros do not record any commands from the TextFX or Plugins menus.

      For your purposes, recording something like the following should work:

      <Edit: Copy Current Filename to Clipboard> <Ctrl-V>

      Depending on what initial assumptions you can make, you may need to also include some cursor movement keystrokes to ensure that the insertion point is where you need it before pressing <Ctrl-V>.

      Regards.
      Greg

       
    • Nobody/Anonymous

      Perhaps using the Find/Replace dialog works for you. There are a lot of messages about this on the forums, in this case considering inserting some text at the beginning of each line.

      Find field:
      ^(.)
      Replace field:
      putthefilenamehere\1

      Using regex (check it) this will look for any line starting with any character, and replace it by putthefilenamehere followed by the character itself. \1 refers to the first () group in the find field.

      Notice that this method will NOT work for EMPTY lines.

      Using the advanced Find\Replace dialog (CTRL+R) you can also enter linebreaks in normal mode (uncheck regex).

      In the Find field:
      Press CTRL+M (or SHIFT+Enter or CTRL+Enter, they're all the same): this enters a linebreak.

      In the Replace field:
      Enter a linebreak (CTRL+M...), and put the filename on the new line.

      Replace all occurrences starting from the top (or using wrap mode).

      Notice that this method does NOT work for the FIRST line.

       
      • Nobody/Anonymous

        You could also take a look at the Simple Script Plug-In. It probably has a straightforward function to insert text at the beginning of each line.

         
        • Nobody/Anonymous

          >>BeginLine(string text): Appends text to the beginning of every line.

          Enclose text in quotes.  For example, beginline("<p>") would put an HTML paragraph tag at the beginning of every line in the document.

           
    • BillBurkett

      BillBurkett - 2008-03-14

      Thanks for your suggestions, everyone.

      Greg: your suggestion to use the "Edit: Copy Current Filename to Clipboard" command works perfectly in the macro - I hadn't seen that function before but meets my needs perfectly.  The macro does include keystrokes to ensure the cursor is positioned at the start of the line before insertion.

      I like the find/replace option, too, but didn't know how to reference a CR/LF.  Until now.

      Thanks again.

      Bill