Changeset 81da6ba in git


Ignore:
Timestamp:
Jul 31, 1998, 11:05:53 PM (26 years ago)
Author:
Jens Schmidt <schmidt@…>
Branches:
(u'spielwiese', '17f1d200f27c5bd38f5dfc6e8a0879242279d1d8')
Children:
1e301581f50efc59aa3df4bf54ca5119abd10448
Parents:
8c4d791b0134ec4b991923ab17351f17c74f3187
Message:
	* singular.el: input/output completely rewritten.  Keine Zeit
	  mehr, Omlett wird fertig!!

	* singular.el (singular-pre-input-filter-functions,
	  singular-post-input-filter-functions,
	  singular-pre-output-filter-functions,
	  singular-post-output-filter-functions): new local variables
	  resp. hooks.  Localizations added.

	* singular.el (singular-last-input-section,
	  singular-last-output-section, singular-current-output-section,
	  singular-latest-output-section):  new functions

	* singular.el (singular-input-filter-init,
	  singular-output-filter-init): new functions
	  (singular-exec): calls new I/O initialization instead of old one

	* singular.el (singular-interactive-mode): all references to
	  `comint-input-filter-functions'
	  resp. `comint-output-filter-functions' replaced by there
	  corresponding singular specific hooks
	  (singular-interactive-mode): `comint-truncate-lines' removed
	  from `comint-output-filter-functions'

	* singular.el (singular-debug-post-output-filter,
	  singular-debug-pre-output-filter,
	  singular-debug-post-output-filter,
	  singular-debug-pre-output-filter):  new functions.  Added to the
	  respective hooks.
	  (singular-debug-input-filter, singular-debug-output-filter):
	  functions removed.  Removed from the respective hooks.

	* singular.el (singular-remove-prompt): does not save point.  Does
	  not jump to beginning of line.
	  (singular-remove-prompt-filter): adapted to new calling
	  conventions.  Uses SIMPLE-SEC-START to determine whether removal
	  is necessary.

	* singular.el (singular-simple-sec-init): initialization slightly
	  changed
	  (singular-run-hook-with-arg-and-value): new function
	  (singular-debug): checks for `t' instead of `all'
	  (singular-fold-section): doc fix
	  (singular-extended-prompt-regexp): `"?"' as prompt character
	  added
	  (singular-skip-prompt-backward): new function


git-svn-id: file:///usr/local/Singular/svn/trunk@2422 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • emacs/singular.el

    r8c4d79 r81da6ba  
    11;;; singular.el --- Emacs support for Computer Algebra System Singular
    22
    3 ;; $Id: singular.el,v 1.15 1998-07-31 08:18:30 schmidt Exp $
     3;; $Id: singular.el,v 1.16 1998-07-31 21:05:53 schmidt Exp $
    44
    55;;; Commentary:
     
    7474(defmacro singular-debug (mode form &optional else-form)
    7575  "Major debugging hook for singular.el.
    76 Evaluates FORM if `singular-debug' equals `all' or if MODE is an
    77 element of `singular-debug', othwerwise ELSE-FORM"
    78   `(if (or (eq singular-debug 'all)
     76Evaluates FORM if `singular-debug' equals t or if MODE is an element
     77of `singular-debug', othwerwise ELSE-FORM."
     78  `(if (or (eq singular-debug t)
    7979           (memq ,mode singular-debug))
    8080       ,form
     
    213213The buffer name is the process name with surrounding `*'."
    214214  (concat "*" process-name "*"))
     215
     216(defun singular-run-hook-with-arg-and-value (hook value)
     217  "Call functions on HOOK.
     218Provides argument VALUE.  If a function returns a non-nil value it
     219replaces VALUE as new argument to the functions.  Returns final
     220VALUE."
     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))
    215227
    216228(defmacro singular-process ()
     
    305317    (substring string beg end)))
    306318
    307 (defconst singular-extended-prompt-regexp "\\([>.] \\)"
     319(defconst singular-extended-prompt-regexp "\\([?>.] \\)"
    308320  "Matches one Singular prompt.
    309321Should not be anchored neither to start nor to end!")
     
    327339(defun singular-remove-prompt (beg end)
    328340  "Remove all superfluous prompts from region between BEG and END.
    329 More precisely, removes prompts from first beginning of line before
    330 BEG to END.
    331341Removes all but the last prompt of a sequence if that sequence ends at
    332342END.
    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))))
     343The region between BEG and END should be accessible.
     344Leaves 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)))
    348357
    349358(defconst singular-skip-prompt-forward-regexp
     
    355364  (looking-at singular-skip-prompt-forward-regexp)
    356365  (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)))
    357370;;}}}
    358371
     
    416429initializes it to POS."
    417430  (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))
    420432      (setq singular-simple-sec-last-end (make-marker)))
    421433  (set-marker singular-simple-sec-last-end pos))
     
    785797;;}}}
    786798
     799;;{{{ Last input and output section
     800(defun singular-last-input-section (&optional no-error)
     801  "Return last input section.
     802Returns nil if optional argument NO-ERROR is non-nil and there is no
     803last 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.
     814Returns nil if optional argument NO-ERROR is non-nil and there is no
     815current 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.
     829Returns nil if optional argument NO-ERROR is non-nil and there is no
     830last 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.
     841This is the current output section if it is defined, otherwise the
     842last output section.
     843Returns nil if optional argument NO-ERROR is non-nil and there is no
     844latest 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
    787852;;{{{ Folding sections
    788853(defvar singular-folding-ellipsis "Singular I/O ..."
     
    808873
    809874(defun singular-fold-section (section)
    810   "(Un)fold SECTION.
    811 (Un)folds section at point and goes to beginning of section if called
     875  "\(Un)fold SECTION.
     876\(Un)folds section at point and goes to beginning of section if called
    812877interactively.
    813878Unfolds folded sections and folds unfolded sections."
     
    828893          (singular-fold-internal start (singular-section-end section)
    829894                                  (not (singular-section-foldedp section))))
     895      ;; this is unwide-protected
    830896      (narrow-to-region old-point-min old-point-max)
    831897      (set-marker old-point-max nil))
     
    836902
    837903;; debugging filters
    838 (defun singular-debug-input-filter (string)
    839   "Echo STRING in mini-buffer."
     904(defun singular-debug-pre-input-filter (string)
     905  "Display STRING and some markers in mini-buffer."
    840906  (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)))
    846909  (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))))
    849952
    850953;; stripping prompts
    851 (defun singular-remove-prompt-filter (&optional string)
     954(defun singular-remove-prompt-filter (beg end simple-sec-start)
    852955  "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)))
    855957;;}}}
    856958
     
    9991101;;}}}
    10001102     
    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.
     1112These functions get one argument, a string containing the text which
     1113is to be sent to process.  The functions should return either nil
     1114or a string.  In the latter case the returned string replaces the
     1115string to be sent to process.
     1116
     1117This 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
     1120the list.")
     1121
     1122(defvar singular-post-input-filter-functions nil
     1123  "Functions to call after input is sent to process.
     1124These functions get two arguments BEG and END.
     1125If `singular-input-filter' has been called with a string as argument
     1126BEG and END gives the position of this string after insertion into the
     1127buffer.
     1128If `singular-input-filter' has been called with a position as argument
     1129BEG and END equal process mark and that position, resp.
     1130The functions may assume that no narrowing is in effect and may change
     1131point at will.
     1132
     1133This hook is buffer-local.")
     1134
     1135(defvar singular-current-input-section-start nil
     1136  "Marker to the start of the current input section.
     1137This marker points nowhere on startup or if there is no current input
     1138section.
     1139
     1140This variable is buffer-local.")
     1141
     1142(defvar singular-last-input-section-start nil
     1143  "Marker to the start of the last input section.
     1144This marker points nowhere on startup.
     1145
     1146This variable is buffer-local.")
     1147
     1148(defun singular-input-filter-init (pos)
     1149  "Initialize all variables concerning input.
     1150POS 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.
     1163Runs the hooks on `singular-pre-input-filter-functions' in the buffer
     1164associated 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.
     1179Inserts STRING-OR-POS followed by a newline at process mark if it is a
     1180string.
     1181Assumes that the input is already inserted and that it is placed
     1182between process mark and STRING-OR-POS if the latter is a position.
     1183Inserts a newline after STRING-OR-POS.
     1184
     1185Takes care off:
     1186- current buffer as well as point and restriction in buffer associated
     1187  with process, even against non-local exits.
     1188Updates:
     1189- process mark;
     1190- current and last sections;
     1191- simple sections;
     1192- mode line.
     1193
     1194Runs the hooks on `singular-pre-input-filter-functions' and
     1195`singular-post-input-filter-functions'.
     1196
     1197For a more detailed descriptions of the input filter, the markers it
     1198sets, and input filter functions refer to the section \"Some lengthy
     1199notes 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           
    10841261(defun singular-get-old-input (get-section)
    10851262  "Retrieve old input.
     
    11011278
    11021279(defun singular-send-or-copy-input (send-full-section)
    1103   "NOT READY!!"
     1280  "Send input from current buffer to associated process.
     1281NOT READY[old input copying, demo mode,
     1282          eol-on-send, history, SEND-FULL-SECTION]!"
    11041283  (interactive "P")
    11051284
     
    11201299      (< (point) pmark)
    11211300      (let ((old-input (singular-get-old-input send-full-section)))
    1122         (goto-char (point-max))
     1301        (goto-char pmark)
    11231302        (insert old-input)))
    11241303
    1125      (;; send input from pmark to point
     1304     (;; send input from pmark to point after doing history expansion
    11261305      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))))
    11341314
    11351315        ;; insert input into history
    1136         (if (and (funcall comint-input-filter history)
     1316        (if (and (funcall comint-input-filter input)
    11371317                 (or (null comint-input-ignoredups)
    11381318                     (not (ring-p comint-input-ring))
    11391319                     (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))
    11451322        (setq comint-input-ring-index nil)
    11461323
    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.
     1333These functions get one argument, a string containing the text sent
     1334from process.  The functions should return either nil or a string.
     1335In the latter case the returned string replaces the string sent from
     1336process.
     1337
     1338This 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
     1341this list.")
     1342
     1343(defvar singular-post-output-filter-functions nil
     1344  "Functions to call after output is inserted into the buffer.
     1345These functions get three arguments BEG, END, and SIMPLE-SEC-START.
     1346The region between BEG and END is what has been inserted into the
     1347buffer.
     1348SIMPLE-SEC-START is the start of the simple section which has been
     1349created on insertion or nil if no simple section has been created.
     1350The functions may assume that no narrowing is in effect and may change
     1351point at will.
     1352
     1353This hook is buffer-local.")
     1354
     1355(defvar singular-current-output-section-start nil
     1356  "Marker to the start of the current output section.
     1357This marker points nowhere on startup or if there is no current output
     1358section.
     1359
     1360This variable is buffer-local.")
     1361
     1362(defvar singular-last-output-section-start nil
     1363  "Marker to the start of the last output section.
     1364This marker points nowhere on startup.
     1365
     1366This variable is buffer-local.")
     1367
     1368(defun singular-output-filter-init (pos)
     1369  "Initialize all variables concerning output including process mark.
     1370Set 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))
    11591382
    11601383(defun singular-output-filter (process string)
    11611384  "Insert STRING containing output from PROCESS into its associated buffer.
    1162 
    11631385Takes 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.
    11671388Updates:
    11681389- process mark;
    1169 - `comint-last-output-start';
     1390- current and last sections;
    11701391- simple sections;
    11711392- mode line.
    1172 Runs the hooks on `comint-output-filter-functions'.
     1393Runs the hooks on `singular-pre-output-filter-functions' and
     1394`singular-post-output-filter-functions'.
    11731395
    11741396For a more detailed descriptions of the output filter, the markers it
    11751397sets, 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)))
     1398notes on input and output\" in singular.el."
     1399  (let ((process-buffer (process-buffer process)))
    11791400
    11801401    ;; check whether buffer is still alive
    11811402    (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
    11901425                (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
    11911431                (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))))))
    12311460;;}}}
    12321461
     
    12381467
    12391468NOT READY [multiple Singulars]!
    1240 
    1241 Singular buffers are automatically limited in length \(by default, to
    1242 2048 lines).  This limit may be adjusted by setting
    1243 `singular-buffer-maximum-size' before Singular interactive mode starts
    1244 up or by setting `comint-buffer-maximum-size' while Singular
    1245 interactive mode is running.
    12461469
    12471470\\{singular-interactive-mode-map}
     
    12691492  (setq comint-input-ring-size singular-input-ring-size)
    12701493  (setq comint-input-filter singular-history-filter)
    1271   ;; do not add `comint-truncate-buffer' if it already has been added
    1272   ;; globally.  This is sort of a bug in `add-hook'.
    1273   (and (default-boundp 'comint-output-filter-functions)
    1274        (not (memq 'comint-truncate-buffer
    1275                   (default-value 'comint-output-filter-functions)))
    1276        (add-hook 'comint-output-filter-functions
    1277                  'comint-truncate-buffer nil t))
    12781494
    12791495  ;; get name of history file (if any)
     
    12841500      (setq comint-input-ring-file-name nil))
    12851501
    1286   ;; initialize singular demo mode
     1502  ;; initialize singular demo mode, input and output filters
    12871503  (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)
    12881508
    12891509  ;; selective display
     
    13011521    (set-glyph-image invisible-text-glyph singular-folding-ellipsis (current-buffer))))
    13021522
    1303   ;; input and output filters
     1523  ;; debugging filters
    13041524  (singular-debug 'interactive-filter
    1305                   (add-hook 'comint-input-filter-functions
    1306                             'singular-debug-input-filter nil t))
     1525                  (add-hook 'singular-pre-input-filter-functions
     1526                            'singular-debug-pre-input-filter nil t))
    13071527  (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
    13111539            'singular-remove-prompt-filter nil t)
    13121540
     
    13821610            (setq comint-ptyp process-connection-type) ; T if pty, NIL if pipe.
    13831611
    1384             ;; go to the end of the buffer, set up markers, and
    1385             ;; initialize simple sections
     1612            ;; go to the end of the buffer, initialize I/O and simple
     1613            ;; sections
    13861614            (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))
    13911617            (singular-simple-sec-init (point))
    13921618
Note: See TracChangeset for help on using the changeset viewer.