Changeset 6d68ac in git for emacs/singular.el


Ignore:
Timestamp:
Jul 23, 1998, 5:57:22 PM (26 years ago)
Author:
Jens Schmidt <schmidt@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
a8575b6ce6d56b755805426e91fb43845420eed8
Parents:
ebb5ccfea178e26b049143e1488ef2c1ca730545
Message:
	* singular.el (singular): initializes the markers
	  `comint-last-input-start', `comint-last-input-end', and
	  `comint-last-output-start'
	  (singular): goes to point max after Singular startup

	* singular.el (singular-interactive-mode):
	  `comint-truncate-buffer' is not longer added unconditionally to
	  `comint-output-filter-functions'
	  (singular): runs `comint-exec' instead of `make-comint'

	* singular.el (comint-mode): advice removed
	  (singular-interactive-mode): `comint-mode' is called now in a
	  more regular way

	* singular.el (singular-debug-output-filter): doc fix


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

Legend:

Unmodified
Added
Removed
  • emacs/singular.el

    rebb5ccf r6d68ac  
    11;;; singular.el --- Emacs support for Computer Algebra System Singular
    22
    3 ;; $Id: singular.el,v 1.4 1998-07-23 08:38:08 schmidt Exp $
     3;; $Id: singular.el,v 1.5 1998-07-23 15:57:22 schmidt Exp $
    44
    55;;; Commentary:
     
    235235
    236236;;{{{ Input and output filters
     237
     238;;{{{ Some lengthy notes on filters
     239
     240;; Note:
     241;;
     242;; The filters and other functions have access to four important markers,
     243;; `comint-last-input-start', `comint-last-input-end',
     244;; `comint-last-output-start', and the buffers process mark.  They are
     245;; initialized to nil (except process mark, which is initialized to
     246;; `(point-max)') when Singular is called in `singular'.  These markers are
     247;; modified by `comint-send-input' and `comint-output-filter' but not in a
     248;; quite reliable way.  Here are some valid invariants and pre-/post-
     249;; conditions.
     250;;
     251;; Output filters:
     252;; ---------------
     253;; The output filters may be sure that they are run in the process buffer
     254;; and that the process buffer is still alive.  `comint-output-filter'
     255;; ensures this.  But `comint-output-filter' does neither catch changes in
     256;; match data done by the filters nor does it protect against non-local
     257;; exits of itself or of one of the filters.  As a result, the current
     258;; buffer may be changed in `comint-output-filter'!
     259;;
     260;; `comint-output-filter' is called also from `comint-send-input' (dunno
     261;; why).  The following holds only for executions of `comint-output-filter'
     262;; as a result of Singular output being processed.
     263;;
     264;; We have the following preconditions for any output filters (up to
     265;; changes through other filter functions):
     266;; - The argument STRING is what has been inserted in the buffer.  Not
     267;;   really reliable.
     268;; - `comint-last-input-end' <= `comint-last-output-start' <= process mark
     269;;   if all of them are defined
     270;; - The text between `comint-last-output-start' and process mark is the
     271;;   one which has been inserted immediately before.
     272;; - The text between `comint-last-input-end' (if it is defined) and
     273;;   process mark is the one which has been inserted into buffer since last
     274;;   user input.
     275;; - It seems to be a reasonable assumption that the text between process
     276;;   mark and `(point-max)' is user input.
     277;;
     278;; The standard filters which come with comint.el do not change the markers
     279;; in the preconditions described above.  But they may change the text
     280;; (e.g., `comint-strip-ctrl-m').
     281;;
     282;; Post-conditions for `comint-output-filter':
     283;; - `comint-last-output-start' <= process mark.  The region between them
     284;;   is the text which has been inserted immediately before.
     285;; - `comint-last-input-start' and `comint-last-input-end' are unchanged.
     286;;
     287;; Input filters:
     288;; --------------
     289;; `comint-send-input' ensures that the process is still alive.  Further
     290;; preconditions for any input filter (up to changes through filter
     291;; functions):
     292;; - The (CR-terminated) argument STRING is what will be sent to the
     293;;   process (up to slight differences between XEmacs and Emacs).  Not
     294;;   really reliable.
     295;; - process mark <= `(point)'
     296;; - The (CR-terminated) text between process mark and `(point)' is what
     297;;   has been inserted by the user.
     298;;
     299;; Post-conditions for `comint-send-input':
     300;; - `comint-last-input-start' <= `comint-last-input-end'
     301;;                              = `comint-last-output-start' (!)
     302;;                              = process marker = `(point)'.
     303;;   The region between the first of them is what has been inserted by the
     304;;   user.
     305;;
     306;; Invariants which always hold outside `comint-send-input' and
     307;; `comint-output-filter':
     308;; ------------------------------------------------------------
     309;; - `comint-last-input-start' <= `comint-last-input-end' <= process mark
     310;;   if all of them are defined.  The region between the first of them is
     311;;   the last input entered by the user, the region between the latter of
     312;;   them is the text from Singular printed since the last input.
     313;; - `comint-last-output-start' <= process mark if both are defined.
     314;; - It is a reasonable assumption that the text from process mark up to
     315;;   `(point-max)' is user input.
     316
     317;;}}}
     318
    237319(defconst singular-bogus-output-filter-calls
    238320  (cond
     
    258340(defun singular-debug-output-filter (string)
    259341  "Echo STRING and `singular-debug-bogus-output-filter-cnt'.
    260 Decrement "
     342Decrement `singular-debug-bogus-output-filter-cnt' until it becomes zero."
    261343  (if (zerop singular-debug-bogus-output-filter-cnt)
    262344      (message "Output filter (real): %s"
     
    276358;; `singular-interactive-mode' every time a new Singular process is
    277359;; started, but only when a new buffer is created.  This behaviour seems
    278 ;; more intuitive w.r.t. local variables and hooks.  So far so good.
    279 ;;
    280 ;; But there is a slight problem: `make-comint' runs `comint-mode'
    281 ;; every time it creates a new process and overwrites a few but
    282 ;; important major-mode related variables.  Another consequence of
    283 ;; `comint-mode' being run more than once is that buffer-local
    284 ;; variables that are not declared to be permanent local are killed by
    285 ;; `comint-mode'.  Last not least, there is allmost no difference
    286 ;; between the `comint-mode-hook' and the `comint-exec-hook' since
    287 ;; both are run every time Singular starts up.
    288 ;;
    289 ;; The best solution seemed to define an advice to `comint-mode' which
    290 ;; inhibits its execution if `singular-interactive-mode' is already
    291 ;; up.
    292 
    293 (defadvice comint-mode (around singular-interactive-mode activate)
    294   "Do not run `comint-mode' if `singular-interactive-mode' is already up."
    295   (if (not (eq major-mode 'singular-interactive-mode))
    296       ad-do-it))
    297  
     360;; more intuitive w.r.t. local variables and hooks.
     361
    298362(defun singular-interactive-mode ()
    299363  "Major mode for interacting with Singular.
     
    319383  (interactive)
    320384
    321   ;; run comint mode and do basic mode setup.  The `let' around
    322   ;; `comint-mode' ensures that `comint-mode' really will be run.  See
    323   ;; the above advice.
    324   (let (major-mode) (comint-mode))
     385  ;; run comint mode and do basic mode setup
     386  (comint-mode)
    325387  (setq major-mode 'singular-interactive-mode)
    326388  (setq mode-name "Singular Interaction")
     
    335397  (setq comint-input-ring-size singular-input-ring-size)
    336398  (setq comint-input-filter singular-history-filter)
    337   (add-hook 'comint-output-filter-functions
    338             'comint-truncate-buffer nil t)
     399  ;; do not add `comint-truncate-buffer' if it already has been added
     400  ;; globally.  This is sort of a bug in `add-hook'.
     401  (and (default-boundp 'comint-output-filter-functions)
     402       (not (memq 'comint-truncate-buffer
     403                  (default-value 'comint-output-filter-functions)))
     404       (add-hook 'comint-output-filter-functions
     405                 'comint-truncate-buffer nil t))
    339406
    340407  ;; get name of history file (if any)
     
    423490                                singular-default-switches))
    424491
     492         (buffer-name (singular-process-name-to-buffer-name singular-name))
    425493         ;; buffer associated with Singular, nil if there is none
    426          (buffer-name (singular-process-name-to-buffer-name singular-name))
    427494         (buffer (get-buffer buffer-name)))
    428495
     
    440507    (if (not (comint-check-proc buffer))
    441508        (progn
     509          ;; initialize markers.  process-marker is initialized by
     510          ;; `comint-exec'.
     511          (set-marker comint-last-input-start nil)
     512          (set-marker comint-last-input-end nil)
     513          (set-marker comint-last-output-start nil)
     514
     515          ;; note that `comint-exec' may result in some process output already!
     516          ;; Note furthermore that we use `comint-exec' instead of
     517          ;; `make-comint' to avoid double calls of `comint-mode'.
    442518          (singular-debug 'interactive (message "Starting new Singular"))
    443           (setq buffer (apply 'make-comint singular-name singular-executable
    444                               (if (file-exists-p singular-start-file) singular-start-file)
    445                               singular-switches))
     519          (setq buffer (funcall 'comint-exec buffer singular-name singular-executable
     520                                (if (file-exists-p singular-start-file) singular-start-file)
     521                                singular-switches))
    446522          (set-process-sentinel (get-buffer-process buffer) 'singular-exit-sentinel)
    447523          (set-buffer buffer)
    448524          (singular-debug 'interactive (message "Reading input ring"))
    449525          (comint-read-input-ring t)
     526
     527          ;; go to end of buffer and run hooks
     528          (goto-char (point-max))
    450529          (run-hooks 'singular-exec-hook)))
    451530
Note: See TracChangeset for help on using the changeset viewer.