Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #10341
    Stefan
    Participant

    I collect here a few macros i have played with.
    I have them as Snippets always at hand.

    //Remove empty lines (incl. whitespace) – in Selection
    document.selection.Replace(“^s*n”,””,eeFindNext | eeReplaceSelOnly | eeReplaceAll | eeFindReplaceRegExp);

    //Remove really empty lines only – in Selection
    document.selection.Replace(“^n”,””,eeFindNext | eeReplaceAll | eeReplaceSelOnly | eeFindReplaceRegExp);

    //Reduce many empty lines to one – in Selection
    document.selection.Replace(“^s*$”,””,eeFindNext | eeReplaceAll | eeReplaceSelOnly | eeFindReplaceRegExp);
    document.selection.Replace(“(nn)n+”,”$1″,eeFindNext | eeReplaceAll | eeReplaceSelOnly | eeFindReplaceRegExp);

    //Reduce many blanks to one – in Selection
    document.selection.Replace(” s+”,” “,eeFindNext | eeFindReplaceEscSeq | eeReplaceSelOnly | eeReplaceAll | eeFindReplaceRegExp);
    //document.selection.Replace(” {2,}”,” “,eeFindNext | eeReplaceAll | eeFindReplaceRegExp);

    //Remove every blanks – in Selection
    document.selection.Replace(“s+”,””,eeFindNext | eeReplaceSelOnly | eeReplaceAll | eeFindReplaceRegExp);

    //Remove leading blanks – in Selection
    //document.selection.Replace(“^s+(.+)$”,”$1″,eeFindNext | eeReplaceAll | eeReplaceSelOnly | eeFindReplaceRegExp);
    document.selection.Replace(“^s+”,””,eeFindNext | eeReplaceAll | eeReplaceSelOnly | eeFindReplaceRegExp);

    //Remove trailing blanks – in Selection
    document.selection.Replace(“^(.+?)s+$”,”$1″,eeFindNext | eeReplaceAll | eeReplaceSelOnly | eeFindReplaceRegExp);

    //Remove first sign from selected lines
    redraw = false;
    document.selection.Replace(“^.”,””, eeReplaceSelOnly | eeReplaceAll | eeFindReplaceRegExp);
    document.HighlightFind = false;

    //Remove first non-blank sign from selected lines
    document.selection.Replace(“^(s*).(.+)$”,”$1$2″, eeReplaceSelOnly | eeReplaceAll | eeFindReplaceRegExp);

    //Remove last sign from selected lines
    document.selection.Replace(“.$”,””, eeReplaceSelOnly | eeReplaceAll | eeFindReplaceRegExp);

    //Insert in front of selected lines
    Leader = prompt(“What to insert in front?”,”// “);
    document.selection.Replace(“^”,Leader, eeReplaceSelOnly | eeReplaceAll | eeFindReplaceRegExp);

    //Insert to the end of selected lines
    Trailer = prompt(“What to insert to the end?”,” //”);
    document.selection.Replace(“$”,Trailer, eeReplaceSelOnly | eeReplaceAll | eeFindReplaceRegExp);

    //Enclose selected word
    mySign = prompt( “Enter sign to enclose selection:”, “\%” );
    selText = document.selection.Text;
    document.selection.Text = mySign + selText + mySign;

    #10343
    Stefan
    Participant

    The same (and more) as pop-up menu:

    For example you can just press “Ctrl+Alt+M” + a
    to “Remove empty lines (incl. whitespace) – in Selection”

    As explained here
    http://www.emeditor.com/modules/newbb/viewtopic.php?viewmode=flat&topic_id=1879&forum=19

    you can create your own menu in EmEditor, here e.g. an pop-up menu.

    To create your own pop-up menu follow this steps:
    1. Copy the below code into EmEditor and Save as e.g. myMenu.jsee
    2. Execute menu “Macros > Select This” to add this macro to My Macros
    3. Assign an keyboard shortcut to launch this pop-up menu
    // Tools > Properties for all configurations > [Keyboard]
    // Category: My Macros
    // Commands: myMenu.jsee
    // Press new shortcut key: e.g. Ctrl+Alt+M
    // [Assign]
    // [OK]

    Now do:
    – open an test file
    – make an selection or press Ctrl+A
    – e.g. press “Ctrl+Alt+M a” to “Remove empty lines (incl. whitespace) – in Selection”

    Here is the macro code:




    //EmEditor TextApe :-)
    //v0.01, 14. Mai 2012, Stefan, First tests
    //v0.02, 15. Mai 2012, Stefan, First public beta release
    //v0.03, 22. Mai 2012, Stefan, Wording: Blanks>Whitespace, some optimizations

    //Found at:
    //http://www.emeditor.com/modules/newbb/viewtopic.php?topic_id=2033&forum=19&post_id=6625#forumpost6625


    //Initial work:
    init();

    //Build the menu:
    TextApe=CreatePopupMenu();
    TextApe.Add("&A Remove empty lines (incl. whitespace)",1);
    TextApe.Add("&B Remove empty lines",2);
    TextApe.Add("&C Reduce many empty lines to one (incl. ws)",3);
    TextApe.Add( "", 0, eeMenuSeparator );
    TextApe.Add("&D Reduce many whitespace to one",31);
    TextApe.Add("&E Remove every whitespace",32);
    TextApe.Add("&F Remove leading whitespace",33);
    TextApe.Add("&G Remove trailing whitespace",34);
    TextApe.Add("&H Remove lead+trail whitespace",35);
    TextApe.Add("&i Remove first sign (any)",36);
    TextApe.Add("&J Remove first sign (non-blank)",37);
    TextApe.Add("&K Remove any of this signs in front...",38);
    TextApe.Add("&L Remove last sign (any)",39);
    TextApe.Add( "", 0, eeMenuSeparator );
    TextApe.Add("&M Insert in front...",61);
    TextApe.Add("&N Insert in front... of first sign",62);
    TextApe.Add("&O Insert to the end...",63);
    TextApe.Add("&P Enclose selection...",64);
    TextApe.Add("&Q Enclose each line...",65);
    TextApe.Add( "", 0, eeMenuSeparator );
    TextApe.Add("About",1000);

    //Get which item was clicked:
    var vClickedItem = TextApe.Track();

    //Execute the related code block:
    switch(vClickedItem)
    {
    case 1:
    //Remove empty lines (incl. whitespace) - in Selection
    document.selection.Replace("^s*n","",eeFindNext | eeReplaceSelOnly | eeReplaceAll | eeFindReplaceRegExp);
    break;
    case 2:
    //Remove really empty lines only - in Selection
    document.selection.Replace("^n","",eeFindNext | eeReplaceAll | eeReplaceSelOnly | eeFindReplaceRegExp);
    break;
    case 3:
    //Reduce many empty lines to one (incl. ws) - in Selection
    document.selection.Replace("^s+$","",eeFindNext | eeReplaceAll | eeReplaceSelOnly | eeFindReplaceRegExp);
    document.selection.Replace("n{2,}","nn",eeFindNext | eeReplaceAll | eeReplaceSelOnly | eeFindReplaceRegExp);
    break;
    case 31:
    //Reduce many whitespace to one - in Selection
    document.selection.Replace("s{2,}"," ",eeFindNext | eeFindReplaceEscSeq | eeReplaceSelOnly | eeReplaceAll | eeFindReplaceRegExp);
    break;
    case 32:
    //Remove every whitespace - in Selection
    document.selection.Replace("s+","",eeFindNext | eeReplaceSelOnly | eeReplaceAll | eeFindReplaceRegExp);
    end();
    break;
    case 33:
    //Remove leading whitespace - in Selection
    document.selection.Replace("^s+","",eeFindNext | eeReplaceAll | eeReplaceSelOnly | eeFindReplaceRegExp);
    break;
    case 34:
    //Remove trailing whitespace - in Selection
    document.selection.Replace("s+$","",eeFindNext | eeReplaceAll | eeReplaceSelOnly | eeFindReplaceRegExp);
    break;
    case 35:
    //Remove leading + trailing whitespace - in Selection
    document.selection.Replace("^s*(.+?)s*$","$1",eeFindNext | eeReplaceAll | eeReplaceSelOnly | eeFindReplaceRegExp);
    break;
    case 36:
    //Remove first sign from selected lines
    document.selection.Replace("^.","", eeReplaceSelOnly | eeReplaceAll | eeFindReplaceRegExp);
    end();
    break;
    case 37:
    //Remove first non-blank sign from selected lines
    document.selection.Replace("^(s*).(.+)$","$1$2", eeReplaceSelOnly | eeReplaceAll | eeFindReplaceRegExp);
    break;
    case 38:
    //Remove any of this signs in front of line - in Selection
    RemoveAnyOfThisSigns();
    break;
    case 39:
    //Remove last sign from selected lines
    document.selection.Replace(".$","", eeReplaceSelOnly | eeReplaceAll | eeFindReplaceRegExp);
    break;
    case 61:
    //Insert in front of selected lines
    Leader = prompt("What to insert in front?","// ");
    document.selection.Replace("^",Leader, eeReplaceSelOnly | eeReplaceAll | eeFindReplaceRegExp);
    break;
    case 62:
    //Insert in front of first non-empty - in selected lines
    Leader = prompt("What to insert in front?","// ");
    document.selection.Replace("^(s*)(.)","$1"+Leader+"$2", eeReplaceSelOnly | eeReplaceAll | eeFindReplaceRegExp);
    break;
    case 63:
    //Insert to the end of selected lines
    Trailer = prompt("What to insert to the end?"," //");
    document.selection.Replace("$",Trailer, eeReplaceSelOnly | eeReplaceAll | eeFindReplaceRegExp);
    break;
    case 64:
    //Enclose selected word
    mySign = prompt( "Enter sign to enclose selection:", "\%" );
    selText = document.selection.Text;
    document.selection.Text = mySign + selText + mySign;
    break;
    case 65:
    //Enclose each selected line
    mySign = prompt( "Enter sign to enclose selection:", "\%" );
    document.selection.Replace("^(.*)$",mySign+"$1"+mySign, eeReplaceSelOnly | eeReplaceAll | eeFindReplaceRegExp);
    break;
    case 1000:
    alert("EmEditor TextApe :-)nv0.03, 22. Mai 2012nnJust some nifty macros.nEnjoy!nnStefan");
    break;
    default:
    break;
    }

    //Some bigger or maybe common used function:
    function init(){
    if(document.selection.IsEmpty){
    alert("This macros works with an selection only.n
    Please make an selection first, then call this menu again.");
    quit();}
    redraw = false;
    }
    function RemoveAnyOfThisSigns(){
    Signs = prompt("What to delete in front?",">-*,+");
    if (Signs.indexOf("-") > -1){
    Signs = Signs.replace("-",""); Signs = Signs + "-";}
    for (i=1;i<10;i++){
    document.selection.Replace("^(s*)[+Signs+]+","$1",eeFindNext
    | eeReplaceAll | eeReplaceSelOnly | eeFindReplaceRegExp);
    }
    }
    function end(){document.HighlightFind = false;}
    //<EOF>

    #10353
    user
    Participant

    congrats for the excellent topic, that should be sticky

    as for: //Remove empty lines (incl. whitespace)
    wouldnt it be better to have h, instead of s?

    #10458
    Stefan
    Participant

    Thanks user. Sorry, I missed this reply somehow.

    I just want to share an idea i had for 30 minutes.
    Customizing the menu to add your own menu items.

    * Tools > Customize Menus…
    * choose here e.g. ‘Main Menu’
    * click at the last item: ‘&Help’
    * click at [Insert Below]
    >> (o)Popup, Name: ‘MyMenu’
    >> [OK]
    * click at the last item: ‘MyMenu’
    * click at [Insert Right]
    >> (o)Command
    >> Category: My Macros
    >> Commands: TextApe.jsee
    >> [OK]
    > [OK]

    You should have an new main menu entry ‘MyMenu’ now after ‘Help’:

    #10459
    user
    Participant

    thanks!

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.