rec.sl 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2. %
  3. % REC.SL - Recursive Editing Functioons
  4. %
  5. % Author: Jeffrey Soreff
  6. % Hewlett-Packard/CRC
  7. % Date: 24 Jan 1983
  8. %
  9. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  10. (compiletime (load extended-char fast-int objects))
  11. % External variables used here:
  12. (fluid '(recurse-mode nmode-current-buffer))
  13. % Global variables defined here:
  14. (fluid '(recurse-query recurse-query-answered))
  15. % Recurse-Query will be T if the user leaves a recursive editing level
  16. % with a "Y". It will be nil if the user leaves with an "N". In either
  17. % of those cases recurse-query-answered will be set to T. If the user
  18. % leaves the recursive editing level by some other means then
  19. % recurse-query-answered will be NIL.
  20. (de recursive-edit-y-or-n (buffer outer-message inner-message)
  21. % This function allows a user to make a yes or no decision about
  22. % some buffer, either before looking at it with the editor or while
  23. % editing within it. Before starting to edit the user is prompted
  24. % with the outer message. This function takes care of interpreting a
  25. % Y or N prior to editing and of providing a prompt (the outer
  26. % message) before editing. The call to recursive-edit takes care of
  27. % the prompt during editing and of interpreting a Y or N during
  28. % editing. This function returns a boolean value.
  29. (prog1
  30. (while t
  31. (write-message outer-message)
  32. (let ((ch (x-char-upcase (input-extended-character))))
  33. (when (= ch (x-char Y)) (exit T))
  34. (when (= ch (x-char N)) (exit NIL))
  35. (when (= ch (x-char C-R))
  36. (recursive-edit buffer recurse-mode inner-message))
  37. (when recurse-query-answered (exit recurse-query))))
  38. (write-message "")))
  39. (de recursive-edit (new-buffer mode inner-message)
  40. % This function triggers the recursive editing loop, switching
  41. % buffers, setting the new buffer temporarily into a user selected
  42. % mode, and returning the buffer and mode to their old values after
  43. % the editing. This function returns a value only through global
  44. % variables, particularly recurse-query and recurse-query-answered.
  45. (let ((old-buffer nmode-current-buffer)
  46. (old-mode (=> new-buffer mode)))
  47. (=> new-buffer set-mode mode)
  48. (buffer-select new-buffer)
  49. (let ((old-message (write-message inner-message)))
  50. (setf recurse-query-answered NIL)
  51. (nmode-reader NIL)
  52. (write-message old-message))
  53. (=> new-buffer set-mode old-mode)
  54. (buffer-select old-buffer))) % Note: resets nmode-current-buffer
  55. (de affirmative-exit ()
  56. % Returns T from a recursive editing mode, usually bound to Y.
  57. (setf recurse-query T)
  58. (setf recurse-query-answered T)
  59. (exit-nmode-reader))
  60. (de negative-exit ()
  61. % Returns NIL from a recursive editing mode, usually bound to N.
  62. (setf recurse-query NIL)
  63. (setf recurse-query-answered T)
  64. (exit-nmode-reader))