Idea collecting: What i wanna do with scripting

Started by Stefan, April 29, 2009, 04:45:58 PM

Previous topic - Next topic

Stefan

Often i had an feature request - then i think "i can do this on my own, if once scripting is supported"

So i collect here my ideas (and maybe you too?),
maybe to aid Alex to find out what is needed for scripting?
Stefan, HippoEDIT beta tester 
HippoEDIT - the editor programmers wants to code thyself when they are dreaming.        -Don't just edit. HippoEDIT!-

Stefan

#1
EDIT: already there

=>"Tools > Keyboard Settings..."
=> Edit.SmartHighlight  (current word under cursor)


I just have assign an shortcut to it  :D :top:

EDIT:  or hold CTRL-key while clicking on an word  ;D
Stefan, HippoEDIT beta tester 
HippoEDIT - the editor programmers wants to code thyself when they are dreaming.        -Don't just edit. HippoEDIT!-

Arthur

I few ideas:

1) Strip out irrelevant text (e.g. HTML, code comments, etc.);
2) Generate a new file based on an existing one;
3) Batch modify a bunch of files;
4) Capture and present certain text;
5) Perform complex searches/replacements (e.g. conditional ones, for instance when a value X is greater than Y, and so forth)

scottbilas

Use scripting to enhance syntax parsing and coloring. For example, queries from the HE editor to a custom lexer to get all the functions in the file - something not always possible with a regex. Or scripts to do small scale refactoring ("convert this property into a function getter/setter"). It doesn't have to be super complex or complete. Could start out with a few helpers to enhance the lexer in ways that regex's can't.

For the internal API, consider taking a look at VS.NET 2010. I've heard really great things about its extensibility model. Perhaps it has elements that would be easy to implement in HE. Here's a good interview on it from @shanselman: http://bit.ly/PFgG.

This would probably rule out a slow scripting language due to the performance requirements of background parsing, but perhaps you can use C# with dynamic compiling and assembly generation.

alex

Hello Scott,

I do not think, that scripting should be used in synatx highlighting. For this purpose I think best would be a compiled lexer plugin I am also planning (some early versions of HE already had support of external lexers, but now this already does not work..)

But for some refactoring tools as getters/setters generation - yes :)

Best regards,
Alex.
P.S: thanks for link ;).
HippoEDIT team
[url="http://www.hippoedit.com/"]http://www.hippoedit.com/[/url]

Stefan

#5
Often i copy some info from Internet and paste it into an editor.

This give me an result like this:

  28.
      If UCase(Mid(args(c1),3,Len(ALongSwitch))) = (UCase(ALongSwitch)) Then
  29.
      Found = True
  30.
      ASign = InStr(args(c1),"=")
  31.
       
  32.
      If ASign <> 0 Then



Here i wanna wrote an script like:

Until HE.EOF
  WS.SendKeys(END)
  WS.SendKeys(Ctrl+Shift+ArrowRight)
  WS.SendKeys(DEL)
  WS.SendKeys(TAB)
  HE.LineDown
Loop


To get:

  28.        If UCase(Mid(args(c1),3,Len(ALongSwitch))) = (UCase(ALongSwitch)) Then
  29.        Found = True
  30.        ASign = InStr(args(c1),"=")
  31.         
  32.        If ASign <> 0 Then



EDIT: i have wrote this like an script, but would work as simple keystroke recording macro too.
Start Recording
  END
  Ctrl+Shift+ArrowRight
  DEL
  TAB
  Pos1
  ArrowDown
Stop Recording
Run Macro
Run Macro multiple times: [X] till EOF
Stefan, HippoEDIT beta tester 
HippoEDIT - the editor programmers wants to code thyself when they are dreaming.        -Don't just edit. HippoEDIT!-

Stefan

Find an label and copy line and next two lines into new tab

curTab = HE.ActiveTab.FullFileName

sel = HE.ActiveTab.FullFileName & vbCRLF & vbCRLF  & "ToDo's:" & vbCRLF

For i = 1 To MaxLinesCount - CurrentLineNumber
result = Find("//ToDo")
  IF Result Then
    Goto.POS1
    Selection.Mode(Line)
    Selection.Start
    Goto.EOL(select true)
    Goto.ArrowDown
    Goto.ArrowDown
    Selection.End
    sel = sel & vbLF &  Selection.Area
  End IF
Next


HE.Tabs.New
Activate NewTab
write(sel)
HE.Tabs.Close(curTab)

