Loading ...
Sorry, an error occurred while loading the content.

Go To Physical Line Script, 4 Variable and Flow Control Qs

Expand Messages
  • Veli-Pekka Tätilä
    Hi list, Is there a clip for going to a physical line on a document? NoetTab s go to line command takes account the word wrapping performed by NoteTab so there
    Message 1 of 3 , Nov 5, 2006
    • 0 Attachment
      Hi list,
      Is there a clip for going to a physical line on a document? NoetTab's go to
      line command takes account the word wrapping performed by NoteTab so there
      might be more than one-line in a doc, even if there's only one physical line
      break "\r\n". Usually this is OK but not in programming.

      Most programming languages report line numbers based on the number of
      physical line breaks encountered in the file. THe reason is that they have
      no idea how some text editor will wrap lines and if it hyphenates or forces
      wrapping on a word boundary, for example.

      So if one has a comment in the source code that wraps in NoteTab there's an
      annoying offset in the line numbers reported by NoteTab and the compiler or
      interpreter one is using.

      One work-around would be to turn off word wrapping to get the line count
      right. But that means not seeing all text at once and also there's no way to
      read the whole line, including the off-screen part, easily using a screen
      reader.

      So a clip could ask for a line number, count that many physical lines either
      by reading them in or repeatedly matching /\r\n/ and then place the cursor
      at the line encountered. Another more native approach would turn off word
      wrap, use goto line and then turn word wrap back on. WOrd wrap need not be
      touched if it is off in the first place. I can easily locate lines in Perl
      but I cannot move the NoteTab cursor, of course.

      Well, I just created a simple clip which does the job and thought I'd share
      it. Here you go:

      ^!Set %wraps%=^$IsWordWrap$
      ^!IfTrue ^%wraps% ^!SetWordWrap "off"
      ^!Menu "Search/Go to Line"
      ^!IfTrue ^%wraps% ^!SetWordWrap "on"

      I tested this and it appears to work OK.

      A couple of sort of related questions about variables:

      1. Regarding flow control, such as in the above script, if I'd like to do a
      while or for loop, is the only way some label and an if that conditionally
      jumps back to that label as in batch files? Howabout ifs that have multiple
      statements in the body, is it labels for flow control once again? That
      reminds me all too much of Fortran 77, though I only had to use it at a Uni
      course about programming.

      2. Can variables be localized to a label or block if there's such a thing?
      I'd prefer it if all of my variables were not accessible everywhere in the
      script.

      3. Why do you need the up arrow ^ to refer to a variable's value? I mean
      what good is the name, without the up arrow, unless it is some reference or
      pointer to the contents of that variable. I've learned that Unix shell
      scripts use variable names, as a string datatype, in processing data. But
      many programming languages and books state this is a bad practice. One
      should use a hashtable or some other related data type that does not depend
      on the properties of the code AKA reflection sso much.

      4. How do I create (possibly nested) records or structs? say I'd like to
      store an array of 100 persons with fields name and age for each one. A more
      text oriented example might be an array of paragraphs with the number of
      chars, lines and words in each one as well as the contents as an array of
      lines. How do you do it in clip code? I cannot find any kind of record
      datatype in the help nor a hashtable, which is what Perl folks might use for
      the same effect.

      --
      With kind regards Veli-Pekka Tätilä (vtatila@...)
      Accessibility, game music, synthesizers and programming:
      http://www.student.oulu.fi/~vtatila/
    • Alan_C
      On Sunday 05 November 2006 04:02, Veli-Pekka Tätilä wrote: ... Yes, you ve hit on what is known. It
      Message 2 of 3 , Nov 5, 2006
      • 0 Attachment
        On Sunday 05 November 2006 04:02, Veli-Pekka Tätilä wrote:
        <snip about line count and when wordwrap is on or off>
        >
        > Well, I just created a simple clip which does the job and thought I'd share
        > it. Here you go:
        >
        > ^!Set %wraps%=^$IsWordWrap$
        > ^!IfTrue ^%wraps% ^!SetWordWrap "off"
        > ^!Menu "Search/Go to Line"
        > ^!IfTrue ^%wraps% ^!SetWordWrap "on"
        >
        > I tested this and it appears to work OK.

        Yes, you've hit on what is known. It would able to be found in the archives
        of this list at Yahoo Groups. It's the only workaround or "solution" that I
        know of.

        > A couple of sort of related questions about variables:
        >
        > 1. Regarding flow control, such as in the above script, if I'd like to do a
        > while or for loop, is the only way some label and an if that conditionally
        > jumps back to that label as in batch files? Howabout ifs that have multiple
        > statements in the body, is it labels for flow control once again?

        Yes.

        ^!Goto your_label_here

        must be used. Yes it's like the .bat batch file language or like qbasic.
        It's not a "structured" language on its own (it's not like C or Perl).

        I use similar to:

        :do_while_initstuff
        ; code
        ; code
        ; next line can make it "skip" 1 line (resumes again at carry on here)
        ^!If condition_so_and_so Skip
        ^!Goto do_while_initstuff
        ; carry on here

        And another, say in the same clip:

        :do_while_interimstuff

        do_while_whatever being the pattern. the whatever is for uniqueness

        The above is patterned in a not unlike way to (the next):

        Mr. Wayne Van Weerhuitzen (spelling?) has I think it's in the files area of
        this list on the www at Yahoo Groups -- it's an article both about the topic
        of programming and structure or flow control and also as applicable to
        Notetab. I think there are templates in it too that can be used in clips.

        And, that's freely available for download by members of this list. It's
        previously been praised/highly_recomended by more than several members of
        this list. (I think someone said it also can aid someone to understand about
        structured programming language if a person needs that).

        > 2. Can variables be localized to a label or block if there's such a thing?
        > I'd prefer it if all of my variables were not accessible everywhere in the
        > script.

        No. All are global. Unless someone has contrived a workaround which I'm not
        aware if someone has done so.

        > 3. Why do you need the up arrow ^ to refer to a variable's value? I mean
        > what good is the name, without the up arrow, unless it is some reference or
        > pointer to the contents of that variable. I've learned that Unix shell
        > scripts use variable names, as a string datatype, in processing data. But
        > many programming languages and books state this is a bad practice. One
        > should use a hashtable or some other related data type that does not depend
        > on the properties of the code AKA reflection sso much.

        I don't grasp what your point is. Perhaps it's about that in Notetab it's
        (well, different, and also) very simple. Either assign to a variable or
        extract the content of a variable. But in other language (Perl for example)
        the print builtin function or command or whatever it is -- it can extracted
        for viewing the content of a scalar variable.

        > 4. How do I create (possibly nested) records or structs? say I'd like to
        > store an array of 100 persons with fields name and age for each one. A more
        > text oriented example might be an array of paragraphs with the number of
        > chars, lines and words in each one as well as the contents as an array of
        > lines. How do you do it in clip code? I cannot find any kind of record
        > datatype in the help nor a hashtable, which is what Perl folks might use
        > for the same effect.

        %variable%^^%index^^

        That's not quite on the money. (perhaps someone else has it to share?) But
        you can nest multi levels deep though I didn't ever find it an easy thing to
        do. (but I struggle with multi levels deep in Perl and Perl makes this easier
        to do than Notetab does). I tend to get lost, lose ability for myself to
        retain what it is that I'm doing. I suppose that I need to create some sort
        of a mapping system for myself to use when doing this.

        --
        Alan.
      • Sheri
        ... There is the ^!SetCursorPara command. It will go to the same place in the document regardless of wordwrap status. e.g., ^!SetCursorPara ^?{Enter Needed
        Message 3 of 3 , Nov 5, 2006
        • 0 Attachment
          --- In ntb-clips@yahoogroups.com, Veli-Pekka Tätilä <vtatila@...>
          wrote:
          >
          >
          > Hi list, Is there a clip for going to a physical line
          > on a document?

          There is the ^!SetCursorPara command.

          It will go to the same place in the document regardless of wordwrap
          status.

          e.g.,

          ^!SetCursorPara ^?{Enter Needed Paragraph Number}:1

          will go to the beginning of the "line" number requested. If wordwrap
          is off, the displayed line number is equal to the paragraph number.

          Regards,
          Sheri
        Your message has been successfully submitted and would be delivered to recipients shortly.