[RESOLVED] Search/Replace new line/line break in a raw code editor?
Results 1 to 11 of 11

Thread: [RESOLVED] Search/Replace new line/line break in a raw code editor?

  1. #1
    Senior Member Joseph Sliker's Avatar
    Join Date
    Dec 2002
    Location
    Milwaukee
    Posts
    409

    resolved [RESOLVED] Search/Replace new line/line break in a raw code editor?

    Hi;

    Sometimes I create some long associative arrays ie "array('k1'=>'v1','k2'=>'v2',...'kn'=>'vn')

    There are often times that I would like to do a search/replace in my editor (using Komodo lately) so that in the editor, the line will break after each comma (after each key=>value pair) to make scanning through these arrays easier.

    I usually do this by pasting the string into MS Word and doing a replace all (ie. find "," replace with ",^p") and then hitting "replace all" which works fine, but is pesky/inefficient. Is there some special character code that can be used in these code text editors (ie. Komodo, Crimson Editor, Geinie, etc.) that functions the same way as "^p" does in the example above (the invisible line break character used in such editors)?
    "The lazy man will find the best way."

  2. #2
    Senior Member traq's Avatar
    Join Date
    Jun 2011
    Location
    so.Cal
    Posts
    949
    Komodo has a find+replace function that can use regular expressions (check the box). In this case, you'd search for "," and replace with "\r\n" (or whatever your preferred line ending is).

  3. #3
    Senior Member Derokorian's Avatar
    Join Date
    Apr 2011
    Location
    Denver
    Posts
    1,774
    It also has multi-line mode on find+find/replace so you can just hit , enter in the replace box. It will use the file settings to determine if it should be Windows line ending or *nix.

    Open find with ctrl+f
    Open find/replace with ctrl+h

    6nmLCQg0ejYI3T7taMWL23myRIOIu.jpg
    Last edited by Derokorian; 02-13-2014 at 05:38 PM.
    Sadly, nobody codes for anyone on this forum. People taste your dishes and tell you what is missing, but they don't cook for you. ~anoopmail
    I'd rather be a comma, then a full stop.
    User Authentication in PHP with MySQLi - Don't forget to mark threads resolved - MySQL(i) warning

  4. #4
    Senior Member Joseph Sliker's Avatar
    Join Date
    Dec 2002
    Location
    Milwaukee
    Posts
    409
    I think I did not explain myself clearly. It's not the script result that I am after but how the text is actually laid out IN THE EDITOR WHILE I AM WORKING ON IT

    ie, I tried the above example, and in Komodo, the result was

    $skip_us=array('LIST_1',\r\n 'LIST_31',\r\n 'LIST_33',\r\n'LIST_34',\r\n'LIST_38',\r\n'LIST_96 ');

    what I want it to look like (AGAIN, IN THE EDITOR WINDOW) is like so:
    $skip_us=array('LIST_1',
    'LIST_31',
    'LIST_33',
    'LIST_34',
    'LIST_38',
    'LIST_96 ');

    Is there some special character or code that I can use in the Komodo search/replace box that will insert whatever the magical/invisible line break is that is used for that editor?
    "The lazy man will find the best way."

  5. #5
    High Energy Magic Dept. NogDog's Avatar
    Join Date
    Aug 2006
    Location
    Ankh-Morpork
    Posts
    13,915
    I think the replace portion is not an actual regex, so just make sure you click the "multiline" checkbox, then simply enter a comma followed by hitting Enter. (And with multiline checked, you can turn off regex for this situation.)
    Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be." ~ from Nation, by Terry Pratchett

    "But the main reason that any programmer learning any new language thinks the new language is SO much better than the old one is because hes a better programmer now!" ~ http://www.oreillynet.com/ruby/blog/...ck_to_p_1.html


    eBookworm.us

  6. #6
    Senior Member
    Join Date
    Jul 2007
    Posts
    3,647
    Komodo ought to support automated formatting according to code style settings, shouldn't it? In my editor I just hit cmd-alt-l and then select file or project to have it formatted as per settings.

  7. #7
    High Energy Magic Dept. NogDog's Avatar
    Join Date
    Aug 2006
    Location
    Ankh-Morpork
    Posts
    13,915
    Quote Originally Posted by johanafm View Post
    Komodo ought to support automated formatting according to code style settings, shouldn't it? In my editor I just hit cmd-alt-l and then select file or project to have it formatted as per settings.
    I think you have to buy the IDE to get that. However, I did create a macro for the free Edit version, that depends on the PEAR formatting package. If anyone is interested, I'll try to dig up my notes over the long weekend on what I had to do to get it to work.
    Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be." ~ from Nation, by Terry Pratchett

    "But the main reason that any programmer learning any new language thinks the new language is SO much better than the old one is because hes a better programmer now!" ~ http://www.oreillynet.com/ruby/blog/...ck_to_p_1.html


    eBookworm.us

  8. #8
    Senior Member Derokorian's Avatar
    Join Date
    Apr 2011
    Location
    Denver
    Posts
    1,774
    Quote Originally Posted by Joseph Sliker View Post
    I think I did not explain myself clearly.
    I think you explained yourself fine. Have you tried the solution NogDog and myself have suggested?
    Sadly, nobody codes for anyone on this forum. People taste your dishes and tell you what is missing, but they don't cook for you. ~anoopmail
    I'd rather be a comma, then a full stop.
    User Authentication in PHP with MySQLi - Don't forget to mark threads resolved - MySQL(i) warning

  9. #9
    High Energy Magic Dept. NogDog's Avatar
    Join Date
    Aug 2006
    Location
    Ankh-Morpork
    Posts
    13,915
    Quote Originally Posted by NogDog View Post
    I think you have to buy the IDE to get that. However, I did create a macro for the free Edit version, that depends on the PEAR formatting package. If anyone is interested, I'll try to dig up my notes over the long weekend on what I had to do to get it to work.
    JS script that defines the Komodo macro:
    Code:
    komodo.assertMacroVersion(3);
    if (komodo.view.scintilla) { komodo.view.scintilla.focus(); } // bug 67103
    
    var formatter;
    var language = komodo.koDoc.language;
    var cannot_tidy_selection = false;
    switch (language) {
        case 'C':
            formatter = 'astyle --style=linux';
            break;
        case 'C++':
            formatter = 'astyle --style=kr';
            break;
        case 'C#':
            formatter = 'astyle --style=ansi';
            break;
        case 'HTML':
            cannot_tidy_selection = true;
            formatter = 'tidy -q -utf8 -asxhtml -i -w 80';
            break;
        case 'Java':
            formatter = 'astyle --style=java';
            break;
        case 'Perl':
            formatter = 'perltidy';
            break;
        case 'PHP':
            formatter = 'php_beautifier.bat -t1 -l "Pear() ArrayNested() IndentStyles(style=bsd)"';
            break;
        case 'XLST':
        case 'XML':
        case 'XUL':
            cannot_tidy_selection = true;
            formatter = 'tidy -q -utf8 -xml -i -w 80';
            break;
        default:
            alert("I don't know how to tidy " + language);
            exit(1);
    }
    
    //save current cursor position
    var currentPos = komodo.editor.currentPos;
    
    try {
        // Save the file.  After the operation you can check what changes where made by
        // File -> Show Unsaved Changes
        komodo.doCommand('cmd_save');
    
        // Group operations into a single undo
        komodo.editor.beginUndoAction();
    
        // Select entire buffer & pipe it into formatter.
        //komodo.doCommand('cmd_selectAll');
        //Run_RunEncodedCommand(window, formatter + " {'insertOutput': True, 'operateOnSelection': True}");
    
        //var text_not_selected = komodo.editor.selText == "";
        var text_not_selected = cannot_tidy_selection
                         || komodo.editor.selText == "";
        if (text_not_selected) {
            komodo.doCommand('cmd_selectAll');
        }
        Run_RunEncodedCommand(window, formatter + " {'insertOutput': True, 'operateOnSelection': True}");
    
        if (text_not_selected) {
            komodo.editor.gotoPos(currentPos);
        }
    
         // Restore cursor.  It will be close to the where it started depending on how the text was modified.
         komodo.editor.gotoPos(currentPos);
    
        // On windows, when the output of a command is inserted into an edit buffer it has unix line ends.
        komodo.doCommand('cmd_cleanLineEndings');
    
    } catch (e) {
        alert(e);
    
    } finally {
        // Must end undo action or may corrupt edit buffer
        komodo.editor.endUndoAction();
    }
    The php_beautifier.bat file it calls:
    Code:
    @ECHO OFF
    SET PHP="C:\PHP\php.exe"
    SET BEAUTIFY="C:\PHP"\php_beautifier
    %PHP% -d output_buffering=1 -c "C:\PHP"\php.ini -f %BEAUTIFY% -- %1 %2 %3 %4 %5 %6 %7 %8 %9
    @ECHO ON
    Lastly, the PEAR PHP_Beautifier package needs to be installed (change the batch file to point to it).
    Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be." ~ from Nation, by Terry Pratchett

    "But the main reason that any programmer learning any new language thinks the new language is SO much better than the old one is because hes a better programmer now!" ~ http://www.oreillynet.com/ruby/blog/...ck_to_p_1.html


    eBookworm.us

  10. #10
    Senior Member Joseph Sliker's Avatar
    Join Date
    Dec 2002
    Location
    Milwaukee
    Posts
    409
    Quote Originally Posted by Derokorian View Post
    I think you explained yourself fine. Have you tried the solution NogDog and myself have suggested?
    YES! It works! (click on the regex and multiline selectors and hitting the enter key in the replace box before clicking the [replace all] button)

    Thanks. This is very helpful (as is pretty much everything else I've gotten from you folks here at PHPBuilder...I love this place!)

    (Been away from my desk since last post...sorry for delayed reply)
    "The lazy man will find the best way."

  11. #11
    Senior Member Joseph Sliker's Avatar
    Join Date
    Dec 2002
    Location
    Milwaukee
    Posts
    409
    ...actually, I was attempting to use that multi-line option incorrectly (and I did not work) I thought it was meant to search/replace multiple lines in the editor all at once, which it does not seem to do.
    "The lazy man will find the best way."

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •