Changeset 81da6ba in git
- Timestamp:
- Jul 31, 1998, 11:05:53 PM (26 years ago)
- Branches:
- (u'spielwiese', '17f1d200f27c5bd38f5dfc6e8a0879242279d1d8')
- Children:
- 1e301581f50efc59aa3df4bf54ca5119abd10448
- Parents:
- 8c4d791b0134ec4b991923ab17351f17c74f3187
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
emacs/singular.el
r8c4d79 r81da6ba 1 1 ;;; singular.el --- Emacs support for Computer Algebra System Singular 2 2 3 ;; $Id: singular.el,v 1.1 5 1998-07-31 08:18:30schmidt Exp $3 ;; $Id: singular.el,v 1.16 1998-07-31 21:05:53 schmidt Exp $ 4 4 5 5 ;;; Commentary: … … 74 74 (defmacro singular-debug (mode form &optional else-form) 75 75 "Major debugging hook for singular.el. 76 Evaluates FORM if `singular-debug' equals `all' or if MODE is an77 element of `singular-debug', othwerwise ELSE-FORM"78 `(if (or (eq singular-debug 'all)76 Evaluates FORM if `singular-debug' equals t or if MODE is an element 77 of `singular-debug', othwerwise ELSE-FORM." 78 `(if (or (eq singular-debug t) 79 79 (memq ,mode singular-debug)) 80 80 ,form … … 213 213 The buffer name is the process name with surrounding `*'." 214 214 (concat "*" process-name "*")) 215 216 (defun singular-run-hook-with-arg-and-value (hook value) 217 "Call functions on HOOK. 218 Provides argument VALUE. If a function returns a non-nil value it 219 replaces VALUE as new argument to the functions. Returns final 220 VALUE." 221 (let (result) 222 (while hook 223 (setq result (funcall (car hook) value)) 224 (and result (setq value result)) 225 (setq hook (cdr hook))) 226 value)) 215 227 216 228 (defmacro singular-process () … … 305 317 (substring string beg end))) 306 318 307 (defconst singular-extended-prompt-regexp "\\([ >.] \\)"319 (defconst singular-extended-prompt-regexp "\\([?>.] \\)" 308 320 "Matches one Singular prompt. 309 321 Should not be anchored neither to start nor to end!") … … 327 339 (defun singular-remove-prompt (beg end) 328 340 "Remove all superfluous prompts from region between BEG and END. 329 More precisely, removes prompts from first beginning of line before330 BEG to END.331 341 Removes all but the last prompt of a sequence if that sequence ends at 332 342 END. 333 The region between BEG and END should be accessible." 334 (save-excursion 335 (let ((end (copy-marker end)) 336 prompt-end) 337 (goto-char beg) 338 (beginning-of-line) 339 (while (and (setq prompt-end 340 (re-search-forward singular-remove-prompt-regexp end t)) 341 (not (= end prompt-end))) 342 (delete-region (match-beginning 0) prompt-end)) 343 344 ;; check for trailing prompt 345 (if prompt-end 346 (delete-region (match-beginning 0) (match-beginning 2))) 347 (set-marker end nil)))) 343 The region between BEG and END should be accessible. 344 Leaves point after the last prompt found." 345 (let ((end (copy-marker end)) 346 prompt-end) 347 (goto-char beg) 348 (while (and (setq prompt-end 349 (re-search-forward singular-remove-prompt-regexp end t)) 350 (not (= end prompt-end))) 351 (delete-region (match-beginning 0) prompt-end)) 352 353 ;; check for trailing prompt 354 (if prompt-end 355 (delete-region (match-beginning 0) (match-beginning 2))) 356 (set-marker end nil))) 348 357 349 358 (defconst singular-skip-prompt-forward-regexp … … 355 364 (looking-at singular-skip-prompt-forward-regexp) 356 365 (goto-char (match-end 0))) 366 367 (defun singular-skip-prompt-backward () 368 "Skip backward over prompts." 369 (while (re-search-backward singular-extended-prompt-regexp (- (point) 2) t))) 357 370 ;;}}} 358 371 … … 416 429 initializes it to POS." 417 430 (make-local-variable 'singular-simple-sec-last-end) 418 (if (not (and (boundp 'singular-simple-sec-last-end) 419 singular-simple-sec-last-end)) 431 (if (not (markerp singular-simple-sec-last-end)) 420 432 (setq singular-simple-sec-last-end (make-marker))) 421 433 (set-marker singular-simple-sec-last-end pos)) … … 785 797 ;;}}} 786 798 799 ;;{{{ Last input and output section 800 (defun singular-last-input-section (&optional no-error) 801 "Return last input section. 802 Returns nil if optional argument NO-ERROR is non-nil and there is no 803 last input section defined, throws an error otherwise." 804 (let ((last-input-start (marker-position singular-last-input-section-start)) 805 (last-input-end (marker-position singular-current-output-section-start))) 806 (cond ((and last-input-start last-input-end) 807 (vector (singular-simple-sec-at last-input-start) 'input 808 last-input-start last-input-end)) 809 (no-error nil) 810 (t (error "No last input section defined"))))) 811 812 (defun singular-current-output-section (&optional no-error) 813 "Return current output section. 814 Returns nil if optional argument NO-ERROR is non-nil and there is no 815 current output section defined, throws an error otherwise." 816 (let ((current-output-start (marker-position singular-current-output-section-start)) 817 (current-output-end (save-excursion 818 (goto-char (singular-process-mark)) 819 (singular-skip-prompt-backward) 820 (and (bolp) (point))))) 821 (cond ((and current-output-start current-output-end) 822 (vector (singular-simple-sec-at current-output-start) 'output 823 current-output-start current-output-end)) 824 (no-error nil) 825 (t (error "No current output section defined"))))) 826 827 (defun singular-last-output-section (&optional no-error) 828 "Return last output section. 829 Returns nil if optional argument NO-ERROR is non-nil and there is no 830 last output section defined, throws an error otherwise." 831 (let ((last-output-start (marker-position singular-last-output-section-start)) 832 (last-output-end (marker-position singular-last-input-section-start))) 833 (cond ((and last-output-start last-output-end) 834 (vector (singular-simple-sec-at last-output-start) 'output 835 last-output-start last-output-end)) 836 (no-error nil) 837 (t (error "No last output section defined"))))) 838 839 (defun singular-latest-output-section (&optional no-error) 840 "Return latest output section. 841 This is the current output section if it is defined, otherwise the 842 last output section. 843 Returns nil if optional argument NO-ERROR is non-nil and there is no 844 latest output section defined, throws an error otherwise." 845 (or (singular-current-output-section t) 846 (singular-last-output-section t) 847 (if no-error 848 nil 849 (error "No latest output section defined")))) 850 ;;}}} 851 787 852 ;;{{{ Folding sections 788 853 (defvar singular-folding-ellipsis "Singular I/O ..." … … 808 873 809 874 (defun singular-fold-section (section) 810 " (Un)fold SECTION.811 (Un)folds section at point and goes to beginning of section if called875 "\(Un)fold SECTION. 876 \(Un)folds section at point and goes to beginning of section if called 812 877 interactively. 813 878 Unfolds folded sections and folds unfolded sections." … … 828 893 (singular-fold-internal start (singular-section-end section) 829 894 (not (singular-section-foldedp section)))) 895 ;; this is unwide-protected 830 896 (narrow-to-region old-point-min old-point-max) 831 897 (set-marker old-point-max nil)) … … 836 902 837 903 ;; debugging filters 838 (defun singular-debug- input-filter (string)839 " Echo STRINGin mini-buffer."904 (defun singular-debug-pre-input-filter (string) 905 "Display STRING and some markers in mini-buffer." 840 906 (singular-debug 'interactive-filter 841 (message "Input filter: %s" 842 (singular-debug-format string)))) 843 844 (defun singular-debug-output-filter (string) 845 "Echo STRING in mini-buffer." 907 (message "Pre-input filter: %s" 908 (singular-debug-format string))) 846 909 (singular-debug 'interactive-filter 847 (message "Output filter: %s" 848 (singular-debug-format string)))) 910 (message "Pre-input filter: (li %S ci %S lo %S co %S)" 911 (marker-position singular-last-input-section-start) 912 (marker-position singular-current-input-section-start) 913 (marker-position singular-last-output-section-start) 914 (marker-position singular-current-output-section-start))) 915 nil) 916 917 (defun singular-debug-post-input-filter (beg end) 918 "Display BEG, END, and some markers in mini-buffer." 919 (singular-debug 'interactive-filter 920 (message "Post-input filter: (beg %S end %S)" beg end)) 921 (singular-debug 'interactive-filter 922 (message "Post-input filter: (li %S ci %S lo %S co %S)" 923 (marker-position singular-last-input-section-start) 924 (marker-position singular-current-input-section-start) 925 (marker-position singular-last-output-section-start) 926 (marker-position singular-current-output-section-start)))) 927 928 (defun singular-debug-pre-output-filter (string) 929 "Display STRING and some markers in mini-buffer." 930 (singular-debug 'interactive-filter 931 (message "Pre-output filter: %s" 932 (singular-debug-format string))) 933 (singular-debug 'interactive-filter 934 (message "Pre-output filter: (li %S ci %S lo %S co %S)" 935 (marker-position singular-last-input-section-start) 936 (marker-position singular-current-input-section-start) 937 (marker-position singular-last-output-section-start) 938 (marker-position singular-current-output-section-start))) 939 nil) 940 941 (defun singular-debug-post-output-filter (beg end simple-sec-start) 942 "Display BEG, END, SIMPLE-SEC-START, and some markers in mini-buffer." 943 (singular-debug 'interactive-filter 944 (message "Post-output filter: (beg %S end %S sss %S)" 945 beg end simple-sec-start)) 946 (singular-debug 'interactive-filter 947 (message "Post-output filter: (li %S ci %S lo %S co %S)" 948 (marker-position singular-last-input-section-start) 949 (marker-position singular-current-input-section-start) 950 (marker-position singular-last-output-section-start) 951 (marker-position singular-current-output-section-start)))) 849 952 850 953 ;; stripping prompts 851 (defun singular-remove-prompt-filter ( &optional string)954 (defun singular-remove-prompt-filter (beg end simple-sec-start) 852 955 "Strip prompts from last simple section." 853 (singular-remove-prompt comint-last-output-start 854 (singular-process-mark))) 956 (if simple-sec-start (singular-remove-prompt simple-sec-start end))) 855 957 ;;}}} 856 958 … … 999 1101 ;;}}} 1000 1102 1001 ;;{{{ Sending input and receiving output 1002 1003 ;;{{{ Some lengthy notes on filters 1004 1005 ;; Note: 1006 ;; 1007 ;; The filters and other functions have access to four important markers, 1008 ;; `comint-last-input-start', `comint-last-input-end', 1009 ;; `comint-last-output-start', and the buffers process mark. They are 1010 ;; initialized to nil (except process mark, which is initialized to 1011 ;; `(point-max)') when Singular is called in `singular'. These markers are 1012 ;; modified by `comint-send-input' and `comint-output-filter' but not in a 1013 ;; quite reliable way. Here are some valid invariants and pre-/post- 1014 ;; conditions. 1015 ;; 1016 ;; Output filters: 1017 ;; --------------- 1018 ;; The output filters may be sure that they are run in the process buffer 1019 ;; and that the process buffer is still alive. `comint-output-filter' 1020 ;; ensures this. But `comint-output-filter' does neither catch changes in 1021 ;; match data done by the filters nor does it protect against non-local 1022 ;; exits of itself or of one of the filters. As a result, the current 1023 ;; buffer may be changed in `comint-output-filter'! 1024 ;; 1025 ;; `comint-output-filter' is called also from `comint-send-input' (dunno 1026 ;; why). The following holds only for executions of `comint-output-filter' 1027 ;; as a result of Singular output being processed. 1028 ;; 1029 ;; We have the following preconditions for any output filters (up to 1030 ;; changes through other filter functions): 1031 ;; - The argument STRING is what has been inserted in the buffer. Not 1032 ;; really reliable. 1033 ;; - `comint-last-input-end' <= `comint-last-output-start' <= process mark 1034 ;; if all of them are defined 1035 ;; - The text between `comint-last-output-start' and process mark is the 1036 ;; one which has been inserted immediately before. 1037 ;; - The text between `comint-last-input-end' (if it is defined) and 1038 ;; process mark is the one which has been inserted into buffer since last 1039 ;; user input. 1040 ;; - It seems to be a reasonable assumption that the text between process 1041 ;; mark and `(point-max)' is user input. 1042 ;; 1043 ;; The standard filters which come with comint.el do not change the markers 1044 ;; in the preconditions described above. But they may change the text 1045 ;; (e.g., `comint-strip-ctrl-m'). 1046 ;; 1047 ;; Post-conditions for `comint-output-filter': 1048 ;; - `comint-last-output-start' <= process mark. The region between them 1049 ;; is the text which has been inserted immediately before. 1050 ;; - `comint-last-input-start' and `comint-last-input-end' are unchanged. 1051 ;; 1052 ;; Input filters: 1053 ;; -------------- 1054 ;; `comint-send-input' ensures that the process is still alive. Further 1055 ;; preconditions for any input filter (up to changes through filter 1056 ;; functions): 1057 ;; - The (CR-terminated) argument STRING is what will be sent to the 1058 ;; process (up to slight differences between XEmacs and Emacs). Not 1059 ;; really reliable. 1060 ;; - process mark <= `(point)' 1061 ;; - The (CR-terminated) text between process mark and `(point)' is what 1062 ;; has been inserted by the user. 1063 ;; 1064 ;; Post-conditions for `comint-send-input': 1065 ;; - `comint-last-input-start' <= `comint-last-input-end' 1066 ;; = `comint-last-output-start' (!) 1067 ;; = process mark = `(point)'. 1068 ;; The region between the first of them is what has been inserted by the 1069 ;; user. 1070 ;; 1071 ;; Invariants which always hold outside `comint-send-input' and 1072 ;; `comint-output-filter': 1073 ;; ------------------------------------------------------------ 1074 ;; - `comint-last-input-start' <= `comint-last-input-end' <= process mark 1075 ;; if all of them are defined. The region between the first of them is 1076 ;; the last input entered by the user, the region between the latter of 1077 ;; them is the text from Singular printed since the last input. 1078 ;; - `comint-last-output-start' <= process mark if both are defined. 1079 ;; - It is a reasonable assumption that the text from process mark up to 1080 ;; `(point-max)' is user input. 1081 1082 ;;}}} 1083 1103 ;;{{{ Some lengthy notes on input and output 1104 1105 ;; NOT READY[so sorry]! 1106 1107 ;;}}} 1108 1109 ;;{{{ Sending input 1110 (defvar singular-pre-input-filter-functions nil 1111 "Functions to call before input is sent to process. 1112 These functions get one argument, a string containing the text which 1113 is to be sent to process. The functions should return either nil 1114 or a string. In the latter case the returned string replaces the 1115 string to be sent to process. 1116 1117 This is a buffer-local variable, not a buffer-local hook! 1118 1119 `singular-run-hook-with-arg-and-value' is used to run the functions in 1120 the list.") 1121 1122 (defvar singular-post-input-filter-functions nil 1123 "Functions to call after input is sent to process. 1124 These functions get two arguments BEG and END. 1125 If `singular-input-filter' has been called with a string as argument 1126 BEG and END gives the position of this string after insertion into the 1127 buffer. 1128 If `singular-input-filter' has been called with a position as argument 1129 BEG and END equal process mark and that position, resp. 1130 The functions may assume that no narrowing is in effect and may change 1131 point at will. 1132 1133 This hook is buffer-local.") 1134 1135 (defvar singular-current-input-section-start nil 1136 "Marker to the start of the current input section. 1137 This marker points nowhere on startup or if there is no current input 1138 section. 1139 1140 This variable is buffer-local.") 1141 1142 (defvar singular-last-input-section-start nil 1143 "Marker to the start of the last input section. 1144 This marker points nowhere on startup. 1145 1146 This variable is buffer-local.") 1147 1148 (defun singular-input-filter-init (pos) 1149 "Initialize all variables concerning input. 1150 POS is the position of the process mark." 1151 ;; localize variables not yet localized in `singular-interactive-mode' 1152 (make-local-variable 'singular-current-input-section-start) 1153 (make-local-variable 'singular-last-input-section-start) 1154 1155 ;; initialize markers 1156 (if (not (markerp singular-current-input-section-start)) 1157 (setq singular-current-input-section-start (make-marker))) 1158 (if (not (markerp singular-last-input-section-start)) 1159 (setq singular-last-input-section-start (make-marker)))) 1160 1161 (defun singular-send-string (process string) 1162 "Send newline terminated STRING to to process PROCESS. 1163 Runs the hooks on `singular-pre-input-filter-functions' in the buffer 1164 associated to PROCESS. The functions get the non-terminated string." 1165 (let ((process-buffer (process-buffer process))) 1166 1167 ;; check whether buffer is still alive 1168 (if (and process-buffer (buffer-name process-buffer)) 1169 (save-excursion 1170 (set-buffer process-buffer) 1171 (send-string 1172 process 1173 (concat (singular-run-hook-with-arg-and-value 1174 singular-pre-input-filter-functions string) 1175 "\n")))))) 1176 1177 (defun singular-input-filter (process string-or-pos) 1178 "Insert/update input from user in buffer associated to PROCESS. 1179 Inserts STRING-OR-POS followed by a newline at process mark if it is a 1180 string. 1181 Assumes that the input is already inserted and that it is placed 1182 between process mark and STRING-OR-POS if the latter is a position. 1183 Inserts a newline after STRING-OR-POS. 1184 1185 Takes care off: 1186 - current buffer as well as point and restriction in buffer associated 1187 with process, even against non-local exits. 1188 Updates: 1189 - process mark; 1190 - current and last sections; 1191 - simple sections; 1192 - mode line. 1193 1194 Runs the hooks on `singular-pre-input-filter-functions' and 1195 `singular-post-input-filter-functions'. 1196 1197 For a more detailed descriptions of the input filter, the markers it 1198 sets, and input filter functions refer to the section \"Some lengthy 1199 notes on input and output\" in singular.el." 1200 (let ((process-buffer (process-buffer process))) 1201 1202 ;; check whether buffer is still alive 1203 (if (and process-buffer (buffer-name process-buffer)) 1204 (let ((old-buffer (current-buffer)) 1205 (old-pmark (marker-position (process-mark process))) 1206 old-point old-point-min old-point-max) 1207 (unwind-protect 1208 (let (simple-sec-start) 1209 (set-buffer process-buffer) 1210 ;; the following lines are not protected since the 1211 ;; unwind-forms refer the variables being set here 1212 (setq old-point (point-marker) 1213 old-point-min (point-min-marker) 1214 old-point-max (point-max-marker) 1215 1216 ;; get end of last simple section (equals start of 1217 ;; current) 1218 simple-sec-start (marker-position singular-simple-sec-last-end)) 1219 1220 ;; prepare for insertion 1221 (widen) 1222 (set-marker-insertion-type old-point t) 1223 (set-marker-insertion-type old-point-max t) 1224 1225 ;; insert string at process mark and advance process 1226 ;; mark after insertion. If it not a string simply 1227 ;; jump to desired position and insrt a newline. 1228 (if (stringp string-or-pos) 1229 (progn 1230 (goto-char old-pmark) 1231 (insert string-or-pos)) 1232 (goto-char string-or-pos)) 1233 (insert ?\n) 1234 (set-marker (process-mark process) (point)) 1235 1236 ;; create new simple section and update section markers 1237 (cond 1238 ((eq (singular-simple-sec-create 'input (point)) 'empty) 1239 nil) 1240 ;; a new simple section has been created ... 1241 ((null (marker-position singular-current-input-section-start)) 1242 ;; ... and even a new input section has been created! 1243 (set-marker singular-current-input-section-start 1244 simple-sec-start) 1245 (set-marker singular-last-output-section-start 1246 singular-current-output-section-start) 1247 (set-marker singular-current-output-section-start nil))) 1248 1249 ;; run post-output hooks and force mode-line update 1250 (run-hook-with-args 'singular-post-input-filter-functions 1251 old-pmark (point))) 1252 1253 ;; restore buffer, restrictions and point 1254 (narrow-to-region old-point-min old-point-max) 1255 (set-marker old-point-min nil) 1256 (set-marker old-point-max nil) 1257 (goto-char old-point) 1258 (set-marker old-point nil) 1259 (set-buffer old-buffer)))))) 1260 1084 1261 (defun singular-get-old-input (get-section) 1085 1262 "Retrieve old input. … … 1101 1278 1102 1279 (defun singular-send-or-copy-input (send-full-section) 1103 "NOT READY!!" 1280 "Send input from current buffer to associated process. 1281 NOT READY[old input copying, demo mode, 1282 eol-on-send, history, SEND-FULL-SECTION]!" 1104 1283 (interactive "P") 1105 1284 … … 1120 1299 (< (point) pmark) 1121 1300 (let ((old-input (singular-get-old-input send-full-section))) 1122 (goto-char (point-max))1301 (goto-char pmark) 1123 1302 (insert old-input))) 1124 1303 1125 (;; send input from pmark to point 1304 (;; send input from pmark to point after doing history expansion 1126 1305 t 1127 ;; note that the input string does not include its terminal newline 1128 (let* ((raw-input (buffer-substring pmark (point))) 1129 (input raw-input) 1130 (history raw-input)) 1131 1132 ;; insert newline into buffer 1133 (insert ?\n) 1306 ;; go to desired position 1307 (if comint-eol-on-send (end-of-line)) 1308 (if send-full-section (goto-char (point-max))) 1309 1310 ;; do history expansion 1311 (if (eq comint-input-autoexpand 'input) 1312 (comint-replace-by-expanded-history t)) 1313 (let* ((input (buffer-substring pmark (point)))) 1134 1314 1135 1315 ;; insert input into history 1136 (if (and (funcall comint-input-filter history)1316 (if (and (funcall comint-input-filter input) 1137 1317 (or (null comint-input-ignoredups) 1138 1318 (not (ring-p comint-input-ring)) 1139 1319 (ring-empty-p comint-input-ring) 1140 (not (string-equal (ring-ref comint-input-ring 0) history)))) 1141 (ring-insert comint-input-ring history)) 1142 1143 ;; run hooks and reset index into history 1144 (run-hook-with-args 'comint-input-filter-functions (concat input "\n")) 1320 (not (string-equal (ring-ref comint-input-ring 0) input)))) 1321 (ring-insert comint-input-ring input)) 1145 1322 (setq comint-input-ring-index nil) 1146 1323 1147 ;; update markers and create a new simple section 1148 (set-marker comint-last-input-start pmark) 1149 (set-marker comint-last-input-end (point)) 1150 (set-marker (process-mark process) (point)) 1151 (singular-debug 'interactive-simple-secs 1152 (message "Simple input section: %S" 1153 (singular-simple-sec-create 'input (point))) 1154 (singular-simple-sec-create 'input (point))) 1155 1156 ;; do it !! 1157 (send-string process input) 1158 (send-string process "\n")))))) 1324 ;; send string to process ... 1325 (singular-send-string process input) 1326 ;; ... and insert it into buffer ... 1327 (singular-input-filter process (point))))))) 1328 ;;}}} 1329 1330 ;;{{{ Receiving output 1331 (defvar singular-pre-output-filter-functions nil 1332 "Functions to call before output is inserted into the buffer. 1333 These functions get one argument, a string containing the text sent 1334 from process. The functions should return either nil or a string. 1335 In the latter case the returned string replaces the string sent from 1336 process. 1337 1338 This is a buffer-local variable, not a buffer-local hook! 1339 1340 `singular-run-hook-with-arg-and-value' is used to run the functions in 1341 this list.") 1342 1343 (defvar singular-post-output-filter-functions nil 1344 "Functions to call after output is inserted into the buffer. 1345 These functions get three arguments BEG, END, and SIMPLE-SEC-START. 1346 The region between BEG and END is what has been inserted into the 1347 buffer. 1348 SIMPLE-SEC-START is the start of the simple section which has been 1349 created on insertion or nil if no simple section has been created. 1350 The functions may assume that no narrowing is in effect and may change 1351 point at will. 1352 1353 This hook is buffer-local.") 1354 1355 (defvar singular-current-output-section-start nil 1356 "Marker to the start of the current output section. 1357 This marker points nowhere on startup or if there is no current output 1358 section. 1359 1360 This variable is buffer-local.") 1361 1362 (defvar singular-last-output-section-start nil 1363 "Marker to the start of the last output section. 1364 This marker points nowhere on startup. 1365 1366 This variable is buffer-local.") 1367 1368 (defun singular-output-filter-init (pos) 1369 "Initialize all variables concerning output including process mark. 1370 Set process mark to POS." 1371 1372 ;; localize variables not yet localized in `singular-interactive-mode' 1373 (make-local-variable 'singular-current-output-section-start) 1374 (make-local-variable 'singular-last-output-section-start) 1375 1376 ;; initialize markers 1377 (if (not (markerp singular-current-output-section-start)) 1378 (setq singular-current-output-section-start (make-marker))) 1379 (if (not (markerp singular-last-output-section-start)) 1380 (setq singular-last-output-section-start (make-marker))) 1381 (set-marker (singular-process-mark) pos)) 1159 1382 1160 1383 (defun singular-output-filter (process string) 1161 1384 "Insert STRING containing output from PROCESS into its associated buffer. 1162 1163 1385 Takes care off: 1164 - current buffer, even in case of non-local exits; 1165 - point and restriction in buffer associated with process; 1166 - markers which should not be advanced when inserting output. 1386 - current buffer as well as point and restriction in buffer associated 1387 with process, even against non-local exits. 1167 1388 Updates: 1168 1389 - process mark; 1169 - `comint-last-output-start';1390 - current and last sections; 1170 1391 - simple sections; 1171 1392 - mode line. 1172 Runs the hooks on `comint-output-filter-functions'. 1393 Runs the hooks on `singular-pre-output-filter-functions' and 1394 `singular-post-output-filter-functions'. 1173 1395 1174 1396 For a more detailed descriptions of the output filter, the markers it 1175 1397 sets, and output filter functions refer to the section \"Some lengthy 1176 notes on filters\" in singular.el." 1177 (let ((process-buffer (process-buffer process)) 1178 (old-buffer (current-buffer))) 1398 notes on input and output\" in singular.el." 1399 (let ((process-buffer (process-buffer process))) 1179 1400 1180 1401 ;; check whether buffer is still alive 1181 1402 (if (and process-buffer (buffer-name process-buffer)) 1182 (unwind-protect 1183 (progn 1184 (set-buffer process-buffer) 1185 (let ((old-point (point)) 1186 (old-point-min (point-min)) 1187 (old-point-max (point-max)) 1188 (old-pmark (marker-position (process-mark process))) 1189 (n (length string))) 1403 (let ((old-buffer (current-buffer)) 1404 (old-pmark (marker-position (process-mark process))) 1405 old-point old-point-min old-point-max) 1406 (unwind-protect 1407 (let (simple-sec-start) 1408 (set-buffer process-buffer) 1409 ;; the following lines are not protected since the 1410 ;; unwind-forms refer the variables being set here 1411 (setq old-point (point-marker) 1412 old-point-min (point-min-marker) 1413 old-point-max (point-max-marker) 1414 1415 ;; get end of last simple section (equals start of 1416 ;; current) 1417 simple-sec-start (marker-position singular-simple-sec-last-end) 1418 1419 ;; get string to insert 1420 string (singular-run-hook-with-arg-and-value 1421 singular-pre-output-filter-functions 1422 string)) 1423 1424 ;; prepare for insertion 1190 1425 (widen) 1426 (set-marker-insertion-type old-point t) 1427 (set-marker-insertion-type old-point-max t) 1428 1429 ;; insert string at process mark and advance process 1430 ;; mark after insertion 1191 1431 (goto-char old-pmark) 1192 1193 ;; adjust point and narrowed region borders 1194 (if (<= (point) old-point) (setq old-point (+ old-point n))) 1195 (if (< (point) old-point-min) (setq old-point-min (+ old-point-min n))) 1196 (if (<= (point) old-point-max) (setq old-point-max (+ old-point-max n))) 1197 1198 ;; do it !! 1199 (insert-before-markers string) 1200 1201 ;; reset markers and simple sections which may have 1202 ;; been advanced by above insertion. We rely on the 1203 ;; fact that `set-marker' always returns some non-nil 1204 ;; value. Looks nicer this way. 1205 (and (= comint-last-input-end (point)) 1206 (set-marker comint-last-input-end old-pmark) 1207 ;; this may happen only on startup and only if 1208 ;; `comint-last-input-end' has been modified, 1209 ;; too. Hence, we check for it after the first 1210 ;; test. 1211 (= comint-last-input-start (point)) 1212 (set-marker comint-last-input-start old-pmark)) 1213 (and (= singular-simple-sec-last-end (point)) 1214 (singular-simple-sec-reset-last old-pmark)) 1215 1216 ;; set new markers and create/extend new simple section 1217 (set-marker comint-last-output-start old-pmark) 1218 (singular-debug 'interactive-simple-secs 1219 (message "Simple output section: %S" 1220 (singular-simple-sec-create 'output (point))) 1221 (singular-simple-sec-create 'output (point))) 1222 1223 ;; restore old values, run hooks, and force mode line update 1224 (narrow-to-region old-point-min old-point-max) 1225 (goto-char old-point) 1226 (run-hook-with-args 'comint-output-filter-functions string) 1227 (force-mode-line-update))) 1228 1229 ;; this is unwind-protected 1230 (set-buffer old-buffer))))) 1432 (insert string) 1433 (set-marker (process-mark process) (point)) 1434 1435 ;; create new simple section and update section markers 1436 (cond 1437 ((eq (singular-simple-sec-create 'output (point)) 'empty) 1438 (setq simple-sec-start nil)) 1439 ;; a new simple section has been created ... 1440 ((null (marker-position singular-current-output-section-start)) 1441 ;; ... and even a new output section has been created! 1442 (set-marker singular-current-output-section-start 1443 simple-sec-start) 1444 (set-marker singular-last-input-section-start 1445 singular-current-input-section-start) 1446 (set-marker singular-current-input-section-start nil))) 1447 1448 ;; run post-output hooks and force mode-line update 1449 (run-hook-with-args 'singular-post-output-filter-functions 1450 old-pmark (point) simple-sec-start) 1451 (force-mode-line-update)) 1452 1453 ;; restore buffer, restrictions and point 1454 (narrow-to-region old-point-min old-point-max) 1455 (set-marker old-point-min nil) 1456 (set-marker old-point-max nil) 1457 (goto-char old-point) 1458 (set-marker old-point nil) 1459 (set-buffer old-buffer)))))) 1231 1460 ;;}}} 1232 1461 … … 1238 1467 1239 1468 NOT READY [multiple Singulars]! 1240 1241 Singular buffers are automatically limited in length \(by default, to1242 2048 lines). This limit may be adjusted by setting1243 `singular-buffer-maximum-size' before Singular interactive mode starts1244 up or by setting `comint-buffer-maximum-size' while Singular1245 interactive mode is running.1246 1469 1247 1470 \\{singular-interactive-mode-map} … … 1269 1492 (setq comint-input-ring-size singular-input-ring-size) 1270 1493 (setq comint-input-filter singular-history-filter) 1271 ;; do not add `comint-truncate-buffer' if it already has been added1272 ;; globally. This is sort of a bug in `add-hook'.1273 (and (default-boundp 'comint-output-filter-functions)1274 (not (memq 'comint-truncate-buffer1275 (default-value 'comint-output-filter-functions)))1276 (add-hook 'comint-output-filter-functions1277 'comint-truncate-buffer nil t))1278 1494 1279 1495 ;; get name of history file (if any) … … 1284 1500 (setq comint-input-ring-file-name nil)) 1285 1501 1286 ;; initialize singular demo mode 1502 ;; initialize singular demo mode, input and output filters 1287 1503 (singular-demo-mode 'init) 1504 (make-local-variable 'singular-pre-input-filter-functions) 1505 (make-local-hook 'singular-post-input-filter-functions) 1506 (make-local-variable 'singular-pre-output-filter-functions) 1507 (make-local-hook 'singular-post-output-filter-functions) 1288 1508 1289 1509 ;; selective display … … 1301 1521 (set-glyph-image invisible-text-glyph singular-folding-ellipsis (current-buffer)))) 1302 1522 1303 ;; input and outputfilters1523 ;; debugging filters 1304 1524 (singular-debug 'interactive-filter 1305 (add-hook ' comint-input-filter-functions1306 'singular-debug- input-filter nil t))1525 (add-hook 'singular-pre-input-filter-functions 1526 'singular-debug-pre-input-filter nil t)) 1307 1527 (singular-debug 'interactive-filter 1308 (add-hook 'comint-output-filter-functions 1309 'singular-debug-output-filter nil t)) 1310 (add-hook 'comint-output-filter-functions 1528 (add-hook 'singular-post-input-filter-functions 1529 'singular-debug-post-input-filter nil t)) 1530 (singular-debug 'interactive-filter 1531 (add-hook 'singular-pre-output-filter-functions 1532 'singular-debug-pre-output-filter nil t)) 1533 (singular-debug 'interactive-filter 1534 (add-hook 'singular-post-output-filter-functions 1535 'singular-debug-post-output-filter nil t)) 1536 1537 ;; other input or output filters 1538 (add-hook 'singular-post-output-filter-functions 1311 1539 'singular-remove-prompt-filter nil t) 1312 1540 … … 1382 1610 (setq comint-ptyp process-connection-type) ; T if pty, NIL if pipe. 1383 1611 1384 ;; go to the end of the buffer, set up markers, and1385 ;; initialize simplesections1612 ;; go to the end of the buffer, initialize I/O and simple 1613 ;; sections 1386 1614 (goto-char (point-max)) 1387 (set-marker comint-last-input-start (point)) 1388 (set-marker comint-last-input-end (point)) 1389 (set-marker comint-last-output-start (point)) 1390 (set-marker (process-mark process) (point)) 1615 (singular-input-filter-init (point)) 1616 (singular-output-filter-init (point)) 1391 1617 (singular-simple-sec-init (point)) 1392 1618
Note: See TracChangeset
for help on using the changeset viewer.