Changeset 1735b4e in git for emacs


Ignore:
Timestamp:
Jul 23, 1998, 10:38:08 AM (26 years ago)
Author:
Jens Schmidt <schmidt@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
f7ac05f40537c46c4f7c55dd263035e13f651e01
Parents:
1135fd63a8c300daf52527692ee2c9ba30e88965
Message:
	* singular.el (singular-bogus-output-filter-calls): new variable

	* singular.el (singular-interactive-mode-map): code for XEmacs
	  added

	* singular.el (singular-emacs-flavor,
	  singular-emacs-major-version, singular-emacs-minor-version): new
 	  variables
	  (singular-set-version, singular-fset): new functions

	* singular.el (singular-debug-format): new function
	  (singular-debug-bogus-output-filter-cnt): new variable
	  (singular-debug-input-filter, singular-debug-output-filter): new
	  variables
	  (singular-interactive-mode): conditionally adds debugging
	  filters

	* singular.el: style and coding conventions added


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

Legend:

Unmodified
Added
Removed
  • emacs/singular.el

    r1135fd6 r1735b4e  
    11;;; singular.el --- Emacs support for Computer Algebra System Singular
    22
    3 ;; $Id: singular.el,v 1.3 1998-07-22 15:09:34 schmidt Exp $
     3;; $Id: singular.el,v 1.4 1998-07-23 08:38:08 schmidt Exp $
    44
    55;;; Commentary:
     
    99;;; Code:
    1010
     11;;{{{ Style and coding conventions
     12
     13;; Style and coding conventions:
     14;;
     15;; - "Singular" is written with an upper-case `S' in comments, doc
     16;;   strings, and messages.  As part of symbols, it is written with
     17;;   a lower-case `s'.
     18;; - use a `fill-column' of 70 for doc strings and comments
     19;; - use foldings to structure the source code but try not to exceed a
     20;;   maximal depth of two folding (one folding in another folding which is
     21;;   on top-level)
     22;; - use lowercase folding titles except for first word
     23;; - folding-marks are `;;{{{' and `;;}}}' resp., for sake of standard
     24;;   conformity
     25;;
     26;; - use `singular' as prefix for all global symbols
     27;; - use `singular-debug' as prefix for all global symbols concerning
     28;;   debugging.
     29;;
     30;; - mark dependencies on Emacs flavor/version with a comment of the form
     31;;   `;; Emacs[ version]' resp.  `;; XEmacs[ version]'
     32;; - use a `cond' statement to execute Emacs flavor/version-dependent code,
     33;;   not `if'.  This is to make such checks more extensible.
     34;; - try to define different functions for different flavors/version
     35;;   and use `singular-fset' at library-loading time to set the function
     36;;   you really need.  If the function is named `singular-<basename>', the
     37;;   flavor/version-dependent functions should be named
     38;;   `singular-<flavor>[-<version>]-<basename>'.
     39
     40;; - use `singular-debug' for debugging output/actions
     41;; - to switch between buffer and process names, use the functions
     42;;   `singular-process-name-to-buffer-name' and
     43;;   `singular-buffer-name-to-process-name'
     44
     45;;}}}
     46
    1147(require 'comint)
    1248
    13 ;;{{{ Code Common to Both Modes
    14 ;;{{{ Debugging Stuff
     49;;{{{ Code common to both modes
     50;;{{{ Debugging stuff
    1551(defvar singular-debug nil
    1652  "*List of modes to debug or `all' to debug all modes.
    1753Currently, only the mode `interactive' is supported.")
     54
     55(defun singular-debug-format (string)
     56  "Return STRING in a nicer format."
     57
     58  ;; is there any better way to replace in strings??
     59  (while (string-match "\n" string)
     60    (setq string (concat (substring string 0 (match-beginning 0))
     61                         "^J"
     62                         (substring string (match-end 0)))))
     63
     64  (if (> (length string) 16)
     65      (concat "<" (substring string 0 7) ">...<" (substring string -8) ">")
     66    (concat "<" string ">")))
    1867
    1968(defmacro singular-debug (mode form)
     
    2574       ,form))
    2675;;}}}
    27 ;;}}}
    28 
    29 ;;{{{ Singular Interactive Mode
    30 ;;{{{ Key Map
     76
     77;;{{{ Determining version
     78(defvar singular-emacs-flavor nil
     79  "A symbol describing the current Emacs.
     80Currently, only Emacs \(`emacs') and XEmacs are supported \(`xemacs').")
     81
     82(defvar singular-emacs-major-version nil
     83  "An integer describing the major version of the current emacs.")
     84
     85(defvar singular-emacs-minor-version nil
     86  "An integer describing the major version of the current emacs.")
     87
     88(defun singular-fset (real-function emacs-function xemacs-function
     89                                    &optional emacs-19-function)
     90  "Set REAL-FUNCTION to one of the functions, in dependency on Emacs flavor and version.
     91Sets REAL-FUNCTION to XEMACS-FUNCTION if `singular-emacs-flavor' is
     92`xemacs'.  Sets REAL-FUNCTION to EMACS-FUNCTION if `singular-emacs-flavor'
     93is `emacs' and `singular-emacs-major-version' is 20.  Otherwise, sets
     94REAL-FUNCTION to EMACS-19-FUNCTION which defaults to EMACS-FUNCTION.
     95
     96This is not as common as would be desirable.  But it is sufficient so far."
     97  (cond
     98   ;; XEmacs
     99   ((eq singular-emacs-flavor 'xemacs)
     100    (fset real-function xemacs-function))
     101   ;; Emacs 20
     102   ((eq singular-emacs-major-version 20)
     103    (fset real-function emacs-function))
     104   ;; Emacs 19
     105   (t
     106    (fset real-function (or emacs-19-function emacs-function)))))
     107
     108(defun singular-set-version ()
     109  "Determine flavor, major version, and minor version of current emacs.
     110singular.el is guaranteed to run on Emacs 19.34, Emacs 20.2, and XEmacs
     11120.2.  It should run on newer version and on slightly older ones, too."
     112
     113  ;; get major and minor versions first
     114  (if (and (boundp 'emacs-major-version)
     115           (boundp 'emacs-minor-version))
     116      (setq singular-emacs-major-version emacs-major-version
     117            singular-emacs-minor-version emacs-minor-version)
     118    (with-output-to-temp-buffer "*singular warnings*"
     119      (princ
     120"You seem to have quite an old Emacs or XEmacs version.  Some of the
     121features from singular.el will not work properly.  Consider upgrading to a
     122more recent version of Emaxs or XEmacs.  singular.el is guaranteed to run
     123on Emacs 19.34, Emacs 20.2, and XEmacs 20.2."))
     124    ;; assume the oldest version we support
     125    (setq singular-emacs-major-version 19
     126          singular-emacs-minor-version 34))
     127
     128  ;; get flavor
     129  (if (string-match "XEmacs\\|Lucid" emacs-version)
     130      (setq singular-emacs-flavor 'xemacs)
     131    (setq singular-emacs-flavor 'emacs)))
     132
     133(singular-set-version)
     134;;}}}
     135;;}}}
     136
     137;;{{{ Singular interactive mode
     138;;{{{ Key map
    31139(defvar singular-interactive-mode-map ()
    32140  "Key map to use in Singular interactive mode.")
    33141
    34 (if singular-interactive-mode-map
    35     ()
    36   (setq singular-interactive-mode-map
    37         (nconc (make-sparse-keymap) comint-mode-map)))
     142(if (not singular-interactive-mode-map)
     143    (cond
     144     ;; Emacs
     145     ((eq singular-emacs-flavor 'emacs)
     146      (setq singular-interactive-mode-map
     147            (nconc (make-sparse-keymap) comint-mode-map)))
     148     ;; XEmacs
     149     (t
     150      (setq singular-interactive-mode-map (make-keymap))
     151      (set-keymap-parents singular-interactive-mode-map (list comint-mode-map))
     152      (set-keymap-name singular-interactive-mode-map
     153                       'singular-interactive-mode-map))))
    38154;;}}}
    39155
     
    58174;;}}}
    59175 
    60 ;;{{{ Customization Variables of comint
     176;;{{{ Customizing variables of comint
    61177
    62178;; Note:
     
    118234;;}}}
    119235
    120 ;;{{{ Singular Interactive Mode
     236;;{{{ Input and output filters
     237(defconst singular-bogus-output-filter-calls
     238  (cond
     239   ;; XEmacs
     240   ((eq singular-emacs-flavor 'xemacs) 2)
     241   ;; Emacs
     242   (t 1))
     243  "Number of bogus runs of hooks on `comint-output-filter-functions'.")
     244
     245;; debugging filters
     246(defvar singular-debug-bogus-output-filter-cnt 0
     247  "Number of bogus runs of hooks on `comint-output-filter-functions' yet to do.
     248This variable is set to `singular-bogus-output-filter-calls' in
     249`singular-debug-input-filter' and decremented for each bogus run of
     250`singular-debug-output-filter' until it becomes zero.")
     251
     252(defun singular-debug-input-filter (string)
     253  "Echo STRING and reset `singular-debug-bogus-output-filter-cnt'."
     254  (message "Input filter: %s" (singular-debug-format string))
     255  (setq singular-debug-bogus-output-filter-cnt
     256        singular-bogus-output-filter-calls))
     257
     258(defun singular-debug-output-filter (string)
     259  "Echo STRING and `singular-debug-bogus-output-filter-cnt'.
     260Decrement "
     261  (if (zerop singular-debug-bogus-output-filter-cnt)
     262      (message "Output filter (real): %s"
     263               (singular-debug-format string))
     264    (message "Output filter (bogus %d): %s"
     265             singular-debug-bogus-output-filter-cnt
     266             (singular-debug-format string))
     267    (setq singular-debug-bogus-output-filter-cnt
     268          (1- singular-debug-bogus-output-filter-cnt))))
     269;;}}}
     270
     271;;{{{ Singular interactive mode
    121272
    122273;; Note:
     
    194345      (setq comint-input-ring-file-name nil))
    195346
     347  ;; marking of input and output
     348  (singular-debug 'interactive-filter
     349                  (add-hook 'comint-input-filter-functions
     350                            'singular-debug-input-filter nil t))
     351  (singular-debug 'interactive-filter
     352                  (add-hook 'comint-output-filter-functions
     353                            'singular-debug-output-filter nil t))
     354
    196355  (run-hooks 'singular-interactive-mode-hook))
    197356;;}}}
    198357
    199 ;;{{{ Starting Singular
     358;;{{{ Starting singular
    200359(defvar singular-start-file "~/.emacs_singularrc"
    201360  "Name of start-up file to pass to Singular.
Note: See TracChangeset for help on using the changeset viewer.