browser-support.sl 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2. %
  3. % Browser-Support.SL - General Browser Support
  4. %
  5. % Author: Alan Snyder
  6. % Hewlett-Packard/CRC
  7. % Date: 18 October 1982
  8. % Revised: 3 February 1983
  9. %
  10. % 3-Feb-83 Alan Snyder
  11. % Revised to use Browser objects.
  12. %
  13. % This file contains support functions for browsers, such as the Buffer
  14. % Browser and DIRED. A browser is a buffer that displays a set of items,
  15. % one item per line, and allows the individual items to be manipulated.
  16. %
  17. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  18. (compiletime (load numeric-operators))
  19. (on fast-integers)
  20. % External variables:
  21. (fluid '(
  22. nmode-current-buffer
  23. nmode-current-window
  24. nmode-command-argument
  25. nmode-command-argument-given
  26. ))
  27. % Global options:
  28. (fluid '(
  29. browser-split-screen
  30. ))
  31. (setf browser-split-screen NIL)
  32. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  33. % General Browser Support Functions
  34. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  35. (de browser-enter (b)
  36. % Start up a browser using the buffer B.
  37. (=> b set-previous-buffer nmode-current-buffer)
  38. (let ((wp (nmode-window-position)))
  39. (=> b put 'window-status wp)
  40. (if browser-split-screen
  41. (if (eq wp 'bottom) (nmode-switch-windows))
  42. (nmode-1-window)
  43. ))
  44. (buffer-select b)
  45. )
  46. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  47. % Browser commands: attach these to keys in your browser mode
  48. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  49. (de browser-kill-and-exit-command ()
  50. (browser-kill-deleted-items-command)
  51. (browser-exit-command)
  52. )
  53. (de browser-exit-command ()
  54. (let ((ws (=> nmode-current-buffer get 'window-status))
  55. (browser (=> nmode-current-buffer get 'browser))
  56. )
  57. (window-kill-buffer)
  58. (nmode-set-window-position ws)
  59. (=> browser exit)
  60. ))
  61. (de browser-delete-command ()
  62. % Mark items as 'deleted'.
  63. (browser-do-repeated-command 'delete-item () nil)
  64. )
  65. (de browser-undelete-command ()
  66. % Mark items as not 'deleted'.
  67. (browser-do-repeated-command 'undelete-item () nil)
  68. )
  69. (de browser-undelete-backwards-command ()
  70. % Mark items as not 'deleted'.
  71. (setf nmode-command-argument (- nmode-command-argument))
  72. (browser-do-repeated-command 'undelete-item () nil)
  73. )
  74. (de browser-kill-command ()
  75. % Kill items.
  76. (browser-do-repeated-command 'kill-item () t)
  77. )
  78. (de browser-ignore-command ()
  79. % Ignore items: filter them out.
  80. (browser-do-repeated-command 'ignore-item () t)
  81. )
  82. (de browser-view-command ()
  83. % View the current item.
  84. (let* ((use-other (xor browser-split-screen nmode-command-argument-given))
  85. (w (if use-other (nmode-other-window) nmode-current-window))
  86. )
  87. (if (browser-view-item w)
  88. (if use-other
  89. (nmode-2-windows) % display the other window
  90. (set-message "C-M-L returns to browser.")
  91. )
  92. (Ding)
  93. )))
  94. (de browser-edit-command ()
  95. % Edit the current item.
  96. (let* ((use-other (xor browser-split-screen nmode-command-argument-given))
  97. (w (if use-other (nmode-other-window) nmode-current-window))
  98. )
  99. (if (browser-view-item w)
  100. (cond (use-other
  101. (nmode-2-windows) % display the other window
  102. (nmode-select-window w)
  103. (set-message "C-X O returns to browser.")
  104. )
  105. (t
  106. (set-message "C-M-L returns to browser.")
  107. ))
  108. (Ding)
  109. )))
  110. (de browser-kill-deleted-items-command ()
  111. (let ((browser (=> nmode-current-buffer get 'browser)))
  112. (=> browser kill-deleted-items)
  113. ))
  114. (de browser-undo-filter-command ()
  115. (let* ((browser (=> nmode-current-buffer get 'browser))
  116. (filter (=> browser undo-filter))
  117. )
  118. (if filter
  119. (set-prompt (bldmsg "Application of %w undone." filter))
  120. (nmode-error "No filters have been applied to create this list.")
  121. )))
  122. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  123. % Browser functions: use these in browser commands
  124. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  125. (de browser-sort (prompt sorter)
  126. (let ((browser (=> nmode-current-buffer get 'browser)))
  127. (=> browser sort sorter)
  128. (write-prompt prompt)
  129. ))
  130. (de browser-view-item (w)
  131. % View the current item in the specified window. Return T if successful,
  132. % NIL otherwise.
  133. (let* ((browser (=> nmode-current-buffer get 'browser))
  134. (buffer (=> browser view-item))
  135. )
  136. (when buffer
  137. (=> buffer set-previous-buffer nmode-current-buffer)
  138. (window-select-buffer w buffer)
  139. T
  140. )))
  141. (de browser-do-repeated-command (msg args removes?)
  142. % Perform a browser command that takes a signed numeric argument to mean
  143. % a repetition count. On each iteration, the browser is sent
  144. % the specified message with the specified arguments. If REMOVES? is
  145. % true, then the browser operation may remove the current item and
  146. % it will return true if it does.
  147. (let ((browser (=> nmode-current-buffer get 'browser)))
  148. (if (> nmode-command-argument 0)
  149. (for (from i 1 nmode-command-argument)
  150. (do (when (not (=> browser current-item))
  151. (Ding) (exit))
  152. (if (not (and (lexpr-send browser msg args) removes?))
  153. (move-to-next-line)
  154. )))
  155. (for (from i 1 (- nmode-command-argument))
  156. (do (when (current-line-is-first?)
  157. (Ding) (exit))
  158. (move-to-previous-line)
  159. (when (not (=> browser current-item))
  160. (move-to-next-line) (Ding) (exit))
  161. (lexpr-send browser msg args)
  162. ))
  163. )))
  164. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  165. (off fast-integers)