commands.sl 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2. %
  3. % Commands.SL - Miscellaneous NMODE commands
  4. %
  5. % Author: Alan Snyder
  6. % Hewlett-Packard/CRC
  7. % Date: 24 August 1982
  8. % Revised: 3 December 1982
  9. %
  10. % 3-Dec-82 Alan Snyder
  11. % Changed Insert-Self-Command to handle control- and meta- characters.
  12. %
  13. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  14. (CompileTime (load objects extended-char fast-int))
  15. % External variables used:
  16. (fluid '(nmode-current-buffer nmode-command-argument nmode-current-window
  17. nmode-command-argument-given nmode-current-command
  18. nmode-terminal nmode-allow-refresh-breakout
  19. Text-Mode
  20. ))
  21. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  22. (de insert-self-command ()
  23. (if (FixP nmode-current-command)
  24. (let ((ch (x-base nmode-current-command)))
  25. (if (x-control? nmode-current-command)
  26. (let ((nch (char-upcase ch)))
  27. (if (and (>= nch #/@) (<= nch #/_))
  28. (setf ch (^ nch #/@))
  29. )))
  30. (for (from i 1 nmode-command-argument)
  31. (do (insert-character ch)))
  32. )
  33. % otherwise
  34. (Ding)
  35. ))
  36. (de insert-next-character-command ()
  37. (nmode-append-separated-prompt "C-Q")
  38. (let ((ch (x-base (input-direct-terminal-character))))
  39. (nmode-complete-prompt (string-concat " " (x-char-name ch)))
  40. (for (from i 1 nmode-command-argument)
  41. (do (insert-character ch)))))
  42. (de return-command ()
  43. % Insert an EOL, unless we are at the end of thee current line and the
  44. % next line is empty. Repeat as directed.
  45. (for (from i 1 nmode-command-argument)
  46. (do (cond ((and (at-line-end?) (not (at-buffer-end?)))
  47. (move-to-next-line)
  48. (cond ((not (current-line-empty?))
  49. (insert-eol)
  50. (move-to-previous-line)
  51. )))
  52. (t (insert-eol))))))
  53. (de select-buffer-command ()
  54. (buffer-select (prompt-for-selectable-buffer)))
  55. (de prompt-for-selectable-buffer ()
  56. (let ((default-b (=> nmode-current-buffer previous-buffer)))
  57. (if (and default-b (not (buffer-is-selectable? default-b)))
  58. (setf default-b NIL))
  59. (prompt-for-buffer "Select Buffer: " default-b)))
  60. (de kill-buffer-command ()
  61. (let ((b (prompt-for-existing-buffer "Kill buffer: " nmode-current-buffer)))
  62. (if (or (not (=> b modified?))
  63. (YesP "Kill unsaved buffer?"))
  64. (buffer-kill-and-detach b))))
  65. (de insert-buffer-command ()
  66. (let ((b (prompt-for-existing-buffer "Insert Buffer:" nmode-current-buffer)))
  67. (insert-buffer-into-buffer b nmode-current-buffer)
  68. ))
  69. (de select-previous-buffer-command ()
  70. (let ((old-buffer nmode-current-buffer))
  71. (buffer-select-previous nmode-current-buffer)
  72. (if (eq old-buffer nmode-current-buffer) (Ding)) % nothing visible happened
  73. ))
  74. (de visit-in-other-window-command ()
  75. (nmode-2-windows)
  76. (selectq (char-upcase (input-base-character))
  77. (#/B (let ((b (prompt-for-selectable-buffer)))
  78. (window-select-buffer (nmode-other-window) b)))
  79. (#/F (find-file-in-window
  80. (nmode-other-window)
  81. (prompt-for-file-name "Find file: " NIL)
  82. ))
  83. (t (Ding))
  84. ))
  85. (de nmode-refresh-command ()
  86. (if nmode-command-argument-given
  87. (let* ((arg nmode-command-argument)
  88. (w nmode-current-window)
  89. (height (=> w height))
  90. (line (current-line-pos))
  91. )
  92. (if (>= arg 0)
  93. (=> w set-buffer-top (- line arg))
  94. (=> w set-buffer-top (- (- line height) arg)))
  95. (nmode-refresh)
  96. )
  97. % Otherwise
  98. (=> nmode-current-window readjust-window)
  99. (nmode-full-refresh)
  100. ))
  101. (de open-line-command ()
  102. (for (from i 1 nmode-command-argument)
  103. (do (insert-eol)
  104. (move-backward)
  105. )))
  106. (de Ding ()
  107. (=> nmode-terminal ring-bell))
  108. (de buffer-not-modified-command ()
  109. (=> nmode-current-buffer set-modified? NIL)
  110. )
  111. (de set-mark-command ()
  112. (cond (nmode-command-argument-given
  113. (buffer-set-position (current-mark))
  114. (previous-mark)
  115. )
  116. (t
  117. (set-mark-from-point)
  118. )))
  119. (de mark-beginning-command ()
  120. (let ((old-pos (buffer-get-position)))
  121. (move-to-buffer-start)
  122. (set-mark-from-point)
  123. (buffer-set-position old-pos)
  124. ))
  125. (de mark-end-command ()
  126. (let ((old-pos (buffer-get-position)))
  127. (move-to-buffer-end)
  128. (set-mark-from-point)
  129. (buffer-set-position old-pos)
  130. ))
  131. (de transpose-characters-command ()
  132. (cond ((or (at-line-start?) (< (current-line-length) 2))
  133. (Ding)
  134. )
  135. (t
  136. (if (at-line-end?) % We are at the end of a non-empty line.
  137. (move-backward)
  138. )
  139. % We are in the middle of a line.
  140. (let ((ch (previous-character)))
  141. (delete-previous-character)
  142. (move-forward)
  143. (insert-character ch)
  144. )
  145. )))
  146. (de mark-word-command ()
  147. (let ((old-pos (buffer-get-position)))
  148. (move-forward-word-command)
  149. (set-mark-from-point)
  150. (buffer-set-position old-pos)
  151. ))
  152. (de mark-form-command ()
  153. (let ((old-pos (buffer-get-position)))
  154. (move-forward-form-command)
  155. (set-mark-from-point)
  156. (buffer-set-position old-pos)
  157. ))
  158. (de mark-whole-buffer-command ()
  159. (move-to-buffer-end)
  160. (set-mark-from-point)
  161. (move-to-buffer-start)
  162. )
  163. (de nmode-abort-command ()
  164. (throw 'abort NIL)
  165. )
  166. (de start-scripting-command ()
  167. (let ((b (prompt-for-buffer "Script Input to Buffer:" NIL)))
  168. (nmode-script-terminal-input b)
  169. ))
  170. (de stop-scripting-command ()
  171. (nmode-script-terminal-input nil)
  172. )
  173. (de execute-buffer-command ()
  174. (let ((b (prompt-for-buffer "Execute from Buffer:" NIL)))
  175. (setf nmode-allow-refresh-breakout nmode-command-argument-given)
  176. (nmode-execute-buffer b)
  177. ))
  178. (de execute-file-command ()
  179. (nmode-execute-file (prompt-for-file-name "Execute File:" NIL)))
  180. (de nmode-execute-file (fn)
  181. (let ((b (buffer-create-unselectable "FOO" Text-Mode)))
  182. (read-file-into-buffer b fn)
  183. (setf nmode-allow-refresh-breakout nmode-command-argument-given)
  184. (nmode-execute-buffer b)
  185. ))
  186. (de apropos-command ()
  187. (let ((s (prompt-for-string
  188. "Show commands whose names contain the string:"
  189. NIL
  190. )))
  191. (nmode-begin-typeout)
  192. (print-matching-dispatch s)
  193. (printf "-----")
  194. (nmode-end-typeout)
  195. ))