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)?

    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).

      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

      [ATTACH=CONFIG]5039[/ATTACH]

      6nmLCQg0ejYI3T7taMWL23myRIOIu.jpg

        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?

          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.)

            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.

              johanafm;11038387 wrote:

              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.

                Joseph Sliker;11038377 wrote:

                I think I did not explain myself clearly.

                I think you explained yourself fine. Have you tried the solution NogDog and myself have suggested?

                  NogDog;11038397 wrote:

                  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:

                  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:

                  @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).

                    Derokorian;11038401 wrote:

                    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)

                      ...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.

                        Write a Reply...