prompting.sl 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. %
  2. % PROMPTING.SL - "Prompting" utilities for EMODE.
  3. %
  4. % Author: William F. Galway
  5. % Symbolic Computation Group
  6. % Computer Science Dept.
  7. % University of Utah
  8. % Date: 15 July 1982
  9. % Copyright (c) 1982 University of Utah
  10. %
  11. % This file provides functions for prompting the user for information, and
  12. % for general maintenance of the "MODE", "PROMPT", and "MESSAGE" windows.
  13. %%%%% Changes: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  14. % AS 7/16/82
  15. % - Delay prompting for single character input.
  16. (FLUID
  17. '(previous_window % This needs to be rethought!
  18. prompt-immediately % T => prompt_for_character always prompts
  19. prompt-was-output % T => prompt_for_character prompted last time
  20. ))
  21. (setq prompt-immediately NIL)
  22. (setq prompt-was-output NIL)
  23. (de prompt_for_character (prompt_string)
  24. % Prompt for (and echo) a single character. Avoid prompting if the user has
  25. % already typed a character or types a character right away. The fluid
  26. % variables PROMPT-IMMEDIATELY and PROMPT-WAS-OUTPUT are used to implement
  27. % sequences of prompts, as done by C-U (for example). Within a sequence of
  28. % related prompts, once a prompt is output, further prompting should be done
  29. % immediately.
  30. % Echo handling needs to do better job of handling control characters, etc.
  31. % First check whether a character is typed quickly. If it is, then
  32. % return it directly without echoing anything.
  33. (if (not prompt-immediately) (sleep-until-timeout-or-input 30))
  34. (setq prompt-was-output (or prompt-immediately (= (CharsInInputBuffer) 0)))
  35. (if (not prompt-was-output)
  36. (GetNextCommandCharacter)
  37. % else
  38. (show_prompt prompt_string) % Setup & select the prompt window.
  39. (let ((ch (GetNextCommandCharacter)))
  40. (cond
  41. ((MetaP ch)
  42. (insert_string "M-")
  43. (InsertCharacter (UnMeta ch)))
  44. (T
  45. (InsertCharacter ch)))
  46. (SelectWindow previous_window) % Go back to old window.
  47. ch
  48. )))
  49. % Prompt for a string (terminated by newline). Use default_string if an
  50. % empty string is returned, (and if default_string is non-NIL).
  51. (de prompt_for_string (prompt_string default_string)
  52. (prog (return_string old-msg-string)
  53. % Show the default, if non-NIL.
  54. (cond
  55. (default_string
  56. (setf old-msg-string
  57. (show_message (concat "Default is: " default_string)))))
  58. % Show the prompt string, and select the "prompt window" (and buffer).
  59. (show_prompt prompt_string)
  60. % Set up mode to pick up a single line of text.
  61. (setf ModeEstablishExpressions '((setup_insert_single_line_mode)))
  62. (EstablishCurrentMode)
  63. % Edit the buffer until an "exit" character is typed.
  64. (EMODEdispatchLoop)
  65. % Pick up the string that was typed.
  66. (setf return_string (GetBufferText CurrentLineIndex))
  67. % Switch back to old window, etc.
  68. (SelectWindow previous_window)
  69. % Restore original "message window label", if it was "hammered".
  70. % Important to do this AFTER (SelectWindow previous_window)
  71. (cond
  72. (default_string (show_message old-msg-string)))
  73. (EstablishCurrentMode)
  74. % If an empty string, use default (unless it's NIL).
  75. (cond
  76. ((and
  77. default_string
  78. (equal return_string ""))
  79. (setf return_string default_string)))
  80. (return return_string)))
  81. % Define a mode for editing a single line of text. Nearly identical to text
  82. % mode. (No 100% guarantee that a single line is all that will be put into
  83. % the buffer, since it's possible to yank back text from the kill buffer,
  84. % for example.)
  85. (de setup_insert_single_line_mode ()
  86. (progn
  87. (for (from i 0 31 1)
  88. (do
  89. (setf (indx MainDispatch i) 'leave_dispatch_loop)))
  90. (for (from i 127 255 1)
  91. (do
  92. (setf (indx MainDispatch i) 'leave_dispatch_loop)))
  93. % "Normal characters" insert themselves.
  94. (for (from i 32 126 1)
  95. (do
  96. (MakeSelfInserting i)))
  97. (MakeSelfInserting (char TAB))
  98. % It would be nice to add some of these folks who are stolen from
  99. % BasicDispatchSetup. BUT, they screw up because they invoke
  100. % prompt_for_character (or some such), which typically will try to grab
  101. % the same window that this mode is invoked in causing bad confusion.
  102. % We need a better method (or philosphy) for doing this.
  103. % (SetKey (char ESC) 'EscapeAsMeta)
  104. % (SetKey (char (cntrl Z)) 'DoControlMeta)
  105. % Make right paren "bounce" to matching left paren.
  106. (SetKey (char '!) ) 'insert_matching_paren)
  107. % Other reasonable (??) commands for editing within the line. Includes
  108. % most of the features of text mode.
  109. (SetKey (char (cntrl '!@)) 'SetMark)
  110. (SetKey (char (cntrl A)) '!$BeginningOfLine)
  111. (SetKey (char (cntrl B)) '!$BackwardCharacter)
  112. (SetKey (char (cntrl D)) '!$DeleteForwardCharacter)
  113. (SetKey (char (cntrl E)) '!$EndOfLine)
  114. (SetKey (char (cntrl F)) '!$ForwardCharacter)
  115. (SetKey (char DELETE) '!$DeleteBackwardCharacter)
  116. (SetKey (char (cntrl K)) 'kill_line)
  117. (SetKey (char (cntrl T)) 'transpose_characters)
  118. (SetKey (char (cntrl Y)) 'insert_kill_buffer)
  119. (SetKey (char (meta (cntrl B))) 'backward_sexpr)
  120. (SetKey (char (meta (cntrl F))) 'forward_sexpr)
  121. (SetKey (char (meta (cntrl K))) 'kill_forward_sexpr)
  122. (SetKey (char (meta (cntrl RUBOUT))) 'kill_backward_sexpr)
  123. (SetKey (char (meta B)) 'backward_word)
  124. (SetKey (char (meta D)) 'kill_forward_word)
  125. (SetKey (char (meta F)) 'forward_word)
  126. (SetKey (char (meta W)) 'copy_region)
  127. (SetKey (char (meta Y)) 'unkill_previous)
  128. (SetKey (char (meta DELETE)) 'kill_backward_word)
  129. (SetKey (CharSequence (cntrl X) (cntrl X)) 'ExchangePointAndMark)))
  130. % Setup and select the prompt window, "remember" the old window in Fluid
  131. % "previous_window".
  132. (de show_prompt (prompt_string)
  133. (string_in_window prompt_string prompt_window))
  134. % Display a string in the "message" window, return the previous label
  135. % string for that window.
  136. (de show_message (strng)
  137. (prog (old-label)
  138. (setf old-label
  139. (string_in_window strng message_window))
  140. % Don't stay in message window.
  141. (SelectWindow previous_window)
  142. % Refresh in order to update the cursor position
  143. (optional_refresh)
  144. (return old-label)))
  145. % "Pop up" and select a window (typically one-line and unframed). Use
  146. % "strng" to label the window, clear out the associated buffer, return the
  147. % old label string. "Remember" the previous window in fluid previous_window.
  148. (de string_in_window (strng window)
  149. (prog (old-label)
  150. (setf previous_window CurrentWindowDescriptor)
  151. (SelectWindow window)
  152. (!$DeleteBuffer) % Kill everything in the buffer
  153. % Save the old label and then put strng into the per-(unframed)window
  154. % "label" variable.
  155. (setf old-label window_label)
  156. (setf window_label strng)
  157. (optional_refresh) % Let the user see it!
  158. (return old-label)))