Mirror of CollapseOS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

163 lines
6.1KB

  1. # Editing text
  2. Collapse OS has 2 levels of text editing capabilities: command-
  3. based editing and visual editing.
  4. The command-based editor is a "traditional" Forth text editor as
  5. described in Starting Forth by Leo Brodie. We call this editor
  6. the "Block editor" and it is located at B100.
  7. The visual editor is a full-blown application that takes over
  8. the interpreter loop with its own key interpreter and takes over
  9. the whole screen using AT-XY. We call this editor the "Visual
  10. Editor" and is located at B120.
  11. When available, the Visual editor is almost always preferable to
  12. the Block editor. It's much more usable. We have the Block edi-
  13. tor around because not all machines can implement AT-XY. For ex-
  14. ample, a machine with only a serial console can't.
  15. # Block editor
  16. The Block editor augments the built-in word LIST with words to
  17. modify the block currently being loaded. Block saving happens
  18. automatically: Whenever you load a new block, the old block, if
  19. changed, is saved to disk first. You can force that with FLUSH.
  20. Editing works around 3 core concepts: cursor, insert buffer
  21. (IBUF), find buffer (FBUF).
  22. The cursor is simply the character index in the 64x16 grid. The
  23. word T allows you to select a line. For example, "3 T" selects
  24. the 3rd line. It then prints the selected line with a "^" char-
  25. acter to show your position on it. After a T, that "^" will
  26. always be at the beginning of the line.
  27. You can insert text at the current position with "i". For exam-
  28. ple, "i foo" inserts "foo" at cursor. Text to the right of it
  29. is shifted right. Any content above 64 chars is lost.
  30. Why "i" and not "I"? Because "I" is already used and we don't
  31. want to overshadow it.
  32. You can "put" a new line with "P". "P foo" will insert a new
  33. line under the cursor and place "foo" on it. The last line of
  34. the block is lost. "U" does the same thing, but on the line
  35. above the cursor.
  36. Inserting anything also copies the inserted content into IBUF.
  37. Whenever an inserting command is used with no content (you still
  38. have to type the whitespace after the word though), what is in-
  39. serted is the content of IBUF.
  40. This is all well and good, but a bit more granularity would be
  41. nice, right? What if you want to insert at a specific position
  42. in the line? Enter FBUF.
  43. "F foo" finds the next occurrence of "foo" in the block and
  44. places the cursor in front of it. It then spits the current line
  45. in the same way "T" does.
  46. It's with this command that you achieve granularity. This allows
  47. you to insert at arbitrary places in the block. You can also
  48. delete contents with this, using "E". "E" deletes the last found
  49. contents. So, after you've done "F foo" and found "foo", running
  50. "E" will delete "foo", shifting the rest of the line left.
  51. List of commands:
  52. T ( n -- ): select line n for editing.
  53. P xxx: put typed IBUF on selected line.
  54. U xxx: insert typed IBUF on selected line.
  55. F xxx: find typed FBUF in block, starting from current
  56. position+1. If not found, don't move.
  57. i xxx: insert typed IBUF at cursor.
  58. Y: Copy n characters after cursor into IBUF, n being length of
  59. FBUF.
  60. X ( n -- ): Delete X chars after cursor and place in IBUF.
  61. E: Run X with n = length of FBUF.
  62. # Visual editor
  63. This editor, unlike the Block Editor, is grid-based instead of
  64. being command-based. It requires the Grid subsystem (B401).
  65. It is loaded with "125 LOAD" and invoked with "VE". Note that
  66. this also fully loads the Block Editor.
  67. This editor uses 19 lines. The top line is the status line and
  68. it's followed by 2 lines showing the contents of IBUF and
  69. FBUF. There are then 16 contents lines. The contents shown is
  70. that of the currently selected block.
  71. The status line displays the active block number, then the
  72. "modifier" and then the cursor position. When the block is dir-
  73. ty, an "*" is displayed next. At the right corner, a mode letter
  74. can appear. 'R' for replace, 'I' for insert, 'F' for find.
  75. All keystrokes are directly interpreted by VE and have the
  76. effect described below.
  77. Pressing a 0-9 digit accumulates that digit into what is named
  78. the "modifier". That modifier affects the behavior of many
  79. keystrokes described below. The modifier starts at zero, but
  80. most commands interpret a zero as a 1 so that they can have an
  81. effect.
  82. 'G' selects the block specified by the modifier as the current
  83. block. Any change made to the previously selected block is
  84. saved beforehand.
  85. '[' and ']' advances the selected block by "modifier". 't' opens
  86. the previously opened block.
  87. 'h' and 'l' move the cursor by "modifier" characters. 'j' and
  88. 'k', by lines. 'g' moves to "modifier" line.
  89. 'H' goes to the beginning of the line, 'L' to the end.
  90. 'w' moves forward by "modifier" words. 'b' moves backward.
  91. 'W' moves to end-of-word. 'B', backwards.
  92. 'I', 'F', 'Y', 'X' and 'E' invoke the corresponding command from
  93. command-based editor.
  94. 'o' inserts a blank line after the cursor. 'O', before.
  95. 'D' deletes "modifier" lines at the cursor. The first of those
  96. lines is copied to IBUF.
  97. 'f' puts the contents of your previous cursor movement into
  98. FBUF. If that movement was a forward movement, it brings the
  99. cursor back where it was. This allows for an efficient combi-
  100. nation of movements and 'E'. For example, if you want to delete
  101. the next word, you type 'w', then 'f', then check your FBUF to
  102. be sure, then press 'E'.
  103. 'R' goes into replace mode at current cursor position.
  104. Following keystrokes replace current character and advance
  105. cursor. Press return to return to normal mode.
  106. '@' re-reads current block even if it's dirty, thus undoing
  107. recent changes.
  108. # Tight screens
  109. Blocks being 64 characters wide, using the Visual editor on a
  110. screen that is not 64 characters wide is a bit less convenient,
  111. but very possible.
  112. When VE is in a "tight screen" situation, it behaves different-
  113. ly: no gutter, no line number. It displays as much of the "left"
  114. part of the block as it can, but truncate every line.
  115. The right part is still accessible, however. If the cursor moves
  116. to a part of the block that is invisible, VE will "slide" right
  117. so that the cursor is shown. It will indicate it "slid" mode by
  118. adding a ">" next to the cursor address in the status bar.
  119. To slide back left, simply move the cursor to the invisible part
  120. of the left half of the block.
  121. Other than that, VE works the same.