home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume4 / vms-vi-2 / part04 < prev    next >
Encoding:
Internet Message Format  |  1989-02-03  |  25.7 KB

  1. Path: xanth!mcnc!gatech!bloom-beacon!bu-cs!mirror!necntc!ncoast!allbery
  2. From: gregg@a.cs.okstate.edu (Gregg Wonderly)
  3. Newsgroups: comp.sources.misc
  4. Subject: v04i095: TPUVI for VMS part 4 of 17
  5. Message-ID: <8809212057.AA07819@uunet.UU.NET>
  6. Date: 26 Sep 88 01:49:13 GMT
  7. Sender: allbery@ncoast.UUCP
  8. Reply-To: gregg@a.cs.okstate.edu (Gregg Wonderly)
  9. Lines: 701
  10. Approved: allbery@ncoast.UUCP
  11.  
  12. Posting-number: Volume 4, Issue 95
  13. Submitted-by: "Gregg Wonderly" <gregg@a.cs.okstate.edu>
  14. Archive-name: vms-vi-2/Part04
  15.  
  16. $ show default
  17. $ if f$search("DOC.DIR;1") .eqs. "" then -
  18.      CREATE/LOG/DIRECTORY [.DOC]
  19. $ write sys$output "Creating [.DOC]TUTOR.RNO"
  20. $ create [.DOC]TUTOR.RNO
  21. $ DECK/DOLLARS="*$*$*EOD*$*$*"
  22. .! TUTOR.RNO - Learning to use VI
  23. .! Written by Gregg Wonderly 12-NOV-1987
  24. .!
  25. .! RUNOFF operation instructions:
  26. .!
  27. .!     $ @VIDOC.COM TUTOR
  28. .!
  29. .!   to create a document for printing.
  30. .!   
  31. .! We set the layout so that running page numbers are on the bottom
  32. .!
  33. .lo 1,2
  34. .st
  35. .!
  36. .! Initial right margin - sections should never set it higher than this.
  37. .! Set page size too.
  38. .ps 57,70 .rm 65
  39. .!
  40. .! Header level setup
  41. .sthl 6,0,0,8,9,1,1,9,2
  42. .dhl D,D,lu,d,ll,ll
  43. .!
  44. .!
  45. .flags bold
  46. .flags overstrike
  47. .!
  48. .c;                                             
  49. .sk 2
  50. .c;Learning to use VI written in TPU
  51. .title Learning to use VI written in TPU
  52. .sk 2
  53. .c;Gregg Wonderly
  54. .c;Mathematics Department
  55. .c;Oklahoma State University
  56. .sk 1
  57. .c;12-NOV-1987
  58. .!
  59. .send toc .ifnot global
  60. .hl 1 ^*Introduction\*
  61. .X introduction
  62. .send toc .endif global
  63. .s
  64. Editing text consists of only a few basic operations.  These operations can be
  65. summarized by generalizations to be just insertions and deletions.  Most text
  66. editors provide text insertion capabilities by allowing the user to just type.
  67. .X deletion
  68. .X insertion
  69. Text deletions are then accomplished by the use of certain non-typing keystrokes
  70. which are not allowed to insert text into the document being edited. These types
  71. of editors are typically called modeless editors, because they apparently have
  72. no special mode to distinguish between inserting and deleting text (just
  73. different keystrokes). 
  74. .s
  75. VI is not one of these types of editors.  VI is a moded editor, as it has
  76. a specific mode for inserting text, and another mode (which makes use of
  77. the normal typing keys) which allows deleting text.  Like anything different,
  78. it can take some time to get used to this type of editing.  There are some
  79. real benefits to be gained from it.  Some are quite significant, an others
  80. while perhaps not terribly important, are deeply rooted in the progression
  81. of computers and terminals.
  82. .PAGE
  83. .REQ 'TUTOR.RNT'
  84. .PAGE
  85. .P
  86. There has never really been a standard terminal with a standard layout of
  87. keys (other than the QWERTY keyboard).  This presents a real problem when
  88. you have several different types of terminals that you use.  VI attempts
  89. to solve the problem of dealing with different keyboards by making it
  90. unnecessary to use anything but the QWERTY keyboard.
  91. .s
  92. This is advantageous when a particular site has different types of terminals.
  93. This was the case at the University of California at Berkeley when Bill Joy
  94. first wrote VI.  Bill was presented with the task of writing a full screen
  95. editor that would be usable on all of the terminals that had been given to the
  96. Computer Science folks there.  Out of this came two things, VI, and more
  97. importantly, curses which allows terminal independent access to windowing
  98. capabilities.  Quite an accomplishment Bill!
  99. .s
  100. Now that there is apparently a move towards standardizing the DEC VT-200 series
  101. keyboards, and the ANSI 3.64 escape sequences, the idea of not using anything
  102. but the QWERTY keyboard may diminish.  But, there will always be the argument
  103. that the QWERTY keyboard is closer to your finger tips than the keypad is.
  104. .!
  105. .send toc .ifnot global
  106. .hl 1 ^*Learning the power of VI\*
  107. .send toc .endif global
  108. .s
  109. With that out of the way, lets move on to learning VI.  There are two modes of
  110. operation that the VI editor can be in.  It is either in command mode, or in
  111. insert mode.  When you first enter the editor, it is in command mode. One of the
  112. .X escape
  113. very first things to learn about VI is, when you are not sure, bang on the
  114. escape key a few times until you hear a beep.  The escape key is used to change
  115. modes from text insert mode to editing command mode, so banging on it a few
  116. times will always get you to command mode, when you are in insert mode. 
  117. .s
  118. VI allows you to perform many tasks with very few keystrokes.  This is good for
  119. those who get tired of typing lots of keystrokes to perform editing operations.
  120. This can be bad for those who make lots of typing mistakes. I say "can be bad"
  121. .X undo
  122. because VI allows you to recover from typing mistakes by undoing operations that
  123. insert/delete text into/from a document.  Operations that alter a document are
  124. explicit in VI.  There is a definite starting point, and a definite ending
  125. point.  This is what allows VI to "know" how to undo what you last did. As long
  126. as you only make one mistake at a time, you can undo that mistake by typing a
  127. 'u' (for undo) keystroke while in command mode.  This is perhaps the most
  128. appreciated feature of VI.  There is another key stroke, 'U', which also allows
  129. you to undo mistakes.  It will undo all changes made to the current line,
  130. providing the cursor has not left that line since the changes were made.
  131. .!
  132. .send toc .ifnot global
  133. .hl 2 ^*Inserting Text\*
  134. .send toc .endif global
  135. .s
  136. VI incorporates several methods of inserting text into a document.
  137. There are three different methods you can use while you are in command mode.
  138. Typing an 'i' (for insert) keystroke allows you to insert characters
  139. into the document at the point that the cursor is positioned.  As
  140. mentioned above, typing the <ESC> (or escape) keystroke allows you to
  141. exit (or escape) from insert mode.  Due to the many different places
  142. that a person may want to insert text at, there are keystrokes other
  143. than 'i', that place the editor directly into insert mode, after
  144. moving the cursor.  These are outlined below. 
  145. .s
  146. ^&Insert commands\&
  147. .lm+5
  148. .LT
  149. 'i'         Allows you to insert at the current cursor
  150.             position.
  151. .EL
  152. .S
  153. .LT
  154. 'I'         Allows you to begin inserting at the beginning
  155.             of the line, no matter where the cursor is
  156.             positioned on the current line.
  157.  
  158. .EL
  159. .lm-5
  160. ^&Open commands\&
  161. .lm+5
  162. .LT
  163. 'o'         Allows you to begin inserting on a new, empty
  164.             line that is opened for you, below the current
  165.             line.
  166. .EL
  167. .S
  168. .LT
  169. 'O'         Allows you to begin inserting on a new, empty
  170.             line that is opened for you, above the current
  171.             line.
  172.  
  173. .EL
  174. .lm-5
  175. ^&Append commands\&
  176. .lm+5
  177. .LT
  178. 'a'         Allows you to begin inserting after the
  179.             character (append) that the cursor is
  180.             positioned on.
  181. .EL
  182. .S
  183. .LT
  184. 'A'         Allows you to begin inserting at the end of the
  185.             current line, no matter where the cursor is
  186.             positioned on that line.
  187. .EL
  188. .lm-5
  189. .s
  190. There are other commands that place you in insert mode.  These commands are
  191. used to perform substitutions of text.  That is, the deletion of old text
  192. and the insertion of new text, all in a single operation.  These commands
  193. will be discussed further on because the are actually macros of the
  194. change command.
  195. .!
  196. .send toc .ifnot global
  197. .hl 2 ^*Deleting Copying and Changing\*
  198. .send toc .endif global
  199. .s
  200. The next three operations we will discuss will be deleting, copying, and
  201. changing.  These three will be discussed together because the methods of
  202. describing the text that these commands operate on is identical.
  203. .s
  204. There are well over 30 different ways that you can tell VI to move the
  205. cursor to a new location in the document.  These movements can also be
  206. used to describe sections of the document that you wish to perform operations
  207. on.  Typically, you will type a single keystroke which describes the
  208. type of operation you wish to perform, e.g. 'd' to delete.  There are several
  209. commands that allow you to use a normal movement command to describe a portion
  210. of the document you are editing.  These commands are outlined below. 
  211. .s
  212. .lm+5
  213. .LT
  214. 'd'         Delete text.
  215. 'y'         Copy text (that is, yank it into a holding
  216.             area for later use).
  217. 'c'         Change text from one thing to another, which
  218.             you will type.
  219. '!'         Filter text through a program.
  220. '<'         Shift a region of text to the left.
  221. '>'         Shift a region of text to the right.
  222. .EL
  223. .lm-5
  224. .s
  225. .c;Figure 1.
  226. .s
  227. The first three are the basic text operations that allow you to alter a
  228. document by deleting, copying and changing the text in it.  The last three are
  229. more advanced operations that are useful and handy to have.
  230. .!
  231. .send toc .ifnot global
  232. .hl 1 ^*Single Key Movements\*
  233. .send toc .endif global
  234. .s
  235. Following one of the commands identifying keystrokes listed in Figure 1, you
  236. must tell VI what portion of the document to perform the operation on.
  237. This is done by typing a keystroke that indicates a movement command.
  238. Most of these are outlined below.  The more complicated movements will be
  239. described later on.  Each character is surrounded by single quotes. 
  240. .s
  241. .lm+5
  242. .LT
  243. '`'         Move the cursor to a previously marked location
  244.             in the document.
  245. .EL
  246. .S
  247. .LT
  248. '$'         Move the cursor to the end of the current line,
  249.             or if a count is specified, to the end of the
  250.             (n-1)th line below the current line.
  251. .EL
  252. .S
  253. .LT
  254. '%'         Move the cursor to the matching parenthesis,
  255.             bracket or brace.
  256. .EL
  257. .S
  258. .LT
  259. '^'         Move the cursor to the beginning of the line.
  260. .EL
  261. .S
  262. .LT
  263. '('         Move the cursor to the beginning of the previous
  264.             sentence.
  265. .EL
  266. .S
  267. .LT
  268. ')'         Move the cursor to the beginning of the next
  269.             sentence.
  270. .EL
  271. .S
  272. .LT
  273. '-'         Move the cursor to the first non-blank character
  274.             on the previous line.
  275. .EL
  276. .S
  277. .LT
  278. '+'         Move the cursor to the first non-blank character
  279.             on the next line.
  280. .EL
  281. .S
  282. .LT
  283. 'w'         Move the cursor to the beginning of the next
  284.             type of character, where types are alphanumeric,
  285.             punctuation, and spaces (words of this type are
  286.             commonly refered to as logical words).
  287. .EL
  288. .S
  289. .LT
  290. 'W'         Move the cursor to the next space separated
  291.             word (words of this type are commonly refered
  292.             to as physical words).
  293. .EL
  294. .S
  295. .LT
  296. 'e'         Move the cursor to the end of the current type
  297.             of character.
  298. .EL
  299. .S
  300. .LT
  301. 'E'         Move the cursor to the end of non blank
  302.             characters.
  303. .EL
  304. .S
  305. .LT
  306. 't'         Move the cursor to the the character preceeding
  307.             that cooresponding to the next character typed,
  308.             moving forward.
  309. .EL
  310. .S
  311. .LT
  312. 'T'         Same as 't' but movement is backward.
  313. .EL
  314. .S
  315. .LT
  316. '[['        Move the cursor to the beginning of the current
  317.             section, where a section is outlined later.
  318. .EL
  319. .S
  320. .LT
  321. ']]'        Move the cursor to the beginning of the next
  322.             section, where a section is outlined later.
  323. .EL
  324. .S
  325. .LT
  326. '{'         Move the cursor to the beginning of the current
  327.             paragraph.
  328. .EL
  329. .S
  330. .LT
  331. '}'         Move the cursor to the beginning of the next
  332.             paragraph.
  333. .EL
  334. .S
  335. .LT
  336. 'f'         Move the cursor to the next occurance (find
  337.             character) of the character corresponding to
  338.             the next keystroke typed, moving backwards.
  339. .EL
  340. .S
  341. .LT
  342. 'F'         Same as 'f' but movement is backwards.
  343. .EL
  344. .S
  345. .LT
  346. 'G'         Move the cursor to the line specified by the
  347.             numeric keys typed preceeding this key, or to
  348.             the end of the document if none were typed.
  349. .EL
  350. .S
  351. .LT
  352. 'h'         Move the cursor to the left one character.
  353. .EL
  354. .S
  355. .LT
  356. 'H'         Move the cursor to the top of the Screen, as
  357.             opposed to the top of the document which may
  358.             not be the same.
  359. .EL
  360. .S
  361. .LT            
  362. 'j'         Move the cursor to the same column of the line
  363.             below the current line.
  364. .EL
  365. .S
  366. .LT
  367. 'k'         Move the cursor to the same column of the line
  368.             preceeding the current line.         
  369. .EL
  370. .S
  371. .LT            
  372. 'l'         Move the cursor to the right one character.         
  373. .EL
  374. .S
  375. .LT
  376. 'L'         Move the cursor to the last line on the screen,
  377.             as opposed to the last line of the document
  378.             which may or may not be the same.
  379. .EL
  380. .S
  381. .LT
  382. ';'         Repeat the last 't' or 'f' command, or the last
  383.             'F' or 'T' command but in the forward direction.
  384. .EL
  385. .S
  386. .LT
  387. '''         Move the cursor to the first non-space character
  388.             of the line that the the indicated marker is set
  389.             on.
  390. .EL
  391. .lm-5
  392. .s
  393. You probably will not adopt the immediate use of all of these movements, but
  394. it is possible to gain proficency in their use only by using them.
  395. .!
  396. .send toc .ifnot global
  397. .hl 2 ^*Sample Use of the Single Key Movements\*
  398. .send toc .endif global
  399. .s
  400. Perhaps some sample uses of these movements will make their use a little more
  401. obvious.  Typically, a VI manual resolves to give the reader a list of the most
  402. common keystroke combinations, without trying to describe the real reasoning
  403. behind the keystrokes.  This is part of the reason that VI seems so
  404. foreign to some people, they never discover the relationship of all the
  405. keystrokes to one another.  However, since I have outlined the basic
  406. relationship of the keystrokes, I feel that I can provide a similar chart
  407. without causing any confusion.  The notation <n> means that you may type
  408. one or more of the keys, 0-9, to indicate a repeat count that will cause
  409. the movement indicated to be performed the indicated number of times.
  410. e.g. 5dw will delete five logical words, 35dd will delete thirty five lines.
  411. .!
  412. .send toc .ifnot global
  413. .hl 2 ^*Common Keystroke Combinations\*
  414. .send toc .endif global
  415. .s
  416. .LM +5
  417. .LT
  418. <n>d$   Delete (including the current character),
  419.         to the end of the (n-1)th line.
  420. <n>d^   Delete (excluding the current character),
  421.         to the beginning of the (n-1)th line.
  422. <n>dE   Delete to the end of physical words
  423.         (or TO the next space or tab character).
  424. <n>de   Delete to the end of logical word.
  425. <n>dd   Delete lines.
  426. dG      Delete from the current line to the end
  427.         of the document.
  428. dH      Delete from the current line to the line
  429.         shown at the top of the display, inclusive.
  430. <n>dh   Delete n characters to the left of the
  431.         cursor, 'X' is equivalent to this.
  432. <n>dj   Delete the current line, and the n lines
  433.         below it.
  434. <n>dk   Delete the current line, and the n lines
  435.         above it.
  436. <n>dl   Delete n characters to the right of the
  437.         cursor, including the one under it,
  438.         'x' is equivalent to this.
  439. <n>db   Delete back to the beginning of the
  440.         nth previous logical word.
  441. <n>dB   Delete back to the beginning of the
  442.         nth previous physical word.
  443. .LM-5
  444. .EL
  445.                
  446. .NHD
  447. .PAGE
  448. .X Glossary
  449. .SEND TOC .IFNOT GLOBAL
  450. .HL 2 ^*Glossary\*
  451. .SEND TOC .ENDIF GLOBAL
  452. .S
  453. .LM +5
  454. .LT
  455. logical word    A word that is made up of characters
  456.                 of a common class.  The classes are
  457.                 alphabetic/numeric and '_',
  458.                 punctuation, and space or tab.
  459.  
  460. Physical word   A word that is made up of non-space
  461.                 and non-tab characters.  Or put
  462.                 another way, words made up of
  463.                 printable characters.
  464. .EL
  465. .lm -5
  466. .PAGE
  467. .REQ 'TUTOR.RNX'
  468. *$*$*EOD*$*$*
  469. $ if f$search("DOC.DIR;1") .eqs. "" then -
  470.      CREATE/LOG/DIRECTORY [.DOC]
  471. $ write sys$output "Creating [.DOC]TUTOR.RNT"
  472. $ create [.DOC]TUTOR.RNT
  473. $ DECK/DOLLARS="*$*$*EOD*$*$*"
  474. .! DSRTOC version V2.1-09
  475. .! RUNOFF/CONTENTS/OUT=TUTOR TUTOR.BRN
  476. .SAVE
  477. .NO FLAGS ALL
  478. .NO FLAGS BREAK        .NO FLAGS CAPITALIZE    .NO FLAGS ENDFOOTNOTE
  479. .NO FLAGS HYPHENATE    .NO FLAGS INDEX        .NO FLAGS PERIOD
  480. .NO FLAGS SPACE        .NO FLAGS SUBSTITUTE
  481. .FLAGS ACCEPT _        .FLAGS BOLD *        .FLAGS COMMENT !
  482. .FLAGS LOWERCASE \    .FLAGS OVERSTRIKE %    .FLAGS UNDERLINE &
  483. .FLAGS UPPERCASE ^
  484. .FLAGS ALL
  485. .NO FILL        .NO JUSTIFY
  486. .LEFT MARGIN 8        .RIGHT MARGIN 70    .PAGE SIZE , 70
  487. .CENTER;CONTENTS
  488. .BLANK
  489. .ifnot global
  490. 1       Introduction . . . . . . . . . . . . . . . . . . . . 1
  491. .endif global
  492. .ifnot global
  493. 2       Learning the power of VI . . . . . . . . . . . . . . 3
  494. .endif global
  495. .ifnot global
  496. 2_.1       Inserting Text . . . . . . . . . . . . . . . . . . 4
  497. .endif global
  498. .ifnot global
  499. 2_.2       Deleting Copying and Changing  . . . . . . . . . . 5
  500. .endif global
  501. .ifnot global
  502. 3       Single Key Movements . . . . . . . . . . . . . . . . 5
  503. .endif global
  504. .ifnot global
  505. 3_.1       Sample Use of the Single Key Movements . . . . . . 7
  506. .endif global
  507. .ifnot global
  508. 3_.2       Common Keystroke Combinations  . . . . . . . . . . 8
  509. .endif global
  510. .IFNOT GLOBAL
  511. 3_.3       Glossary . . . . . . . . . . . . . . . . . . . . . 9
  512. .ENDIF GLOBAL
  513. .RESTORE
  514. *$*$*EOD*$*$*
  515. $ if f$search("DOC.DIR;1") .eqs. "" then -
  516.      CREATE/LOG/DIRECTORY [.DOC]
  517. $ write sys$output "Creating [.DOC]TUTOR.RNX"
  518. $ create [.DOC]TUTOR.RNX
  519. $ DECK/DOLLARS="*$*$*EOD*$*$*"
  520. .! DSRINDEX version V2.1-12
  521. .! RUNOFF/INDEX/OUT=TUTOR TUTOR.BRN
  522. .SAVE
  523. .NO FLAGS ALL
  524. .NO FLAGS BREAK        .NO FLAGS CAPITALIZE    .NO FLAGS ENDFOOTNOTE
  525. .NO FLAGS HYPHENATE    .NO FLAGS INDEX        .NO FLAGS LOWERCASE
  526. .NO FLAGS PERIOD    .NO FLAGS SPACE        .NO FLAGS SUBSTITUTE
  527. .NO FLAGS UPPERCASE
  528. .FLAGS ACCEPT _        .FLAGS BOLD *        .FLAGS COMMENT !
  529. .FLAGS OVERSTRIKE %    .FLAGS UNDERLINE &
  530. .FLAGS ALL
  531. .NO FILL        .NO JUSTIFY
  532. .LEFT MARGIN 0        .RIGHT MARGIN 70    .PAGE SIZE , 70
  533. .NUMBER INDEX        .NUMBER PAGE 1        .FIRST TITLE
  534. .CENTER;INDEX
  535. .BLANK3
  536. Deletion, 1                         Insertion, 1
  537.                                     Introduction, 1
  538. Escape, 3
  539.  
  540. Glossary, 9                         Undo, 3
  541. .RESTORE
  542. *$*$*EOD*$*$*
  543. $ if f$search("DOC.DIR;1") .eqs. "" then -
  544.      CREATE/LOG/DIRECTORY [.DOC]
  545. $ write sys$output "Creating [.DOC]HOW-VI-WORKS."
  546. $ create [.DOC]HOW-VI-WORKS.
  547. $ DECK/DOLLARS="*$*$*EOD*$*$*"
  548. The operaton of the program is pretty straight forward.  It goes something
  549. like this.
  550.  
  551. command_mode:
  552.  
  553. 1) TPU$INIT_PROCEDURE arranges for vi$command_mode to be called whenever ANY
  554.    key is pressed, passing it the key_name of the pressed key.
  555. 2) vi$command_mode then looks in the cmd_keys key_map for a definition of that
  556.    key.  This is done to funnel each key stroke through one routine that can
  557.    aid in remembering key strokes for '.' to replay.  There is some logic there
  558.    that determines when a valid sequence that could be replayed has been typed.
  559. 3) The PROGRAM definition for the key is checked for 0 which indicates an
  560.    undefined key, and such keystrokes are ignored.  Otherwise, the PROGRAM
  561.    defined for the key is envoked.
  562.  
  563. 4) There is also some code here to handle the U command.  Basically, we need
  564.    to know when the cursor moves to a new line, so that is handled here.
  565.  
  566. 5) That takes care of command mode.
  567.  
  568. movements:
  569.  
  570. 1) vi$command_mode invokes a program (obtained using LOOKUP_KEY (PROGRAM...))
  571.    that is a function call to a procedure which in turn envokes a generic
  572.    routine that returns a marker indicating the destination of the movement.  If
  573.    the marker is zero, then the position was not found (e.g. a search command
  574.    failed to find an occurance).  vi$position is in charge of deciding whether
  575.    or not a particular location can be moved to, since it keeps track of the '',
  576.    and `` markers.  Thus a typical movement procedure looks something like: 
  577.  
  578.       PROCEDURE vi$find_next (direction)
  579.           vi$position (vi$search_next (vi$old_subs, direction), 1);
  580.       ENDPROCEDURE;
  581.  
  582.    (The names of the variables above may or may not be correct) vi$position
  583.    must be told to remember where we were prior to doing the movement to the
  584.    marker passed to it, and that is what the second parameter does.
  585.  
  586. delete, change, yank, shift, filter:
  587.  
  588. 1) These command each read one or more keys to determine what region is being
  589.    operated on.  An existing select region always has precedence over any other
  590.    type of movement, so if one is active, then NO keystrokes are read. The
  591.    move_keys map describes all of the possible movements that these routines
  592.    will recognize.  They recognize leading numeric counts on movements such as
  593.    d3w which is synonomous with 3dw.  They do a lot of testing for directions so
  594.    that they will know how to adjust markers which are returned from the
  595.    movement routines.  The movement routines are the same generic ones that are
  596.    called from the command mode movement procedures. 
  597.  
  598. 2) The global values, vi$start_pos, vi$endpos, and vi$new_endpos are used to
  599.    mark the region to be worked on.  vi$start_pos is set prior to calling any
  600.    movement procedure, and vi$new_endpos is set to zero.  Any routine that
  601.    wishes to doctor up the value of vi$start_pos, may, and some do. 
  602.    vi$new_endpos allows for a generic movement procedure to be written that
  603.    returns different values based on who is using it.  cw verses dw is a
  604.    prime example.  dw removes trailing white space, while cw does not allow
  605.    you to change it.  Therefore, the move by word routines set vi$new_endpos
  606.    to a different value.  Granted, this could have really been done with
  607.    conditional returns of different values I believe, but for some reason,
  608.    I chose this method.  vi$endpos is assigned the value returned by the
  609.    EXECUTE ( COMPILE ("vi$endpos:="+LOOKUP_KEY(keyn,COMMENT))); statement
  610.    which builds an assignment and compiles and executes it on the fly.
  611.    Following this, vi$endpos will be altered if vi$new_endpos is non-zero.
  612.  
  613. 3) The region to manipulate is mapped out after some hanky panky with end
  614.    points and such, and the action is performed.
  615.  
  616. Undo:
  617.  
  618. 1) Deletes are made undoable by saving the deleted text into a buffer with
  619.    a single line at the top of the buffer describing how the text was
  620.    deleted (i.e. dw vs. dd).  Then, vi$undo_start is set to the location
  621.    where the text should be restored.  vi$undo_end is set to zero in the
  622.    case of delete, as it is used to mark the end of a region of text that
  623.    must be deleted (vi$undo_start is the start) when undo is performed.
  624.  
  625. 2) Puts, are made undoable by setting vi$undo_start to the start of the
  626.    inserted regions, and vi$undo_end to the end.  The routine vi$kill_undo
  627.    assures that no text will be inserted for the next undo.
  628.  
  629. 3) Inserts follow the same strategy as puts.
  630.  
  631. 4) Change commands make use of both facets of undoing.  There is a region
  632.    to delete, that which was typed, and a region to restore, that which
  633.    existed previously.
  634.  
  635.    vi$perform_undo, vi$kill_undo, vi$undo_start and vi$undo_end are the
  636.    main variables and such that undo operations deal with.
  637.  
  638. Inserting:
  639.  
  640. 1) All operations that insert text into a buffer by letting the user type
  641.    text use the routine (after a little hopscotch) vi$line_edit to do
  642.    the actual work.  This routine does a lot of things.  It recognizes
  643.    when abbreviations have been used, and discovers which text has and
  644.    hasn't been typed over by an 'R' command.  Basiclly, this routine
  645.    and its interface is not pretty.  It accepts four parameters.  A starting
  646.    marker where inserting actually begin (this may not be where the cursor
  647.    is at function entry), a corresponding column offset, a return
  648.    parameter which is the ending position, and a flag which determine if
  649.    the 'R' command is active.  This flag is either 0, or the string image
  650.    of the line that is being 'R'd over.  This string is replaced over the
  651.    top of characters that are 'R'd over, but then backspaced over and then
  652.    the user hits ESCAPE.
  653.  
  654. ex mode:
  655.  
  656. 1) Ex mode is a series of operations, the first is reading a string.  Next,
  657.    the beginning is parsed to try and locate a range specification.  This
  658.    range is indicated in several ways inside vi$do_command.  There are
  659.    markers, line numbers, and two ranges, one being the range by line, and
  660.    the other being the range only.  The second range comes into affect
  661.    when things are delimited with search ranges.
  662.  
  663. 2) Once the range of the command has been determined, then the rest of
  664.    the command line is placed into the variable, cmd.  The index variable,
  665.    idx, is used to mark the current location in cmd where we have parsed to.
  666.    All lower case alphabetic characters are extracted from the beginning of
  667.    cmd to get the command to perform.
  668.  
  669. 3) The command is then analyzed by doing simple string compares.  There is
  670.    a certain order to the IF's that perform this activity, as we must
  671.    distiguish between commands with common leading substrings.
  672.  
  673. 4) A special routine handles each command, and that routine has a unique
  674.    set of arguments based on its needs.
  675.  
  676. maps:
  677.  
  678. 1) Maps are handled by placing all of the KEY_NAME values of the key stokes
  679.    into a buffer, one per line.  Whenever a mapped key is detected, then its
  680.    buffers contents are pushed into the typing stream by the function
  681.    vi$insert_macro_keys.  TPU's key values are really strange, and I am not
  682.    so sure that I like the way this is done, it is just that I originally
  683.    wanted to be able to have maps with any keystroke in them, and that
  684.    pretty much eliminated the use of strings (well okay, maybe).
  685.  
  686. 2) The routine vi$do_macro MUST be called to initiate the processing of a
  687.    map, as TPU's main loop does not know about the pushed keys in the input
  688.    stream.  This routines performs all of the actions indicated by the mapped
  689.    key strokes, and then returns control to the caller.  Note that vi$do_macro
  690.    recognizes either strings or buffers of macro key strokes.  There are some
  691.    command mode key strokes that are mapped to macros.
  692.  
  693.       D ==> d$
  694.       s ==> cl
  695.       C ==> c$   etc...
  696.  
  697. learn sequences:
  698.  
  699. 1) Learn sequences are implemented by creating global variables on the
  700.    fly to contain the LEARN program.  Then, a DEFINE_KEY is done to
  701.    pass the program to a routine that knows what to do with it.
  702.  
  703. 2) This routine checks the status of :set undomap, and then performs
  704.    the necessary stuff to set up for undo if undomap is in effect.
  705.  
  706. 3) Then, the program passed is executed.  When the EXECUTE returns,
  707.    the LEARN sequence is complete.  Note that LEARN's are different
  708.    from MAP's in that a map can be recursive, and will stop when it
  709.    finds an error.  A learn sequence just keeps going if it is
  710.    recursive, and NEVER stops.
  711. *$*$*EOD*$*$*
  712. $ exit
  713.