toy-mode.sl 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. %
  2. % TOY-MODE.SL - A "toy" to demonstrate a "non-text" data mode
  3. %
  4. % Author: William F. Galway
  5. % Symbolic Computation Group
  6. % Computer Science Dept.
  7. % University of Utah
  8. % Date: 12 August 1982
  9. % Copyright (c) 1982 University of Utah
  10. %
  11. % In reality, this is really the same as text, but with a different refresh
  12. % algorithm.
  13. % Need to fix clear window problems at creation time, plus misc clear to
  14. % end of line problems plus onewindow/twowindow problems.
  15. (load nstruct)
  16. (declare_data_mode "toy" 'create_toy_buffer)
  17. % Taken from "create_text_buffer"
  18. (de create_toy_buffer ()
  19. % Environment bindings for this buffer.
  20. % May prefer to use backquote to do this, but current version is buggy
  21. % for lists of the form `( (a .b) ). Also, it's important not to share
  22. % any substructure with other alists built by this routine.
  23. (list
  24. % The following 5 "per buffer" variables should be defined for a buffer
  25. % of any "data mode".
  26. (cons 'buffers_view_creator 'create_toy_view)
  27. (cons 'buffers_file_reader 'read_channel_into_text_buffer)
  28. (cons 'buffers_file_writer 'write_text_buffer_to_channel)
  29. (cons 'buffers_file NIL) % Name of file associated with buffer.
  30. (cons 'ModeEstablishExpressions RlispMode)
  31. % Variables unique to "text data mode" follow.
  32. % Initial vector allows only one line. (Should really be parameterized
  33. % somehow?)
  34. (cons 'CurrentBufferText (MkVect 0)) % 0 is upper bound, one element.
  35. (cons 'CurrentBufferSize 1) % Start with one line of text (but zero
  36. % characters in the line! )
  37. (cons 'CurrentLine NIL)
  38. (cons 'CurrentLineIndex 0)
  39. (cons 'point 0)
  40. % MarkLineIndex corresponds to CurrentLineIndex, but for "mark".
  41. (cons 'MarkLineIndex 0)
  42. (cons 'MarkPoint 0) % Corresponds to "point".
  43. ))
  44. % Modified from "create_text_view"
  45. (de create_toy_view (buffer-name)
  46. (cond
  47. % If the current buffer also uses a "toy view" or "text view" (hum,
  48. % needs more work--not very modular! )
  49. ((memq buffers_view_creator
  50. '(create_text_view create_toy_view))
  51. % Just modify (destructively) the current "view" (or "window")
  52. % environment to look into the new buffer, use the proper refresh
  53. % algorithm, return the current environment.
  54. (SelectBuffer buffer-name)
  55. % Let window know what buffer it's looking into (wierd)!
  56. (setf WindowsBufferName buffer-name)
  57. (setf windows_refresher (function refresh_toy_window))
  58. % Make sure the virtual screen is properly cleared and framed.
  59. (ClearVirtualScreen CurrentVirtualScreen)
  60. (FrameScreen CurrentVirtualScreen)
  61. % Save (and return) the current "view" environment.
  62. (SaveEnv CurrentWindowDescriptor))
  63. % Otherwise (if current view isn't into "text" or "toy"), create a
  64. % framed window of an appropriate size and at an appropriate location.
  65. % (For lack of a better idea, just use a large window taking up most of
  66. % the screen--same as provided by "OneWindow".)
  67. (T
  68. (let
  69. ((new-view
  70. (FramedWindowDescriptor
  71. buffer-name
  72. % Upper left corner
  73. (coords (sub1 (Column ScreenBase)) (sub1 (Row ScreenBase)))
  74. % Size of window uses entire width of screen, leaves room for two
  75. % one line windows at bottom of screen.
  76. (coords (plus 2 (Column ScreenDelta)) (sub1 (Row ScreenDelta)))
  77. )))
  78. (setf (cdr (atsoc 'windows_refresher new-view))
  79. (function refresh_toy_window))
  80. new-view))))
  81. (fluid '(row_offset column_offset))
  82. % Taken from refresh_framed_window.
  83. (de refresh_toy_window ()
  84. (progn
  85. (setf row_offset 1)
  86. (setf column_offset 1)
  87. (quietly_copyd 'original-WriteToScreen 'WriteToScreen)
  88. (quietly_copyd 'WriteToScreen 'backwards-WriteToScreen)
  89. (refresh_text)
  90. (quietly_copyd 'WriteToScreen 'original-WriteToScreen)
  91. (refresh_frame_label)
  92. (MoveToScreenLocation
  93. CurrentVirtualScreen
  94. (plus
  95. row_offset (CountLinesFrom TopOfDisplayIndex CurrentLineIndex))
  96. (difference
  97. (VirtualScreenWidth CurrentVirtualScreen)
  98. (plus
  99. column_offset
  100. (difference
  101. (LineColumn point CurrentLine)
  102. ShiftDisplayColumn))))))
  103. (de backwards-WriteToScreen (Scrn chr rw col)
  104. (original-WriteToScreen
  105. Scrn
  106. chr
  107. rw
  108. (difference (VirtualScreenWidth Scrn) col)))
  109. (de quietly_copyd (dest src)
  110. (let ((*USERMODE NIL) (*REDEFMSG NIL))
  111. (copyd dest src)))
  112. (de quietly_putd (fname ftype body)
  113. (let ((*USERMODE NIL) (*REDEFMSG NIL))
  114. (putd fname ftype body)))