Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Diff of /sml/trunk/sml-mode/sml-proc.el
ViewVC logotype

Diff of /sml/trunk/sml-mode/sml-proc.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 39, Sat Mar 14 04:41:37 1998 UTC revision 394, Mon Aug 9 21:45:51 1999 UTC
# Line 1  Line 1 
1  ;;; sml-proc.el. Comint based interaction mode for Standard ML.  ;;; sml-proc.el. Comint based interaction mode for Standard ML.
2    
3    (defconst rcsid-sml-proc "@(#)$Name$:$Id$")
4    
5  ;; Copyright (C) 1989, Lars Bo Nielsen, 1994,1997 Matthew J. Morley  ;; Copyright (C) 1989, Lars Bo Nielsen, 1994,1997 Matthew J. Morley
6    
7  ;; $Revision$  ;; $Revision$
# Line 36  Line 38 
38  ;; Inferior-sml-mode is for interacting with an ML process run under  ;; Inferior-sml-mode is for interacting with an ML process run under
39  ;; emacs. This uses the comint package so you get history, expansion,  ;; emacs. This uses the comint package so you get history, expansion,
40  ;; backup and all the other benefits of comint. Interaction is  ;; backup and all the other benefits of comint. Interaction is
41  ;; achieved by M-x sml which starts a sub-process under emacs. You may  ;; achieved by M-x run-sml which starts a sub-process under emacs. You may
42  ;; need to set this up for autoloading in your .emacs:  ;; need to set this up for autoloading in your .emacs:
43    
44  ;; (autoload 'sml "sml-proc" "Run an inferior ML process." t)  ;; (autoload 'run-sml "sml-proc" "Run an inferior ML process." t)
45    
46  ;; Exactly what process is governed by the variable sml-program-name  ;; Exactly what process is governed by the variable sml-program-name
47  ;; -- just "sml" by default. If you give a prefix argument (C-u M-x  ;; -- just "sml" by default. If you give a prefix argument (C-u M-x
48  ;; sml) you will be prompted for a different program to execute from  ;; run-sml) you will be prompted for a different program to execute from
49  ;; the default -- if you just hit RETURN you get the default anyway --  ;; the default -- if you just hit RETURN you get the default anyway --
50  ;; along with the option to specify any command line arguments. Once  ;; along with the option to specify any command line arguments. Once
51  ;; you select the ML program name in this manner, it remains the  ;; you select the ML program name in this manner, it remains the
# Line 64  Line 66 
66  ;; region of text to the ML process, etc. Given a prefix argument to  ;; region of text to the ML process, etc. Given a prefix argument to
67  ;; these commands will switch you from the SML buffer to the ML  ;; these commands will switch you from the SML buffer to the ML
68  ;; process buffer as well as sending the text. If you get errors  ;; process buffer as well as sending the text. If you get errors
69  ;; reported by the compiler, C-c ` (sml-next-error) will step through  ;; reported by the compiler, C-x ` (next-error) will step through
70  ;; the errors with you.  ;; the errors with you.
71    
72  ;; NOTE. There is only limited support for this as it obviously  ;; NOTE. There is only limited support for this as it obviously
73  ;; depends on the compiler's error messages being recognised by the  ;; depends on the compiler's error messages being recognised by the
74  ;; mode. Error reporting is currently only geared up for SML/NJ,  ;; mode. Error reporting is currently only geared up for SML/NJ,
75  ;; Moscow ML, and Poly/ML (see file sml-{mosml,poly-ml}.el). Look at  ;; Moscow ML, and Poly/ML.  For other compilers, add the relevant
76  ;; the documentation for sml-error-parser and sml-next-error -- you  ;; regexp to sml-error-regexp-alist and send it to me.
77  ;; may only need to modify the former to recover this feature for some  
78  ;; other ML systems, along with sml-error-regexp.  ;; To send pieces of code to the underlying compiler, we never send the text
79    ;; directly but use a temporary file instead.  This breaks if the compiler
80  ;; While small pieces of text can be fed quite happily into the ML  ;; does not understand `use', but has the benefit of allowing better error
81  ;; process directly, lager pieces should (probably) be sent via a  ;; reporting.
 ;; temporary file making use of the compiler's "use" command.  
   
 ;; CURRENT RATIONALE: you get sense out of the error messages if  
 ;; there's a real file associated with a block of code, and XEmacs is  
 ;; less likely to hang. These are likely to change.  
   
 ;; For more information see the variable sml-temp-threshold. You  
 ;; should set the variable sml-use-command appropriately for your ML  
 ;; compiler. By default things are set up to work for the SML/NJ  
 ;; compiler.  
   
 ;;; FOR YOUR .EMACS  
   
 ;; Here  are some ideas for inferior-sml-*-hooks:  
   
 ;; (setq inferior-sml-load-hook  
 ;;       '(lambda() "Set global defaults for inferior-sml-mode"  
 ;;          (define-key inferior-sml-mode-map "\C-cd"    'sml-cd)  
 ;;          (define-key          sml-mode-map "\C-cd"    'sml-cd)  
 ;;          (define-key          sml-mode-map "\C-c\C-f" 'sml-send-function)  
 ;;          (setq sml-temp-threshold 0))) ; safe: always use tmp file  
   
 ;; (setq inferior-sml-mode-hook  
 ;;       '(lambda() "Inferior SML mode defaults"  
 ;;          (setq comint-scroll-show-maximum-output t  
 ;;                comint-scroll-to-bottom-on-output t  
 ;;                comint-input-autoexpand nil)))  
82    
83  ;; ===================================================================  ;; ===================================================================
84    
85  ;;; INFERIOR ML MODE VARIABLES  ;;; INFERIOR ML MODE VARIABLES
86    
87  (require 'sml-mode)  (require 'sml-mode)
88    (require 'sml-util)
89  (require 'comint)  (require 'comint)
90  (provide 'sml-proc)  (require 'compile)
91    
92  (defvar sml-program-name "sml"  (defgroup sml-proc ()
93    "*Program to run as ML.")    "Interacting with an SML process."
94      :group 'sml)
95    
96    (defcustom sml-program-name "sml"
97      "*Program to run as ML."
98      :group 'sml-proc
99      :type '(string))
100    
101    (defcustom sml-default-arg ""
102      "*Default command line option to pass, if any."
103      :group 'sml-proc
104      :type '(string))
105    
106  (defvar sml-default-arg ""  (defvar sml-compile-command "CM.make()"
   "*Default command line option to pass, if any.")  
   
 (defvar sml-make-command "CM.make()"  
107    "The command used by default by `sml-make'.")    "The command used by default by `sml-make'.")
108    
109  (defvar sml-make-file-name "sources.cm"  (defvar sml-make-file-name "sources.cm"
# Line 128  Line 112 
112  ;;(defvar sml-raise-on-error nil  ;;(defvar sml-raise-on-error nil
113  ;;  "*When non-nil, `sml-next-error' will raise the ML process's frame.")  ;;  "*When non-nil, `sml-next-error' will raise the ML process's frame.")
114    
 (defvar sml-temp-threshold 0  
   "*Controls when emacs uses temporary files to communicate with ML.  
 If not a number (e.g., NIL), then emacs always sends text directly to  
 the subprocess. If an integer N, then emacs uses a temporary file  
 whenever the text is longer than N chars. `sml-temp-file' contains the  
 name of the temporary file for communicating. See variable  
 `sml-use-command' and function `sml-send-region'.  
   
 Sending regions directly through the pty (not using temp files)  
 doesn't work very well -- e.g., SML/NJ nor Poly/ML incorrectly report  
 the line # of errors occurring in std_in.")  
   
 (defvar sml-temp-file  
   (make-temp-name  
    (concat (file-name-as-directory (or (getenv "TMPDIR") "/tmp")) "/ml"))  
   "*Temp file that emacs uses to communicate with the ML process.  
 See `sml-temp-threshold'. Defaults to \(make-temp-name \"/tmp/ml\"\)")  
   
115  (defvar inferior-sml-mode-hook nil  (defvar inferior-sml-mode-hook nil
116    "*This hook is run when the inferior ML process is started.    "*This hook is run when the inferior ML process is started.
117  All buffer local customisations for the interaction buffers go here.")  All buffer local customisations for the interaction buffers go here.")
# Line 154  Line 120 
120    "*Hook run when inferior-sml-mode (sml-proc.el) is loaded into Emacs.    "*Hook run when inferior-sml-mode (sml-proc.el) is loaded into Emacs.
121  This is a good place to put your preferred key bindings.")  This is a good place to put your preferred key bindings.")
122    
123    (defvar sml-error-overlay nil
124      "*Non-nil means use an overlay to highlight errorful code in the buffer.
125    The actual value is the name of a face to use for the overlay.
126    Instead of setting this variable to 'region, you can also simply keep
127    it NIL and use (transient-mark-mode) which will provide similar
128    benefits (but with several side effects).")
129    
130  (defvar sml-buffer nil  (defvar sml-buffer nil
131    "*The current ML process buffer.    "*The current ML process buffer.
132    
# Line 211  Line 184 
184  The format specifier \"%s\" will be converted into the directory name  The format specifier \"%s\" will be converted into the directory name
185  specified when running the command \\[sml-cd].")  specified when running the command \\[sml-cd].")
186    
187  (defvar sml-prompt-regexp "^[\-=] *"  (defcustom sml-prompt-regexp "^[-=>#] *"
188    "*Regexp used to recognise prompts in the inferior ML process.")    "*Regexp used to recognise prompts in the inferior ML process."
189      :group 'sml-proc
190  (defvar sml-error-parser 'sml-smlnj-error-parser    :type '(regexp))
191    "*This function parses an error message into a 3-5 element list:  
192    (defconst sml-error-regexp-alist
193      \(file start-line start-col end-line-col err-msg\).    '(;; Poly/ML messages
194        ("\\(Error\\|Warning:\\) in '\\(.+\\)', line \\([0-9]+\\)" 2 3)
195  The first three components are required by `sml-next-error', but the other      ;; Moscow ML
196  two are optional. If the file associated with the input is the standard      ("File \"\\([^\"]+\\)\", line \\([0-9]+\\)\\(-\\([0-9]+\\)\\)?, characters \\([0-9]+\\)-\\([0-9]+\\):" 1 2 5)
197  input stream, this function should probably return      ;; SML/NJ:  the file-pattern is anchored to avoid
198        ;; pathological behavior with very long lines.
199      \(\"std_in\" start-line start-col\).      ("^[-= ]*\\(.+\\):\\([0-9]+\\)\\.\\([0-9]+\\)\\(-\\([0-9]+\\)\\.\\([0-9]+\\)\\)? \\(Error\\|Warning\\): .*" 1 sml-make-error 2 3 5 6)
200        ;; SML/NJ's exceptions:  see above.
201  This function will be called in a context in which the match data \(see      ("^ +\\(raised at: \\)?\\(.+\\):\\([0-9]+\\)\\.\\([0-9]+\\)\\(-\\([0-9]+\\)\\.\\([0-9]+\\)\\)" 2 sml-make-error 3 4 6 7)))
 `match-data'\) are current for `sml-error-regexp'. The mode sets the  
 default value to the function `sml-smlnj-error-parser'.  
   
 In a step towards greater sml-mode modularity END-LINE-COL can be either  
   
   - the symbol nil \(in which case it is ignored\)  
   
 or  
   
   - an Emacs Lisp expression that when `eval'd at \(start-line,start-col\)  
     will move point to the end of the errorful text in the file.  
   
 Note that the compiler should return the full path name of the errorful  
 file, and that this might require you to fiddle with the compiler's  
 prettyprinting switches.")  
   
 ;; std_in:2.1-4.3 Error: operator and operand don't agree (tycon mismatch)  
 ;; std_in:2.1 Error: operator and operand don't agree (tycon mismatch)  
   
 (defconst sml-smlnj-error-regexp  
   (concat  
    "^[-= ]*\\(.+\\):"                     ;file name  
    "\\([0-9]+\\)\\.\\([0-9]+\\)"          ;start line.column  
    "\\(-\\([0-9]+\\)\\.\\([0-9]+\\)\\)?"  ;end line.colum  
    ".+\\(\\(Error\\|Warning\\): .*\\)")   ;the message  
   
   "Default regexp matching SML/NJ error and warning messages.  
   
 There should be no need to customise this, though you might decide  
 that you aren't interested in Warnings -- my advice would be to modify  
 `sml-error-regexp' explicitly to do that though.  
   
 If you do customise `sml-smlnj-error-regexp' you may need to modify  
 the function `sml-smlnj-error-parser' (qv).")  
   
 (defvar sml-error-regexp sml-smlnj-error-regexp  
   "*Regexp for matching \(the start of\) an error message.")  
202    
203  ;; font-lock support  ;; font-lock support
204  (defvar inferior-sml-font-lock-keywords  (defconst inferior-sml-font-lock-keywords
205    `((,(concat "\\(" sml-prompt-regexp "\\)\\(.*\\)")    `(;; prompt and following interactive command
206        (,(concat "\\(" sml-prompt-regexp "\\)\\(.*\\)")
207       (1 font-lock-prompt-face)       (1 font-lock-prompt-face)
208       (2 font-lock-command-face keep))       (2 font-lock-command-face keep))
209      (,sml-error-regexp . font-lock-warning-face)      ;; CM's messages
210      ("^\\[\\(.*GC #.*\n\\)*.*\\]" . font-lock-comment-face)      ("^\\[\\(.*GC #.*\n\\)*.*\\]" . font-lock-comment-face)
211      ("^GC #.*" . font-lock-comment-face)))      ;; SML/NJ's irritating GC messages
212        ("^GC #.*" . font-lock-comment-face)
213  ;; default faces values      ;; error messages
214  (defvar font-lock-prompt-face      ,@(mapcar (lambda (ra) (cons (car ra) 'font-lock-warning-face))
215    (if (facep 'font-lock-prompt-face)                sml-error-regexp-alist))
216        'font-lock-prompt-face    "Font-locking specification for inferior SML mode.")
217      'font-lock-keyword-face))  
218  (defvar font-lock-command-face  (defface font-lock-prompt-face
219    (if (facep 'font-lock-command-face)    '((t (:bold t)))
220        'font-lock-command-face    "Font Lock mode face used to highlight prompts."
221      'font-lock-function-name-face))    :group 'font-lock-highlighting-faces)
222    (defvar font-lock-prompt-face 'font-lock-prompt-face
223      "Face name to use for prompts.")
224    
225    (defface font-lock-command-face
226      '((t (:bold t)))
227      "Font Lock mode face used to highlight interactive commands."
228      :group 'font-lock-highlighting-faces)
229    (defvar font-lock-command-face 'font-lock-command-face
230      "Face name to use for interactive commands.")
231    
232  (defvar inferior-sml-font-lock-defaults  (defconst inferior-sml-font-lock-defaults
233    '(inferior-sml-font-lock-keywords nil nil nil nil))    '(inferior-sml-font-lock-keywords nil nil nil nil))
234    
 (defun sml-smlnj-error-parser (pt)  
  "This parses the SML/NJ error message at PT into a 5 element list  
   
     \(file start-line start-col end-of-err msg\)  
   
 where FILE is the file in which the error occurs\; START-LINE is the line  
 number in the file where the error occurs\; START-COL is the character  
 position on that line where the error occurs.  
   
 If present, the fourth return value is a simple Emacs Lisp expression that  
 will move point to the end of the errorful text, assuming that point is at  
 \(start-line,start-col\) to begin with\; and MSG is the text of the error  
 message given by the compiler."  
   
  ;; This function uses `sml-smlnj-error-regexp' to do the parsing, and  
  ;; assumes that regexp groups 1, 2, and 3 correspond to the first three  
  ;; elements of the list returned\; and groups 5, 6 and 7 correspond to the  
  ;; optional elements in that order.  
   
  (save-excursion  
    (goto-char pt)  
    (if (not (looking-at sml-smlnj-error-regexp))  
        ;; the user loses big time.  
        (list nil nil nil)  
      (let ((file (match-string 1))                  ; the file  
            (slin (string-to-int (match-string 2)))  ; the start line  
            (scol (string-to-int (match-string 3)))  ; the start col  
            (msg (if (match-beginning 7) (match-string 7))))  
        ;; another loss: buggy sml/nj's produce nonsense like file:0.0 Error  
        (if (zerop slin) (list file nil scol)  
          ;; ok, was a range of characters mentioned?  
          (if (match-beginning 4)  
              ;; assume m-b 4 implies m-b 5 and m-b 6 (sml-smlnj-error-regexp)  
              (let* ((elin (string-to-int (match-string 5))) ; end line  
                     (ecol (string-to-int (match-string 6))) ; end col  
                     (jump (if (= elin slin)  
                               ;; move forward on the same line  
                               `(forward-char ,(1+ (- ecol scol)))  
                             ;; otherwise move down, and over to ecol  
                             `(progn  
                                (forward-line ,(- elin slin))  
                                (forward-char ,ecol)))))  
                ;; nconc glues lists together. jump & msg aren't lists  
                (nconc (list file slin scol) (list jump) (list msg)))  
            (nconc (list file slin scol) (list nil) (list msg))))))))  
   
 (defun sml-smlnj (pfx)  
    "Set up and run Standard ML of New Jersey.  
 Prefix argument means accept the defaults below.  
   
 Note: defaults set here will be clobbered if you setq them in the  
 inferior-sml-mode-hook.  
   
  sml-program-name  <option> \(default \"sml\"\)  
  sml-default-arg   <option> \(default \"\"\)  
  sml-use-command   \"use \\\"%s\\\"\"  
  sml-cd-command    \"OS.FileSys.chDir \\\"%s\\\"\"  
  sml-prompt-regexp \"^[\\-=] *\"  
  sml-error-regexp  sml-sml-nj-error-regexp  
  sml-error-parser  'sml-sml-nj-error-parser"  
    (interactive "P")  
    (let ((cmd (if pfx "sml"  
                 (read-string "Command name: " sml-program-name)))  
          (arg (if pfx ""  
                 (read-string "Any arguments or options (default none): "))))  
      ;; sml-mode global variables  
      (setq sml-program-name cmd)  
      (setq sml-default-arg  arg)  
      ;; buffer-local (compiler-local) variables  
      (setq-default sml-use-command   "use \"%s\""  
                    sml-cd-command    "OS.FileSys.chDir \"%s\""  
                    sml-prompt-regexp "^[\-=] *"  
                    sml-error-regexp  sml-smlnj-error-regexp  
                    sml-error-parser  'sml-smlnj-error-parser)  
      (sml-run cmd sml-default-arg)))  
   
   
235  ;;; CODE  ;;; CODE
236    
237  (defvar inferior-sml-mode-map nil)  (defmap inferior-sml-mode-map
238      '(("\C-c\C-s" . run-sml)
239        ("\t"       . comint-dynamic-complete))
240      "Keymap for inferior-sml mode"
241      :inherit (list sml-bindings comint-mode-map)
242      :group 'sml-proc)
243    
244    
245  ;; buffer-local  ;; buffer-local
246    
247  (defvar sml-error-file nil)             ; file from which the last error came  (defvar sml-temp-file nil)
248  (defvar sml-real-file nil)              ; used for finding source errors  ;;(defvar sml-error-file nil)             ; file from which the last error came
249  (defvar sml-error-cursor nil)           ;   ditto  (defvar sml-error-cursor nil)           ;   ditto
 (defvar sml-error-barrier nil)          ;   ditto  
250    
251  (defun sml-proc-buffer ()  (defun sml-proc-buffer ()
252    "Returns the current ML process buffer,    "Returns the current ML process buffer,
253  or the current buffer if it is in `inferior-sml-mode'. Raises an error  or the current buffer if it is in `inferior-sml-mode'. Raises an error
254  if the variable `sml-buffer' does not appear to point to an existing  if the variable `sml-buffer' does not appear to point to an existing
255  buffer."  buffer."
256    (let ((buffer    (or (and (eq major-mode 'inferior-sml-mode) (current-buffer))
257           (cond ((eq major-mode 'inferior-sml-mode)        (and sml-buffer
258                  ;; default to current buffer if it's in inferior-sml-mode             (let ((buf (get-buffer sml-buffer)))
                 (current-buffer))  
                ((bufferp sml-buffer)  
259                 ;; buffer-name returns nil if the buffer has been killed                 ;; buffer-name returns nil if the buffer has been killed
260                  (buffer-name sml-buffer))               (and buf (buffer-name buf) buf)))
261                 ((stringp sml-buffer)        ;; no buffer found, make a new one
262                  ;; get-buffer returns nil if there's no buffer of that name        (run-sml t)))
                 (get-buffer sml-buffer)))))  
     (or buffer  
         (error "No current process buffer. See variable sml-buffer"))))  
263    
264  (defun sml-proc ()  (defun sml-proc ()
265    "Returns the current ML process. See variable `sml-buffer'."    "Returns the current ML process. See variable `sml-buffer'."
266    (let ((proc (get-buffer-process (sml-proc-buffer))))    (assert (eq major-mode 'inferior-sml-mode))
267      (or proc    (or (get-buffer-process (current-buffer))
268          (error "No current process. See variable sml-buffer"))))        (progn (run-sml t) (get-buffer-process (current-buffer)))))
269    
270  (defun sml-buffer (echo)  (defun sml-buffer (echo)
271    "Make the current buffer the current `sml-buffer' if that is sensible.    "Make the current buffer the current `sml-buffer' if that is sensible.
272  Lookup variable `sml-buffer' to see why this might be useful."  Lookup variable `sml-buffer' to see why this might be useful."
273    (interactive "P")    (interactive "P")
274    (let ((current    (when (and (not echo) (eq major-mode 'inferior-sml-mode))
275           (cond ((bufferp sml-buffer) (or (buffer-name sml-buffer) "undefined"))      (setq sml-buffer (current-buffer)))
276                 ((stringp sml-buffer) sml-buffer)    (message "ML process buffer is %s."
277                 (t "undefined"))))             (or (ignore-errors (buffer-name (get-buffer sml-buffer)))
278    (if echo (message (format "ML process buffer is %s." current))                 "undefined")))
     (let ((buffer (if (eq major-mode 'inferior-sml-mode) (current-buffer))))  
       (if (not buffer) (message (format "ML process buffer is %s." current))  
         (setq sml-buffer buffer)  
         (message (format "ML process buffer is %s." (buffer-name buffer))))))))  
   
 (defun sml-noproc ()  
   "Nil iff `sml-proc' returns a process."  
   (condition-case nil (progn (sml-proc) nil) (error t)))  
   
 (defun sml-proc-tidy ()  
   "Something to add to `kill-emacs-hook' to tidy up tmp files on exit."  
   (if (file-readable-p sml-temp-file)  
       (delete-file sml-temp-file)))  
279    
280  (defun inferior-sml-mode ()  (defun inferior-sml-mode ()
281    "Major mode for interacting with an inferior ML process.    "Major mode for interacting with an inferior ML process.
# Line 446  Line 302 
302  `sml-prompt-regexp' (default \"^[\\-=] *\")  `sml-prompt-regexp' (default \"^[\\-=] *\")
303      Regexp used to recognise prompts in the inferior ML process.      Regexp used to recognise prompts in the inferior ML process.
304    
 `sml-temp-threshold' (default 0)  
     Controls when emacs uses temporary files to communicate with ML.  
     If an integer N, then emacs uses a temporary file whenever the  
     text is longer than N chars.  
   
 `sml-temp-file' (default (make-temp-name \"/tmp/ml\"))  
     Temp file that emacs uses to communicate with the ML process.  
   
 `sml-error-regexp'  
    (default -- complicated)  
     Regexp for matching error messages from the compiler.  
   
 `sml-error-parser' (default 'sml-smlnj-error-parser)  
     This function parses a error messages into a 3, 4 or 5 element list:  
     (file start-line start-col (end-line end-col) err-msg).  
   
305  You can send text to the inferior ML process from other buffers containing  You can send text to the inferior ML process from other buffers containing
306  ML source.  ML source.
307      `switch-to-sml' switches the current buffer to the ML process buffer.      `switch-to-sml' switches the current buffer to the ML process buffer.
# Line 488  Line 328 
328    (sml-mode-variables)    (sml-mode-variables)
329    
330    ;; For sequencing through error messages:    ;; For sequencing through error messages:
331      (set (make-local-variable 'sml-error-cursor) (point-max-marker))
332    (set (make-local-variable 'sml-error-cursor)    (set-marker-insertion-type sml-error-cursor nil)
        (marker-position (point-max-marker)))  
   (set (make-local-variable 'sml-error-barrier)  
        (marker-position (point-max-marker)))  
   (set (make-local-variable 'sml-real-file) (cons nil 0))  
333    (set (make-local-variable 'font-lock-defaults)    (set (make-local-variable 'font-lock-defaults)
334         inferior-sml-font-lock-defaults)         inferior-sml-font-lock-defaults)
335    
336    (make-local-variable 'sml-use-command)    ;; compilation support (used for next-error)
337    (make-local-variable 'sml-cd-command)    (set (make-local-variable 'compilation-error-regexp-alist)
338    (make-local-variable 'sml-prompt-regexp)         sml-error-regexp-alist)
339    (make-local-variable 'sml-error-parser)    (compilation-shell-minor-mode 1)
340    (make-local-variable 'sml-error-regexp)    ;; I'm sure people might kill me for that
341      (setq compilation-error-screen-columns nil)
342      (make-local-variable 'sml-endof-error-alist)
343      ;;(make-local-variable 'sml-error-overlay)
344    
345    (setq major-mode 'inferior-sml-mode)    (setq major-mode 'inferior-sml-mode)
346    (setq mode-name "Inferior ML")    (setq mode-name "Inferior ML")
347    (setq mode-line-process '(": %s"))    (setq mode-line-process '(": %s"))
348    (use-local-map inferior-sml-mode-map)    (use-local-map inferior-sml-mode-map)
349    (add-hook 'kill-emacs-hook 'sml-proc-tidy)    ;;(add-hook 'kill-emacs-hook 'sml-temp-tidy)
350    
351    (run-hooks 'inferior-sml-mode-hook))    (run-hooks 'inferior-sml-mode-hook))
352    
# Line 542  Line 381 
381    "Run the ML program CMD with given arguments ARGS.    "Run the ML program CMD with given arguments ARGS.
382  This usually updates `sml-buffer' to a buffer named *CMD*."  This usually updates `sml-buffer' to a buffer named *CMD*."
383    (let* ((pname (file-name-nondirectory cmd))    (let* ((pname (file-name-nondirectory cmd))
          (bname (format "*%s*" pname))  
384           (args (if (equal arg "") () (sml-args-to-list arg))))           (args (if (equal arg "") () (sml-args-to-list arg))))
     (if (comint-check-proc bname)  
         (pop-to-buffer (sml-proc-buffer)) ;do nothing but switch buffer  
       (setq sml-buffer  
             (if (null args)  
                 ;; there is a good reason for this; to ensure  
                 ;; *no* argument is sent, not even a "".  
                 (set-buffer (apply 'make-comint pname cmd nil))  
               (set-buffer (apply 'make-comint pname cmd nil args))))  
       (message (format "Starting \"%s\" in background." pname))  
       (inferior-sml-mode)  
       (goto-char (point-max))  
385        ;; and this -- to keep these as defaults even if        ;; and this -- to keep these as defaults even if
386        ;; they're set in the mode hooks.        ;; they're set in the mode hooks.
387        (setq sml-program-name cmd)        (setq sml-program-name cmd)
388        (setq sml-default-arg arg))))      (setq sml-default-arg arg)
389        (setq sml-buffer (apply 'make-comint pname cmd nil args))
390    
391        (set-buffer sml-buffer)
392        (message (format "Starting \"%s\" in background." pname))
393        (inferior-sml-mode)
394        (goto-char (point-max))
395        sml-buffer))
396    
397  (defun sml-args-to-list (string)  (defun sml-args-to-list (string)
398    (let ((where (string-match "[ \t]" string)))    (let ((where (string-match "[ \t]" string)))
# Line 573  Line 407 
407                     (sml-args-to-list (substring string pos                     (sml-args-to-list (substring string pos
408                                                  (length string)))))))))                                                  (length string)))))))))
409    
 (defun sml-temp-threshold (&optional thold)  
   "Set the variable to the given prefix (nil, if no prefix given).  
 This is really mainly here to help debugging sml-mode!"  
   (interactive "P")  
   (setq sml-temp-threshold  
         (if current-prefix-arg (prefix-numeric-value thold)))  
   (message "%s" sml-temp-threshold))  
   
410  ;;;###autoload  ;;;###autoload
411  (defun switch-to-sml (eob-p)  (defun switch-to-sml (eob-p)
412    "Switch to the ML process buffer.    "Switch to the ML process buffer.
413  With prefix argument, positions cursor at point, otherwise at end of buffer."  With prefix argument, positions cursor at point, otherwise at end of buffer."
414    (interactive "P")    (interactive "P")
   (if (sml-noproc) (save-excursion (run-sml t)))  
415    (pop-to-buffer (sml-proc-buffer))    (pop-to-buffer (sml-proc-buffer))
416    (cond ((not eob-p)    (cond ((not eob-p)
417           (push-mark (point) t)           (push-mark (point) t)
# Line 599  Line 424 
424    "Send current region to the inferior ML process.    "Send current region to the inferior ML process.
425  Prefix argument means switch-to-sml afterwards.  Prefix argument means switch-to-sml afterwards.
426    
427  If the region is longer than `sml-temp-threshold' and the variable  The region is written out to a temporary file and a \"use <temp-file>\" command
428  `sml-use-command' is defined, the region is written out to a temporary file  is sent to the compiler.
429  and a \"use <temp-file>\" command is sent to the compiler\; otherwise the  See variables `sml-use-command'."
 text in the region is sent directly to the compiler. In either case a  
 trailing \"\;\\n\" will be added automatically.  
   
 See variables `sml-temp-threshold', `sml-temp-file' and `sml-use-command'."  
430    (interactive "r\nP")    (interactive "r\nP")
431    (if (sml-noproc) (save-excursion (run-sml t)))    (if (= start end)
432    (cond ((equal start end)        (message "The region is zero (ignored)")
433           (message "The region is zero (ignored)"))      (let* ((buf (sml-proc-buffer))
434          ((and sml-use-command             (file (buffer-file-name))
435                (numberp sml-temp-threshold)             (marker (copy-marker start))
436                (< sml-temp-threshold (- end start)))             (tmp (make-temp-file "sml")))
437           ;; Just in case someone is still reading from sml-temp-file:        (write-region start end tmp nil 'silently)
438           (if (file-exists-p sml-temp-file)        (with-current-buffer buf
439               (delete-file sml-temp-file))          (when sml-temp-file
440           (write-region start end sml-temp-file nil 'silently)            (ignore-errors (delete-file (car sml-temp-file)))
441           (sml-update-barrier (buffer-file-name (current-buffer)) start)            (set-marker (cdr sml-temp-file) nil))
442           (sml-update-cursor (sml-proc-buffer))          (setq sml-temp-file (cons tmp marker))
443           (comint-send-string (sml-proc)          (sml-send-string (format sml-use-command tmp) nil and-go)))))
                  (concat (format sml-use-command sml-temp-file) ";\n")))  
         (t  
          (comint-send-region (sml-proc) start end)  
          (comint-send-string (sml-proc) ";\n")))  
   (if and-go (switch-to-sml nil)))  
   
 ;; Update the buffer-local variables sml-real-file and sml-error-barrier  
 ;; in the process buffer:  
   
 (defun sml-update-barrier (file pos)  
   (let ((buf (current-buffer)))  
     (unwind-protect  
         (let* ((proc (sml-proc))  
                (pmark (marker-position (process-mark proc))))  
           (set-buffer (process-buffer proc))  
           ;; update buffer local variables  
           (setq sml-real-file (and file (cons file pos)))  
           (setq sml-error-barrier pmark))  
       (set-buffer buf))))  
   
 ;; Update the buffer-local error-cursor in proc-buffer to be its  
 ;; current proc mark.  
   
 (defun sml-update-cursor (proc-buffer)  ;always= sml-proc-buffer  
   (let ((buf (current-buffer)))  
     (unwind-protect  
         (let* ((proc (sml-proc))        ;just in case?  
                (pmark (marker-position (process-mark proc))))  
           (set-buffer proc-buffer)  
           ;; update buffer local variable  
           (setq sml-error-cursor pmark))  
       (set-buffer buf))))  
444    
445  ;; This is quite bogus, so it isn't bound to a key by default.  ;; This is quite bogus, so it isn't bound to a key by default.
446  ;; Anyone coming up with an algorithm to recognise fun & local  ;; Anyone coming up with an algorithm to recognise fun & local
# Line 667  Line 456 
456      (sml-send-region (point) (mark)))      (sml-send-region (point) (mark)))
457    (if and-go (switch-to-sml nil)))    (if and-go (switch-to-sml nil)))
458    
459    (defvar sml-source-modes '(sml-mode)
460      "*Used to determine if a buffer contains ML source code.
461    If it's loaded into a buffer that is in one of these major modes, it's
462    considered an ML source file by `sml-load-file'. Used by these commands
463    to determine defaults.")
464    
465  ;;;###autoload  ;;;###autoload
466  (defun sml-send-buffer (&optional and-go)  (defun sml-send-buffer (&optional and-go)
467    "Send buffer to inferior shell running ML process.    "Send buffer to inferior shell running ML process.
# Line 690  Line 485 
485    (interactive)    (interactive)
486    (sml-send-function t))    (sml-send-function t))
487    
   
 ;;; Mouse control and handling dedicated frames for Inferior ML  
   
 ;; simplified from frame.el in Emacs: special-display-popup-frame...  
   
 (defun sml-proc-frame ()  
   "Returns the current ML process buffer's frame, or creates one first."  
   (let ((buffer (sml-proc-buffer)))  
     (window-frame (display-buffer buffer))))  
   
 ;;(defun sml-pop-to-buffer (warp)  
 ;;  "(Towards) handling multiple frames properly.  
 ;;Raises the frame, and warps the mouse over there, only if WARP is non-nil."  
 ;;  (let ((current (window-frame (selected-window)))  
 ;;        (buffer  (sml-proc-buffer)))  
 ;;    (let ((frame (sml-proc-frame)))  
 ;;      (if (eq current frame)  
 ;;          (pop-to-buffer buffer)           ; stay on the same frame.  
 ;;        (select-frame frame)               ; XEmacs sometimes moves focus.  
 ;;        (select-window (get-buffer-window buffer)) ; necc. for XEmacs  
 ;;        ;; (raise-frame frame)  
 ;;        (if warp (sml-warp-mouse frame))))))  
   
   
488  ;;; H A C K   A T T A C K !   X E M A C S   V E R S U S   E M A C S  ;;; H A C K   A T T A C K !   X E M A C S   V E R S U S   E M A C S
489    
 ;; Only these two functions have to dance around the inane differences  
 ;; between Emacs and XEmacs (fortunately)  
   
 (defun sml-warp-mouse (frame)  
   "Warp the pointer across the screen to upper right corner of FRAME."  
   (raise-frame frame)  
   (cond ((string-match "\\(Lucid\\|XEmacs\\)" emacs-version)  
          ;; LUCID (19.10) or later... set-m-pos needs a WINDOW  
          (set-mouse-position (frame-root-window frame) (1- (frame-width)) 0))  
         (t  
          ;; GNU, post circa 19.19... set-m-pos needs a FRAME  
          (set-mouse-position frame (1- (frame-width)) 0)  
          ;; probably not needed post 19.29  
          (if (fboundp 'unfocus-frame) (unfocus-frame)))))  
   
490  (defun sml-drag-region (event)  (defun sml-drag-region (event)
491    "Highlight the text the mouse is dragged over, and send it to ML.    "Highlight the text the mouse is dragged over, and send it to ML.
492  This must be bound to a button-down mouse event, currently \\[sml-drag-region].  This must be bound to a button-down mouse event, currently \\[sml-drag-region].
# Line 767  Line 523 
523    
524  ;;; LOADING AND IMPORTING SOURCE FILES:  ;;; LOADING AND IMPORTING SOURCE FILES:
525    
526  (defvar sml-source-modes '(sml-mode)  (defvar sml-prev-dir/file nil
   "*Used to determine if a buffer contains ML source code.  
 If it's loaded into a buffer that is in one of these major modes, it's  
 considered an ML source file by `sml-load-file'. Used by these commands  
 to determine defaults.")  
   
 (defvar sml-prev-l/c-dir/file nil  
527    "Caches the (directory . file) pair used in the last `sml-load-file'    "Caches the (directory . file) pair used in the last `sml-load-file'
528  or `sml-cd' command. Used for determining the default in the next one.")  or `sml-cd' command. Used for determining the default in the next one.")
529    
# Line 786  Line 536 
536  the command to send to the ML process\; a trailing \"\;\\n\" will be added  the command to send to the ML process\; a trailing \"\;\\n\" will be added
537  automatically."  automatically."
538    (interactive "P")    (interactive "P")
539    (if (sml-noproc) (save-excursion (run-sml t)))    (let ((file (car (comint-get-source
540    (if sml-use-command                      "Load ML file: " sml-prev-dir/file sml-source-modes t))))
541        (let ((file      (with-current-buffer (sml-proc-buffer)
              (car (comint-get-source "Load ML file: " sml-prev-l/c-dir/file  
                                      sml-source-modes t))))  
542          ;; Check if buffer needs saved. Should (save-some-buffers) instead?          ;; Check if buffer needs saved. Should (save-some-buffers) instead?
543          (comint-check-source file)          (comint-check-source file)
544          (setq sml-prev-l/c-dir/file        (setq sml-prev-dir/file
545                (cons (file-name-directory file) (file-name-nondirectory file)))                (cons (file-name-directory file) (file-name-nondirectory file)))
546          (sml-update-cursor (sml-proc-buffer))        (sml-send-string (format sml-use-command file) nil and-go))))
         (comint-send-string  
          (sml-proc) (concat (format sml-use-command file) ";\n")))  
     (message "Can't load files if `sml-use-command' is undefined!"))  
   (if and-go (switch-to-sml nil)))  
547    
548  (defun sml-cd (dir)  (defun sml-cd (dir)
549    "Change the working directory of the inferior ML process.    "Change the working directory of the inferior ML process.
# Line 808  Line 552 
552  be executed to change the compiler's working directory\; a trailing  be executed to change the compiler's working directory\; a trailing
553  \"\;\\n\" will be added automatically."  \"\;\\n\" will be added automatically."
554    (interactive "DSML Directory: ")    (interactive "DSML Directory: ")
555    (let* ((buf (sml-proc-buffer))    (let ((dir (expand-file-name dir)))
556           (proc (get-buffer-process buf))      (with-current-buffer (sml-proc-buffer)
557           (dir (expand-file-name dir))        (sml-send-string (format sml-cd-command dir) t)
558           (string (concat (format sml-cd-command dir) ";\n")))        (setq default-directory dir))
559      (save-excursion      (setq sml-prev-dir/file (cons dir nil))))
560        (set-buffer buf)  
561    (defun sml-send-string (str &optional print and-go)
562      (let ((proc (sml-proc))
563            (str (concat str ";\n"))
564            (win (get-buffer-window (current-buffer) 'visible)))
565        (when win (select-window win))
566        (goto-char (point-max))        (goto-char (point-max))
567        (insert string)      (when print (insert str))
568        (set-marker (process-mark proc) (point))      (sml-update-cursor)
569        (if sml-cd-command (process-send-string proc string))      (set-marker (process-mark proc) (point-max))
570        (cd dir))      (setq compilation-last-buffer (current-buffer))
571      (setq sml-prev-l/c-dir/file (cons dir nil))))      (comint-send-string proc str)
572        (when and-go (switch-to-sml nil))))
 (defun sml-send-command (cmd &optional dir)  
   "Send string to ML process, display this string in ML's buffer"  
   (if (sml-noproc) (save-excursion (run-sml t)))  
   (let* ((my-dir (or dir (expand-file-name default-directory)))  
          (cd-cmd (if my-dir  
                      (concat (format sml-cd-command my-dir) "; ")  
                    ""))  
          (buf (sml-proc-buffer))  
          (proc (get-buffer-process buf))  
          (string (concat cd-cmd cmd ";\n")))  
     (save-some-buffers t)  
     (save-excursion  
       (sml-update-cursor buf)  
       (set-buffer buf)  
       (goto-char (point-max))  
       (insert string)  
       (if my-dir (cd my-dir))  
       (set-marker (process-mark proc) (point))  
       (process-send-string proc string))  
     (switch-to-sml t)))  
573    
574  (defun sml-make (command)  (defun sml-compile (command)
575    "re-make a system using (by default) CM.    "re-make a system using (by default) CM.
576     The exact command used can be specified by providing a prefix argument."     The exact command used can be specified by providing a prefix argument."
577    (interactive    (interactive
578     ;; code taken straight from compile.el     ;; code taken straight from compile.el
579     (if (or current-prefix-arg (not sml-make-command))     (if (or compilation-read-command current-prefix-arg)
580         (list (read-from-minibuffer "Compile command: "         (list (read-from-minibuffer "Compile command: "
581                                   sml-make-command nil nil                                   sml-compile-command nil nil
582                                   '(compile-history . 1)))                                   '(compile-history . 1)))
583       (list sml-make-command)))       (list sml-compile-command)))
584    (setq sml-make-command command)    (setq sml-compile-command command)
585    ;; try to find a makefile up the sirectory tree    (save-some-buffers (not compilation-ask-about-save) nil)
586    (let ((dir (and sml-make-file-name (expand-file-name default-directory))))    ;; try to find a makefile up the directory tree
587      (let ((dir (when sml-make-file-name default-directory)))
588      (while (and dir (not (file-exists-p (concat dir sml-make-file-name))))      (while (and dir (not (file-exists-p (concat dir sml-make-file-name))))
589        (let ((newdir (file-name-directory (directory-file-name dir))))        (let ((newdir (file-name-directory (directory-file-name dir))))
590          (setq dir (if (equal newdir dir) nil newdir))))          (setq dir (unless (equal newdir dir) newdir))))
591      (sml-send-command command dir)))      (unless dir (setq dir default-directory))
592        (with-current-buffer (sml-proc-buffer)
593          (setq default-directory dir)
594          (sml-send-string (concat (format sml-cd-command dir) "; " command) t t))))
595    
596  ;;; PARSING ERROR MESSAGES  ;;; PARSING ERROR MESSAGES
597    
598  ;; This should need no modification to support other compilers.  ;; This should need no modification to support other compilers.
599    
600  ;;;###autoload  ;; Update the buffer-local error-cursor in proc-buffer to be its
601  (defun sml-next-error (skip)  ;; current proc mark.
   "Find the next error by parsing the inferior ML buffer.  
 A prefix argument means `sml-skip-errors' (qv) instead.  
   
 Move the error message on the top line of the window\; put the cursor  
 \(point\) at the beginning of the error source.  
   
 If the error message specifies a range, and `sml-error-parser' returns  
 the range, the mark is placed at the end of the range. If the variable  
 `sml-error-overlay' is non-nil, the region will also be highlighted.  
   
 If `sml-error-parser' returns a fifth component this is assumed to be  
 a string to indicate the nature of the error: this will be echoed in  
 the minibuffer.  
   
 Error interaction only works if there is a real file associated with  
 the input -- though of course it also depends on the compiler's error  
 messages \(also see documantation for `sml-error-parser'\).  
   
 However: if the last text sent went via `sml-load-file' (or the temp  
 file mechanism), the next error reported will be relative to the start  
 of the region sent, any error reports in the previous output being  
 forgotten. If the text went directly to the compiler the succeeding  
 error reported will be the next error relative to the location \(in  
 the output\) of the last error. This odd behaviour may have a use...?"  
   (interactive "P")  
   (if skip (sml-skip-errors) (sml-do-next-error)))  
602    
603  (defun sml-bottle (msg)  (defvar sml-endof-error-alist nil)
   "Function to let `sml-next-error' give up gracefully."  
   (sml-warp-mouse (selected-frame))  
   (error msg))  
   
 (defun sml-do-next-error ()  
   "The buisiness end of `sml-next-error' (qv)"  
   (let ((case-fold-search nil)  
         ;; set this variable iff we called sml-next-error in a SML buffer  
         (sml-window (if (memq major-mode sml-source-modes) (selected-window)))  
         (proc-buffer (sml-proc-buffer)))  
     ;; undo (don't destroy) the previous overlay to be tidy  
     (sml-error-overlay 'undo 1 1  
                        (and sml-error-file (get-file-buffer sml-error-file)))  
     ;; go to interaction buffer but don't raise it's frame  
     (pop-to-buffer (sml-proc-buffer))  
     ;; go to the last remembered error, and search for the next one.  
     (goto-char sml-error-cursor)  
     (if (not (re-search-forward sml-error-regexp (point-max) t))  
         ;; no more errors -- move point to the sml prompt at the end  
         (progn  
           (goto-char (point-max))  
           (if sml-window (select-window sml-window)) ;return there, perhaps  
           (message "No error message(s) found."))  
       ;; error found: point is at end of last match; set the cursor posn.  
       (setq sml-error-cursor (point))  
       ;; move the SML window's text up to this line  
       (set-window-start (get-buffer-window proc-buffer) (match-beginning 0))  
       (let* ((pos)  
              (parse (funcall sml-error-parser (match-beginning 0)))  
              (file (nth 0 parse))  
              (line0 (nth 1 parse))  
              (col0 (nth 2 parse))  
              (line/col1 (nth 3 parse))  
              (msg (nth 4 parse)))  
         ;; Give up immediately if the error report is scribble  
         (if (or (null file) (null line0))  
             (sml-bottle "Failed to parse/locate this error properly!"))  
         ;; decide what to do depending on the file returned  
         (if (string= file "std_in")  
             ;; presently a fundamental limitation i'm afraid.  
             (sml-bottle "Sorry, can't locate errors on std_in.")  
           (if (string= file sml-temp-file)  
               ;; errors found in tmp file; seek the real file  
               (if (< (point) sml-error-barrier)  
                   ;; weird. user cleared *sml* and use'd the tmp file?  
                   (sml-bottle "Temp file error report is not current.")  
                 (if (not (car sml-real-file))  
                     ;; sent from a buffer w/o a file attached.  
                     ;; DEAL WITH THIS EVENTUALLY.  
                     (sml-bottle "No real file associated with the temp file.")  
                   ;; real file and error-barrier  
                   (setq file (car sml-real-file))  
                   (setq pos (cdr sml-real-file))))))  
         (if (not (file-readable-p file))  
             (sml-bottle (concat "Can't read " file))  
           ;; instead of (find-file-other-window file) to lookup the file  
           (find-file-other-window file)  
           ;; no good if the buffer's narrowed, still...  
           (goto-char (or pos 1))        ; line 1 if no tmp file  
           (forward-line (1- line0))  
           (forward-char (1- col0))  
           ;; point is at start of error text; seek the end.  
           (let ((start (point))  
                 (end (and line/col1  
                           (condition-case nil  
                               (progn (eval line/col1) (point))  
                             (error nil)))))  
             ;; return to start anyway  
             (goto-char start)  
             ;; if point went to end, put mark there, and maybe highlight  
             (if end (progn (push-mark end t)  
                            (sml-error-overlay nil start end)))  
             (setq sml-error-file file)   ; remember this for next time  
             (if msg (message msg)))))))) ; echo the error/warning message  
604    
605  (defun sml-skip-errors ()  (defun sml-update-cursor ()
606    "Skip past the rest of the errors."    ;; update buffer local variable
607    (interactive)    (set-marker sml-error-cursor (1- (process-mark (sml-proc))))
608    (if (memq major-mode sml-source-modes) (sml-error-overlay 'undo))    (setq sml-endof-error-alist nil)
609    (sml-update-cursor (sml-proc-buffer))    (compilation-forget-errors)
610    (if (eq major-mode 'sml-inferior-mode) (goto-char (point-max))))    (if (markerp compilation-parsing-end)
611          (set-marker compilation-parsing-end sml-error-cursor)
612  ;;; Set up the inferior mode keymap, using sml-mode bindings...      (setq compilation-parsing-end sml-error-cursor)))
613    
614  (cond ((not inferior-sml-mode-map)  (defun sml-make-error (f c)
615         (setq inferior-sml-mode-map (nconc (make-sparse-keymap) comint-mode-map))    (let ((err (point-marker))
616         (install-sml-keybindings inferior-sml-mode-map)          (linenum (string-to-number c))
617         (define-key inferior-sml-mode-map "\C-c\C-s" 'run-sml)          (filename (list (first f) (second f)))
618         (define-key inferior-sml-mode-map "\t"       'comint-dynamic-complete)))          (column (string-to-number (compile-buffer-substring (third f)))))
619        ;; record the end of error, if any
620        (when (fourth f)
621          (let* ((endline (string-to-number (compile-buffer-substring (fourth f))))
622                 (endcol (string-to-number (compile-buffer-substring (fifth f))))
623                 (linediff (- endline linenum)))
624            (push (list err linediff (if (= 0 linediff) (- endcol column) endcol))
625                  sml-endof-error-alist)))
626        ;; build the error descriptor
627        (if (string= (car sml-temp-file) (first f))
628            ;; special case for code sent via sml-send-region
629            (let ((marker (cdr sml-temp-file)))
630              (with-current-buffer (marker-buffer marker)
631                (goto-char marker)
632                (forward-line (1- linenum))
633                (forward-char (1- column))
634                (cons err (point-marker))))
635          ;; taken from compile.el
636          (list err filename linenum column))))
637    
638    (defadvice compilation-goto-locus (after sml-endof-error activate)
639      (let* ((next-error (ad-get-arg 0))
640             (err (car next-error))
641             (pos (cdr next-error))
642             (endof (with-current-buffer (marker-buffer err)
643                      (assq err sml-endof-error-alist))))
644        (if (not endof) (sml-error-overlay 'undo)
645          (with-current-buffer (marker-buffer pos)
646            (goto-char pos)
647            (let ((linediff (second endof))
648                  (coldiff (third endof)))
649              (when (> 0 linediff) (forward-line linediff))
650              (forward-char coldiff))
651            (sml-error-overlay nil pos (point))
652            (push-mark nil t (not sml-error-overlay))
653            (goto-char pos)))))
654    
655    (defun sml-error-overlay (undo &optional beg end)
656      "Move `sml-error-overlay' so it surrounds the text region in the
657    current buffer. If the buffer-local variable `sml-error-overlay' is
658    non-nil it should be an overlay \(or extent, in XEmacs speak\)\; this
659    function moves the overlay over the current region. If the optional
660    BUFFER argument is given, move the overlay in that buffer instead of
661    the current buffer.
662    
663    Called interactively, the optional prefix argument UNDO indicates that
664    the overlay should simply be removed: \\[universal-argument] \
665    \\[sml-error-overlay]."
666      (interactive "P")
667      (when sml-error-overlay
668        (unless (overlayp sml-error-overlay)
669          (let ((ol sml-error-overlay))
670            (setq sml-error-overlay (make-overlay 0 0))
671            (overlay-put sml-error-overlay 'face (if (symbolp ol) ol 'region))))
672        (if undo (move-overlay sml-error-overlay 1 1 (current-buffer))
673          ;; if active regions, signals mark not active if no region set
674          (let ((beg (or beg (region-beginning)))
675                (end (or end (region-end))))
676            (move-overlay sml-error-overlay beg end (current-buffer))))))
677    
678  ;;; H A C K   A T T A C K !   X E M A C S   /   E M A C S   K E Y S  ;;; H A C K   A T T A C K !   X E M A C S   /   E M A C S   K E Y S
679    
# Line 999  Line 690 
690  (run-hooks 'inferior-sml-load-hook)  (run-hooks 'inferior-sml-load-hook)
691    
692  ;;; Here is where sml-proc.el ends  ;;; Here is where sml-proc.el ends
693    (provide 'sml-proc)

Legend:
Removed from v.39  
changed lines
  Added in v.394

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0