.
Stefan, HippoEDIT beta tester 
HippoEDIT - the editor programmers wants to code thyself when they are dreaming.        -Don't just edit. HippoEDIT!-

Stefan

#7
I often copy tutorials or other many lines of text from the internet.
Often this are
- a few line as "header" or description - which i didn't want to break
- a few or more but very long lines - "the" text to reformat.
- a few lines below, f.ex. commants from other readers - which i didn't want to reformat


f.ex.:

Description Description Description Description
Description Description Description Description Description
Headline
Selected Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text

Comments Comments Comments Comments
Comments Comments Comments Comments Comments

-----------------



Now i need to reformat those lines. (Break each line longer then x chars at n chars and add linefeed)



1. select the part of the text to reformat.

2.
FOR EACH line IN lines
  IF line > 72 chars THEN
      GoOneLineUp
      IF line > 0 THEN //but shorter then 72
        GoOneLineDown
        GoToPos1
        Press ENTER   //add an empty line
     ELSE
        GoOneLineDown
      End IF

      While line > 55  
            break line at end-of-word after 55 chars
       Went

      GoOneLineDown
      IF line > 0 THEN   // if there is not already an empty line - add one
         GoToPos1
         Press ENTER
      End IF

  ELSE
      continue  // nothing to do
 End IF
NEXT

----------------------

Hmm, Most is covered by script language i think.
Editor only provide/write selected text.

varSelection = Editor.selection

Lines = array(varSelection, vbCRLF)
GoOneLineUp => Lines[X]-1
GoOneLineDowm => Lines[X]+1
GoToPos1+Press ENTER => Lines[X] & vbCRLF ? ? ?
and like this...

Editor.selection = varSelection
Stefan, HippoEDIT beta tester 
HippoEDIT - the editor programmers wants to code thyself when they are dreaming.        -Don't just edit. HippoEDIT!-

Stefan

I want to execute an script by an short cut which should do the following:

* execute an intern HippoEDIT command (Paste As HTML)
* insert a few line breaks \r\n
* insert an string like "<BR><BR><BR>"
* insert a few line breaks \r\n
* scroll the last line in the middle of screen
* save the document

.
Stefan, HippoEDIT beta tester 
HippoEDIT - the editor programmers wants to code thyself when they are dreaming.        -Don't just edit. HippoEDIT!-

Stefan

I want to execute an script while HippoEDIT is not visible.

For example as clip board collector.

* In HippoEDIT i set an global hotkey to execute the script from above ("Paste As HTM and format")
* Then i minimize HippoEDIT and went to my browser
* in browser i select and copy some text
* now i press the global hotkey to trigger HippoEDIT to execute the script...
... or i set HippoEDIT to use an EVENT "OnClipboardUpdate" :D

.
Stefan, HippoEDIT beta tester 
HippoEDIT - the editor programmers wants to code thyself when they are dreaming.        -Don't just edit. HippoEDIT!-

Stefan

#10
Like Ctrl+D

i want to duplicate an line or block of code
AND automatically increase all found digits by 1

Examples1:
<form name="HE" action="" method="get" enctype="text/html">
<input type="radio" name="Radio1" value="Option1" ="" />
<input type="radio" name="Radio2" value="Option2" ="" /> Duplicated and increased to 2
<input type="radio" name="Radio3" value="Option3" ="" /> Duplicated and increased to 3
</form>

Examples2:
name_1=
app_1=
arg_1=
dir_1=

Duplicated and increased:
name_2=
app_2=
arg_2=
dir_2=



---------

I want to select an block/column only and de- or increase all found digits by n

.
Stefan, HippoEDIT beta tester 
HippoEDIT - the editor programmers wants to code thyself when they are dreaming.        -Don't just edit. HippoEDIT!-

Stefan


I want be able to execute an scripting command from an %placeholder% ... or like that.


  <title>Untitled</title>
  <meta name="generator" content="HippoEDIT" />
  <meta name="author" content="%USERNAME%" />
  <meta name="keywords" content="" />
  <meta name="description" content="" />
</head>
<body>
   <DIV style=width:65%%;>
%Clipboard{PasteAsHTML2}%
%HE.executeScript"Scripts\templates\PasteAsHTML.hes"%
  %|%
  </DIV>
</body>
Stefan, HippoEDIT beta tester 
HippoEDIT - the editor programmers wants to code thyself when they are dreaming.        -Don't just edit. HippoEDIT!-

Stefan

#12
// Find lines containing 'Fixed' AND 'Buttonbar' AND copy this lines with surrounded lines to new tab


