Getting the number and jump to a line

Getting the number and jump to a line

9

    May 08, 2007#1

    Hi
    I am trying to write a script that captures a number and a file name written in a line, then opens this file and jumps to the line with the captured number.
    I have tried a few things but I am a dummy with respect to Java. Could anyone help me out?

    Thanks

    6,604548
    Grand MasterGrand Master
    6,604548

      May 08, 2007#2

      And what exactly is your problem? To get the number and file name from the line of the current file? Or to open the file? Or to jump to the line?

      Have you searched or simply looked on the existing threads in the Script forum? Honestly!

      What about forum topics Get current line and col from Script and Selecting text? They are not exactly what you want, but they should help you to find the solution.
      Best regards from an UC/UE/UES for Windows user from Austria

      9

        May 08, 2007#3

        Yep, I looked at them, but that didn't solve my problem. Here is the code for getting the number and using it to go to the line. But this is not working:

        var rexCodeTypes = "[0-9]";
        var rexCodeTypesF = "[/]";


        UltraEdit.activeDocument.findReplace.regExp = true;
        UltraEdit.activeDocument.findReplace.find(rexCodeTypes);

        var intLine = UltraEdit.activeDocument.selectWord;
        UltraEdit.open('filexyz');
        UltraEdit.activeDocument.gotoLine(intLine,5);

        6,604548
        Grand MasterGrand Master
        6,604548

          May 08, 2007#4

          First specify always the regular expression engine before using a regular expression find/replace. See UE Regular Expressions Problem why this is important. Well, your very simple regular expression search string will work for all search engines.

          Second, function selectWord selects the current word, but does not return anything as far as I know. You have to use

          var intLine = UltraEdit.activeDocument.selection;

          Well, I have not really written a script, only a few lines for testing. I just have read whole help page about the script commands and created the tag list group for "UE/UES Script Commands" based on the help and some tests for some commands, but not all commands.

          By the way: If you use [0-9]+ you will find always the whole line number and don't need to use selectWord before using selection (I guess, not tested).
          Best regards from an UC/UE/UES for Windows user from Austria

          9

            May 08, 2007#5

            The problem is that UE doesn't seem to accept
            UltraEdit.activeDocument.gotoLine(intLine,5);

            this works, but this is not what I want:
            UltraEdit.activeDocument.gotoLine(10,5);

            Greetings from Switzerland

            344
            MasterMaster
            344

              May 08, 2007#6

              Hi dude,

              Well, there is something to learn here. Try this text file as your ONLY open file (file 0):
              213 123 test 12
              213 123 test 12
              213 123 test 12
              213 123 test 12
              213 123 test 12
              213 123 test 12
              213 123 test 12
              213 123 test 12
              213 123 test 12
              213 123 test 12
              Now let run this macro:

              Code: Select all

              var l = 5;
              UltraEdit.activeDocument.top();
              UltraEdit.activeDocument.findReplace.regExp = true;
              UltraEdit.activeDocument.findReplace.find("t");  //it will match in 1st line
              
              var intLine = UltraEdit.activeDocument.selectWord;
              UltraEdit.activeDocument.gotoLine(l,0);  //Will go to line 5, same column. OK !
              UltraEdit.document[0].write("Line " + String(intLine));
              ups.
              There is a line like this:
              213 123 Line function selectWord() {    [native code]}Line 12
              intline seems to hold something different, something like "YES, true, the function is available (also posted somewhere else here Sam ??? and Mofi above. ))

              Now correct the macro and use selectWord()
              You will now get a true. The function is there. OK. But no place to jump to !!! ;-)

              Now write

              Code: Select all

              selectABCnotThere()
              You'll get an "undefined".

              So, better jump to correct integer-values. See also for "getCol" to get the current column-position, here in this forum. I hope this helped quite well.

              viewtopic.php?f=52&t=4430

              Gruezi, Bego
              Normally using all newest english version incl. each hotfix. Win 10 64 bit

              21
              Basic UserBasic User
              21

                May 09, 2007#7

                The Problem is, that UltraEdit.activeDocument.selection returns a string, but you need an integer for UltraEdit.activeDocument.gotoLine.

                use the following code to get intLine

                Code: Select all

                var line = UltraEdit.activeDocument.selection;
                var intLine = parseInt( line );
                

                9

                  May 09, 2007#8

                  Thanks! That was where I was looking for!

                    May 09, 2007#9

                    One last question: now I can jump to a line, but now I want to open the name of a file I copied:

                    I have the following line in my listing-file

                    **** error on line 28 in file c:\models\kli.gms

                    I want to copy the line number (which functions now with the help of all of you) and then open the file mentioned in this line.

                    I tried, but this exceeds my humble knowledge of java scripting.

                    All help is greatly aprreciated.

                    Greetings from the Swiss mountains

                    262
                    MasterMaster
                    262

                      May 09, 2007#10

                      How about this:

                      Code: Select all

                      UltraEdit.ueReOn(); /* Let's use UE's own regexp syntax */
                      UltraEdit.activeDocument.findReplace.regExp = true;
                      UltraEdit.activeDocument.top();
                      
                      var regexpFind = "error on line [0-9]+ in file *$";
                      
                      if(UltraEdit.activeDocument.findReplace.find(regexpFind)) {
                      	var lineandfile = UltraEdit.activeDocument.selection;
                      	
                      	var words = lineandfile.split(" ");
                      	var lineno = parseInt(words[3]); // points to lineno in array
                      	
                      	var path = lineandfile.substr(lineandfile.indexOf("in file ")+8);
                      
                      	UltraEdit.open(path);
                      	UltraEdit.activeDocument.gotoLine(lineno,0);	
                      }