Artifact af34495300e48ff512f6d36b3a85b8744e95f89e127a2d425604ba6d7fcb0af8:
- File
psl-1983/emode/edc.sl
— part of check-in
[eb17ceb7f6]
at
2020-04-21 19:40:01
on branch master
— Add Reduce 3.0 to the historical section of the archive, and some more
files relating to version sof PSL from the early 1980s. Thanks are due to
Paul McJones and Nelson Beebe for these, as well as to all the original
authors.git-svn-id: https://svn.code.sf.net/p/reduce-algebra/code/historical@5328 2bfe0521-f11c-4a00-b80e-6202646ff360 (user: arthurcnorman@users.sourceforge.net, size: 3195) [annotate] [blame] [check-ins using] [more...]
% A simple desk calculator to run under EMODE. In this mode all the % numbers in the buffer are summed up, any other characters are inserted % and ignored, the total is given as the last line of the OUT_WINDOW buffer.. (load useful) % Need useful so that FOR loops work! % Insert a character, and then sum up all the lines in the buffer. (DE InsertAndTotal () (progn (InsertSelfCharacter) (FindBufferTotal))) (DE DeleteBackwardAndTotal () (progn (!$DeleteBackwardCharacter) (FindBufferTotal))) (DE DeleteForwardAndTotal () (progn (!$DeleteForwardCharacter) (FindBufferTotal))) (DE kill_line_and_total () (progn (kill_line) (FindBufferTotal))) (DE insert_kill_buffer_and_total () (progn (insert_kill_buffer) (FindBufferTotal))) (DE FindBufferTotal () (prog (total save-point save-line-index itm) % Remember our spot in the buffer. (setf save-point point) (setf save-line-index CurrentLineIndex) (setf total 0) % Move to the start of the buffer. (!$BeginningOfBuffer) % Read from, and write to, EMODE buffers. (SelectEmodeChannels) % Find the total. (while (not (EndOfBufferP (NextIndex CurrentLineIndex))) (progn % NOTE that READ would loose badly here--since it calls % MakeInputAvailable here, and thus call EMODE recursively. (setf itm (ChannelRead IN*)) (cond ((NumberP itm) (setf total (plus total itm)))))) % Now, show the total in the OUT_WINDOW buffer. (prog (old-point old-line-index old-buffer) (setf old-buffer CurrentBufferName) (SelectBuffer 'OUT_WINDOW) (!$EndOfBuffer) % Move to end of the buffer. (setf old-point point) (setf old-line-index CurrentLineIndex) % Move to beginning of previous line. (!$BackwardLine) (!$BeginningOfLine) % Delete the old text (delete_or_copy T CurrentLineIndex point old-line-index old-point) % Print the total (to the output buffer) (PRINT total) (SelectBuffer old-buffer)) % Finally, restore the original point and mark. (SelectLine save-line-index) (setf point save-point))) % Establish keyboard bindings for Desk Calculator mode. (DE SetDCmode () (progn % Make most characters insert and then find total. (for (from i 32 126 1) (do (SetKey i 'InsertAndTotal))) (SetKey (char TAB) 'InsertAndTotal) % Inherit the rest of the bindings from "text mode" (for (in itm TextDispatchList) (do (SetKey (car itm) (cdr itm)))) % Then, rebind (some of?) the folks who actually modify stuff. (SetKey (char (cntrl D)) 'DeleteForwardAndTotal) (SetKey (char (cntrl K)) 'kill_line_and_total) (SetKey (char DELETE) 'DeleteBackwardAndTotal) (SetKey (char (cntrl Y)) 'insert_kill_buffer_and_total))) (setf DCMode '(RlispInterfaceDispatch SetDCmode BasicDispatchSetup)) % This code must be run AFTER starting up EMODE. (prog (old-buffer) (setf old-buffer CurrentBufferName) (CreateBuffer 'DC DCMode) (SelectBuffer 'DC) (!$CRLF) (insert_string "0") (!$CRLF) (!$BeginningOfBuffer) (SelectBuffer old-buffer))