Pseudo code:
//store selection mode to set it later back to this mode
StoredSelectionMode = Current selection mode


//find first word
HE.PosLine(1)
For x = 1 to HE.LineCount
Find line containing WORD
Update arrayX with line number
Next x


//find second word and remember only lines already containing word 1
HE.PosLine(1)
For y = 1 to HE.LineCount
Find line containing AnotherWORD
If line number already in arrayX Then update arrayY with line number
Next y

// go to line containing both words, go 2 lines back, select whole line,
// go 6 lines down (to cover all related sentences), copy selection in background mode (still stay on current document)
For i = 0 to UBount(arrayY)
If i > HE.PosLine() +2 THEN
  HE.PosLine(i) -2
ELSE
  HE.PosLine(i)
End IF
enable line selection mode
HE.PosLine(i) +6   //or For n=1To6 HE.ArrowDown
Copy selection to Tab("xyz") in Background
disable selection mode
Next i

Current selection mode = StoredSelectionMode


-------- or
Copy selection to clipboard,adding
Open new tab
paste

---------or
Write selection to %tmp%\tmp.tmp
Open new tab
Load ("%tmp%\tmp.tmp")




HE.PosLine(i) = set pos absolute
HE.PosLine() = get pos
HE.ArrowDown or HE.PosLine(+)  =  set pos relative
Stefan, HippoEDIT beta tester 
HippoEDIT - the editor programmers wants to code thyself when they are dreaming.        -Don't just edit. HippoEDIT!-

Stefan

Simple, but anyway here for an testing idea:

// Check for lines without <BR> at line end - and add <BR> on those lines

- Paste as HTML
- go pos 1
For i = 1 To HE.LineCount
  currLine = HE.WholeLineContent
  tmp = currLine
  Trim(tmp)
  Lcase(tmp)
  IF Not Right(tmp,4) = "
" Then
    HE.LineDelete
    HE.LineAdd(currLine) & " <BR>"
  // or maybe smtg like HE.LineAddAppend(" <BR>")
  End IF
Next
Stefan, HippoEDIT beta tester 
HippoEDIT - the editor programmers wants to code thyself when they are dreaming.        -Don't just edit. HippoEDIT!-

Stefan

#14
Keep only one line of an hostname from an log file, and that has to be the last one in log (those one with newest time):

1) Transpose whole doc upside-down

2)
Till EOF
 For Each line
   Host = first alphanumeric chars till first coma
   If  InStr(HostArray, Host) Then
     delete line
   Else
    HostArray = HostArray & Host
   End If
 Next Line




Example Data

HostName-1, some dummy data, some dummy data, older date time 12:30
HostName-4, some dummy data, some dummy data, older date time 12:45
HostName-7, some dummy data, some dummy data
HostName-old1, some dummy data, some dummy data
HostName-1, some dummy data, some dummy data, newer date time 17:15
HostName-old9, some dummy data, some dummy data
HostName-4, some dummy data, some dummy data, newer date time 18:30
and 200 more




666
.


In the meantime i have done this need with an XYplorer script  (File manager from www.XYplorer.com):
$file = readfile("<curitem>");

   //sort lines upside-down:
  $count =1;
  $arrRev="";
  while(1)
  {
    $line = gettoken($file, $count, <crlf>);
    if ($line==""){break;}
    $arrRev = $line<crlf>$arrRev;
    incr $count;
  }
  //text $arrRev;


   //Collect only lines not already in $array:
   $file = $arrRev;
  $count =1;
  $array="";
  while(1)
  {
    $line = gettoken($file, $count, <crlf>);
    if ($line==""){break;}
    $token = regexreplace($line, "(.+?),.+", "$1");
    if (strpos($array, $token)== -1)
    {
      $array = $array$line<crlf>;
    }
    incr $count;
  }

   //Output:
  //text $array;
  writefile("<curitem>.clean.txt", $array, n);





Resulting in an new file based on the original name but added "clean.txt"
with this filtered line only (every hostname only onces):

HostName-4, some dummy data, some dummy data, newer date time 18:30
HostName-old9, some dummy data, some dummy data
HostName-1, some dummy data, some dummy data, newer date time 17:15
HostName-old1, some dummy data, some dummy data
HostName-7, some dummy data, some dummy data


Once available, i will rebuild this script with HE-script too.
Stefan, HippoEDIT beta tester 
HippoEDIT - the editor programmers wants to code thyself when they are dreaming.        -Don't just edit. HippoEDIT!-