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

11439Re: [Clip] Re: Delete thousands of lines

Expand Messages
  • Sheri
    Jan 2, 2004
      Hi Chuck,

      Here's another attempt.

      It only works on the current email message. The next email message is identified by locating the first line after the cursor that starts with the word "From".

      It deletes all attachment sections following the starting cursor position until it reaches an attachment section that has no tabfilename= line within its first few lines. It preserves the prefix text (assumed to be email text) and suffix text (everything following the first section with no attachment file name). From your example it appears that the message ends with one of those boundary lines. That last boundary line is treated as part of the suffix text and is not removed. I thought perhaps it could cause problems with your email program if it was missing.

      Its very fast. I altered your test file to put over 15000 lines in each attachment. I discovered that most of the typical manners of deleting or pasting or inserting over these large blocks worked very slowly when done with clip instructions. I don't know why these were so slow since (for example) doing similar tasks manually were not delayed. Fortunately I discovered that using ^!InsertSelect ^$GetFileText(filename.txt)$ to replace thousands of selected lines didn't have this problem. Otherwise, I would be suggesting a Perl solution (were you aware that NoteTab clips can run Perl?)

      It doesn't really work as you said you wanted it to. You're not prompted for a search string.

      Instead, you should save any attachments in the current message that you want to keep. Then position the cursor within the text message (i.e., below its "------=_NextPart_" line) and run the clip. The line count and file name associated with each deleted section is preserved.

      If this works well, you could make a new clip with a clip wizard that helps you locate proper starting points and then automatically runs this clip with a ^!Clip command.

      To copy this clip without broken lines, copy/paste from somewhere around this page:



      H="Delete attachments"
      ^!SetWordWrap Off
      ^!Continue Cursor position should be in or below email text (above attachments). If necessary Cancel and reposition the cursor.
      ^!SetHintInfo Working ...
      ^!SetScreenUpdate Off
      ^!DeleteFile "^$GetLibraryPath$delatt.txt"
      ^!Set %curdoc%=^$GetDocIndex$
      ^!Set %beginpos%=^$GetRow$:^$GetCol$
      ;Operate only within this message - next starts with "From" in col 1
      ;Or if no next message, operate to end of file
      ^!Find "^From" RS
      ^!IfError Next Else Skip_1
      ^!Jump Doc_End
      ^!Jump -1
      ^!SelectTo ^%beginpos%
      ;Copy from starting point to end of message to temporary buffer
      ^!SetClipboard ^$GetSelection$
      ^!Menu Edit/Paste New
      ^!SetClipboard ""
      ^!Select All
      ^!SetArray %attachnames%=
      ^!Set %Index%=0
      ^!Jump Doc_Start
      ^!Inc %Index%
      ^!Find "------=_NextPart_" TIS
      ^!IfError Out
      ^!Set %startpos%="^$GetRow$:1"
      ;Don't delete from 1st section of message (s/b text)
      ^!If ^%Index%=1 Next Else Skip_3
      ^!SelectTo 1:1
      ^!AppendToFile "^$GetLibraryPath$delatt.txt" ^$GetSelection$
      ^!SetCursor ^%startpos%
      ^!Find "^P^P" IS
      ^!SelectTo ^%startpos%
      ;Parse filename
      ^!Find "^P^Tfilename="" THS
      ;If attachment has no filename, preserve all remaining attachments in file
      ^!IfError Last
      ^!Jump Select_End
      ;Parse filename
      ^!Find "[^"]*" RS
      ^!Set %attachnames^%Index%%="^$GetSelection$"
      ^!SetCursor ^%startpos%
      ^!Jump +1
      ^!Find "------=_NextPart_" IS
      ^!IfError Last
      ^!Jump Select_Start
      ^!SelectTo ^%startpos%
      ^!Set %count%=^$StrCount("^%NL%";"^$GetSelection$";No;No)$
      ^!AppendToFile "^$GetLibraryPath$delatt.txt" *** "^%attachnames^%Index%%"(^%count% LINES DELETED)^%NL%
      ^!Jump Select_End
      ^!Goto Loop
      ;leave last boundary in place
      ^!If ^%Index%=1 Error
      ^!Jump Doc_End
      ^!SelectTo ^%startpos%
      ^!AppendToFile "^$GetLibraryPath$delatt.txt" ^%NL%^$GetSelection$
      ^!Close Discard
      ^!SetDocIndex ^%curdoc%
      ^!IfFileExist "^$GetLibraryPath$delatt.txt" Next Else Error
      ^!InsertSelect ^$GetFileText("^$GetLibraryPath$delatt.txt")$
      ^!SetView ^$GetRowStart$:1
      ^!Goto ClearVars
      ^!Close Discard
      ^!SetDocIndex ^%curdoc%
      ^!SetCursor ^%beginpos%
      ^!Info Error - Cursor was not within message text or 1st boundary had no filename in expected format.
      ^!Clearvariable %attachnames%
      ^!Clearvariable %count%
      ^!Clearvariable %index%
      ^!Clearvariable %startpos%
      ^!Clearvariable %beginpos%
      ^!Clearvariable %curdoc%
    • Show all 6 messages in this topic