home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / beav1402.zip / word.c < prev   
Text File  |  1993-04-16  |  3KB  |  122 lines

  1. /*
  2. *       Word mode commands.
  3. * The routines in this file
  4. * implement commands that work unit at
  5. * a time. There are all sorts of unit mode
  6. * commands. If I do any sentence and/or paragraph
  7. * mode commands, they are likely to be put in
  8. * this file.
  9. */
  10. #include    "def.h"
  11.  
  12. extern BUFFER sav_buf;
  13. char forwunit ();
  14.  
  15. /*
  16. * Move the cursor backward by
  17. * "n" units. All of the details of motion
  18. * are performed by the "backchar" and "forwchar"
  19. * routines. Error if you try to move beyond
  20. * the buffers.
  21. */
  22. char
  23. backunit (f, n, k)
  24.     int f, n, k;
  25. {
  26.     char ret;
  27.  
  28.     if (n < 0)
  29.     return (forwunit (f, -n, KRANDOM));
  30.  
  31.     curwp->w_unit_offset = 0;
  32.     while (n--)
  33.     {
  34.     ret = move_ptr (curwp, -(long) R_B_PER_U (curwp), TRUE, TRUE, TRUE);
  35.     }
  36.     wind_on_dot (curwp);
  37.     curwp->w_flag |= WFMODE;    /* update mode line */
  38.     return (ret);
  39. }
  40.  
  41. /*
  42. * Move the cursor forward by
  43. * the specified number of units. All of the
  44. * motion is done by "forwchar". Error if you
  45. * try and move beyond the buffer's end.
  46. */
  47. char
  48. forwunit (f, n, k)
  49.     int f, n, k;
  50. {
  51.  
  52.     if (n < 0)
  53.     return (backunit (f, -n, KRANDOM));
  54.  
  55.     curwp->w_unit_offset = 0;
  56.     while (n--)
  57.     {
  58.     move_ptr (curwp, (long) R_B_PER_U (curwp), TRUE, TRUE, TRUE);
  59.     }
  60.     wind_on_dot (curwp);
  61.     curwp->w_flag |= WFMODE;    /* update mode line */
  62.     return (TRUE);
  63. }
  64.  
  65. /*
  66. * Kill forward by "n" units. The rules for final
  67. * status are now different. It is not considered an error
  68. * to delete fewer units than you asked. This lets you say
  69. * "kill lots of units" and have the command stop in a reasonable
  70. * way when it hits the end of the buffer.
  71. */
  72. bool
  73. delfunit (f, n, k)
  74.     int f, n, k;
  75. {
  76.     if (n < 0)
  77.     return (FALSE);
  78.     if ((lastflag & CFKILL) == 0)    /* Purge kill buffer.   */
  79.     bclear (&sav_buf);
  80.     thisflag |= CFKILL;
  81.     while (n--)
  82.     {
  83.     ldelete ((A32) (R_B_PER_U (curwp)), TRUE);
  84.     }
  85.     curwp->w_flag |= WFHARD;
  86.     curwp->w_unit_offset = 0;
  87.     return (TRUE);
  88. }
  89.  
  90. /*
  91. * Kill backwards by "n" units. The rules
  92. * for success and failure are now different, to prevent
  93. * strange behavior at the start of the buffer. The command
  94. * only fails if something goes wrong with the actual delete
  95. * of the characters. It is successful even if no characters
  96. * are deleted, or if you say delete 5 units, and there are
  97. * only 4 units left. I considered making the first call
  98. * to "backchar" special, but decided that that would just
  99. * be wierd. Normally this is bound to "M-Rubout" and
  100. * to "M-Backspace".
  101. */
  102. bool
  103. delbunit (f, n, k)
  104.     int f, n, k;
  105. {
  106.     int size;
  107.  
  108.     if (n < 0)
  109.     return (FALSE);
  110.     if ((lastflag & CFKILL) == 0)    /* Purge kill buffer.   */
  111.     bclear (&sav_buf);
  112.     thisflag |= CFKILL;
  113.     size = R_B_PER_U (curwp);
  114.     while (n--)
  115.     {
  116.     if (move_ptr (curwp, -((long) size), TRUE, TRUE, TRUE))
  117.         ldelete ((A32) size, TRUE);
  118.     }
  119.     curwp->w_flag |= WFHARD;
  120.     return (TRUE);
  121. }
  122.