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 342, Sat Jun 19 09:26:38 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 78  Line 80 
80  ;; While small pieces of text can be fed quite happily into the ML  ;; While small pieces of text can be fed quite happily into the ML
81  ;; process directly, lager pieces should (probably) be sent via a  ;; process directly, lager pieces should (probably) be sent via a
82  ;; temporary file making use of the compiler's "use" command.  ;; temporary file making use of the compiler's "use" command.
83    ;; To be safe, we always use a temp file (which also improves error
84  ;; CURRENT RATIONALE: you get sense out of the error messages if  ;; reporting).
 ;; 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.  
85    
86  ;;; FOR YOUR .EMACS  ;;; FOR YOUR .EMACS
87    
# Line 97  Line 92 
92  ;;          (define-key inferior-sml-mode-map "\C-cd"    'sml-cd)  ;;          (define-key inferior-sml-mode-map "\C-cd"    'sml-cd)
93  ;;          (define-key          sml-mode-map "\C-cd"    'sml-cd)  ;;          (define-key          sml-mode-map "\C-cd"    'sml-cd)
94  ;;          (define-key          sml-mode-map "\C-c\C-f" 'sml-send-function)  ;;          (define-key          sml-mode-map "\C-c\C-f" 'sml-send-function)
 ;;          (setq sml-temp-threshold 0))) ; safe: always use tmp file  
95    
96  ;; (setq inferior-sml-mode-hook  ;; (setq inferior-sml-mode-hook
97  ;;       '(lambda() "Inferior SML mode defaults"  ;;       '(lambda() "Inferior SML mode defaults"
# Line 110  Line 104 
104  ;;; INFERIOR ML MODE VARIABLES  ;;; INFERIOR ML MODE VARIABLES
105    
106  (require 'sml-mode)  (require 'sml-mode)
107    (require 'sml-util)
108  (require 'comint)  (require 'comint)
109  (provide 'sml-proc)  (require 'compile)
110    
111  (defvar sml-program-name "sml"  (defvar sml-program-name "sml"
112    "*Program to run as ML.")    "*Program to run as ML.")
# Line 119  Line 114 
114  (defvar sml-default-arg ""  (defvar sml-default-arg ""
115    "*Default command line option to pass, if any.")    "*Default command line option to pass, if any.")
116    
117  (defvar sml-make-command "CM.make()"  (defvar sml-compile-command "CM.make()"
118    "The command used by default by `sml-make'.")    "The command used by default by `sml-make'.")
119    
120  (defvar sml-make-file-name "sources.cm"  (defvar sml-make-file-name "sources.cm"
# Line 128  Line 123 
123  ;;(defvar sml-raise-on-error nil  ;;(defvar sml-raise-on-error nil
124  ;;  "*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.")
125    
 (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\"\)")  
   
126  (defvar inferior-sml-mode-hook nil  (defvar inferior-sml-mode-hook nil
127    "*This hook is run when the inferior ML process is started.    "*This hook is run when the inferior ML process is started.
128  All buffer local customisations for the interaction buffers go here.")  All buffer local customisations for the interaction buffers go here.")
# Line 154  Line 131 
131    "*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.
132  This is a good place to put your preferred key bindings.")  This is a good place to put your preferred key bindings.")
133    
134    (defvar sml-error-overlay nil
135      "*Non-nil means use an overlay to highlight errorful code in the buffer.
136    The actual value is the name of a face to use for the overlay.
137    Instead of setting this variable to 'region, you can also simply keep
138    it NIL and use (transient-mark-mode) which will provide similar
139    benefits (but with several side effects).")
140    
141  (defvar sml-buffer nil  (defvar sml-buffer nil
142    "*The current ML process buffer.    "*The current ML process buffer.
143    
# Line 211  Line 195 
195  The format specifier \"%s\" will be converted into the directory name  The format specifier \"%s\" will be converted into the directory name
196  specified when running the command \\[sml-cd].")  specified when running the command \\[sml-cd].")
197    
198  (defvar sml-prompt-regexp "^[\-=] *"  (defvar sml-prompt-regexp "^[-=>#] *"
199    "*Regexp used to recognise prompts in the inferior ML process.")    "*Regexp used to recognise prompts in the inferior ML process.")
200    
201  (defvar sml-error-parser 'sml-smlnj-error-parser  (defvar sml-error-parser 'sml-smlnj-error-parser
# Line 245  Line 229 
229  ;; std_in:2.1-4.3 Error: operator and operand don't agree (tycon mismatch)  ;; std_in:2.1-4.3 Error: operator and operand don't agree (tycon mismatch)
230  ;; std_in:2.1 Error: operator and operand don't agree (tycon mismatch)  ;; std_in:2.1 Error: operator and operand don't agree (tycon mismatch)
231    
232  (defconst sml-smlnj-error-regexp  (defconst sml-error-regexp-alist
233    (concat    '(;; Poly/ML messages
234     "^[-= ]*\\(.+\\):"                     ;file name      ("\\(Error\\|Warning:\\) in '\\(.+\\)', line \\([0-9]+\\)" 2 3)
235     "\\([0-9]+\\)\\.\\([0-9]+\\)"          ;start line.column      ;; Moscow ML
236     "\\(-\\([0-9]+\\)\\.\\([0-9]+\\)\\)?"  ;end line.colum      ("File \"\\([^\"]+\\)\", line \\([0-9]+\\)\\(-\\([0-9]+\\)\\)?, characters \\([0-9]+\\)-\\([0-9]+\\):" 1 2 5)
237     ".+\\(\\(Error\\|Warning\\): .*\\)")   ;the message      ;; SML/NJ:  the file-pattern is restricted to no-spaces to avoid
238        ;; pathological behavior with very long lines.
239    "Default regexp matching SML/NJ error and warning messages.      ("^[-= ]*\\([^ ]+\\):\\([0-9]+\\)\\.\\([0-9]+\\)\\(-\\([0-9]+\\)\\.\\([0-9]+\\)\\)? \\(Error\\|Warning\\): .*" 1 sml-make-error 2 3 5 6)
240        ;; SML/NJ's exceptions:  see above.
241  There should be no need to customise this, though you might decide      ("^ +\\(raised at: \\)?\\([^ ]+\\):\\([0-9]+\\)\\.\\([0-9]+\\)\\(-\\([0-9]+\\)\\.\\([0-9]+\\)\\)" 2 sml-make-error 3 4 6 7)))
 that you aren't interested in Warnings -- my advice would be to modify  
 `sml-error-regexp' explicitly to do that though.  
242    
243  If you do customise `sml-smlnj-error-regexp' you may need to modify  (defvar sml-error-regexp nil
 the function `sml-smlnj-error-parser' (qv).")  
   
 (defvar sml-error-regexp sml-smlnj-error-regexp  
244    "*Regexp for matching \(the start of\) an error message.")    "*Regexp for matching \(the start of\) an error message.")
245    
246  ;; font-lock support  ;; font-lock support
247  (defvar inferior-sml-font-lock-keywords  (defconst inferior-sml-font-lock-keywords
248    `((,(concat "\\(" sml-prompt-regexp "\\)\\(.*\\)")    `(;; prompt and following interactive command
249        (,(concat "\\(" sml-prompt-regexp "\\)\\(.*\\)")
250       (1 font-lock-prompt-face)       (1 font-lock-prompt-face)
251       (2 font-lock-command-face keep))       (2 font-lock-command-face keep))
252      (,sml-error-regexp . font-lock-warning-face)      ;; CM's messages
253      ("^\\[\\(.*GC #.*\n\\)*.*\\]" . font-lock-comment-face)      ("^\\[\\(.*GC #.*\n\\)*.*\\]" . font-lock-comment-face)
254      ("^GC #.*" . font-lock-comment-face)))      ;; SML/NJ's irritating GC messages
255        ("^GC #.*" . font-lock-comment-face)
256        ;; error messages
257        ,@(mapcar (lambda (ra) (cons (car ra) 'font-lock-warning-face))
258                  sml-error-regexp-alist))
259      "Font-locking specification for inferior SML mode.")
260    
261  ;; default faces values  ;; default faces values
262  (defvar font-lock-prompt-face  (defvar font-lock-prompt-face
# Line 286  Line 271 
271  (defvar inferior-sml-font-lock-defaults  (defvar inferior-sml-font-lock-defaults
272    '(inferior-sml-font-lock-keywords nil nil nil nil))    '(inferior-sml-font-lock-keywords nil nil nil nil))
273    
 (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)))  
   
   
274  ;;; CODE  ;;; CODE
275    
276  (defvar inferior-sml-mode-map nil)  (defmap inferior-sml-mode-map
277      '(("\C-c\C-s" . run-sml)
278        ("\t"       . comint-dynamic-complete))
279      "Keymap for inferior-sml mode"
280      :inherit (list sml-bindings comint-mode-map))
281    
282    
283  ;; buffer-local  ;; buffer-local
284    
285    (defvar sml-temp-file nil)
286  (defvar sml-error-file nil)             ; file from which the last error came  (defvar sml-error-file nil)             ; file from which the last error came
 (defvar sml-real-file nil)              ; used for finding source errors  
287  (defvar sml-error-cursor nil)           ;   ditto  (defvar sml-error-cursor nil)           ;   ditto
 (defvar sml-error-barrier nil)          ;   ditto  
288    
289  (defun sml-proc-buffer ()  (defun sml-proc-buffer ()
290    "Returns the current ML process buffer,    "Returns the current ML process buffer,
291  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
292  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
293  buffer."  buffer."
294    (let ((buffer    (or (and (eq major-mode 'inferior-sml-mode) (current-buffer))
295           (cond ((eq major-mode 'inferior-sml-mode)        (and sml-buffer
296                  ;; default to current buffer if it's in inferior-sml-mode             (let ((buf (get-buffer sml-buffer)))
                 (current-buffer))  
                ((bufferp sml-buffer)  
297                 ;; buffer-name returns nil if the buffer has been killed                 ;; buffer-name returns nil if the buffer has been killed
298                  (buffer-name sml-buffer))               (and buf (buffer-name buf) buf)))
299                 ((stringp sml-buffer)        ;; no buffer found, make a new one
300                  ;; 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"))))  
301    
302  (defun sml-proc ()  (defun sml-proc ()
303    "Returns the current ML process. See variable `sml-buffer'."    "Returns the current ML process. See variable `sml-buffer'."
304    (let ((proc (get-buffer-process (sml-proc-buffer))))    (assert (eq major-mode 'inferior-sml-mode))
305      (or proc    (or (get-buffer-process (current-buffer))
306          (error "No current process. See variable sml-buffer"))))        (progn (run-sml t) (get-buffer-process (current-buffer)))))
307    
308  (defun sml-buffer (echo)  (defun sml-buffer (echo)
309    "Make the current buffer the current `sml-buffer' if that is sensible.    "Make the current buffer the current `sml-buffer' if that is sensible.
310  Lookup variable `sml-buffer' to see why this might be useful."  Lookup variable `sml-buffer' to see why this might be useful."
311    (interactive "P")    (interactive "P")
312    (let ((current    (when (and (not echo) (eq major-mode 'inferior-sml-mode))
313           (cond ((bufferp sml-buffer) (or (buffer-name sml-buffer) "undefined"))      (setq sml-buffer (current-buffer)))
314                 ((stringp sml-buffer) sml-buffer)    (message "ML process buffer is %s."
315                 (t "undefined"))))             (or (ignore-errors (buffer-name (get-buffer sml-buffer)))
316    (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)))  
317    
318  (defun inferior-sml-mode ()  (defun inferior-sml-mode ()
319    "Major mode for interacting with an inferior ML process.    "Major mode for interacting with an inferior ML process.
# Line 446  Line 340 
340  `sml-prompt-regexp' (default \"^[\\-=] *\")  `sml-prompt-regexp' (default \"^[\\-=] *\")
341      Regexp used to recognise prompts in the inferior ML process.      Regexp used to recognise prompts in the inferior ML process.
342    
 `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.  
   
343  `sml-error-regexp'  `sml-error-regexp'
344     (default -- complicated)     (default -- complicated)
345      Regexp for matching error messages from the compiler.      Regexp for matching error messages from the compiler.
# Line 488  Line 374 
374    (sml-mode-variables)    (sml-mode-variables)
375    
376    ;; For sequencing through error messages:    ;; For sequencing through error messages:
377      (set (make-local-variable 'sml-error-cursor) (point-max-marker))
378    (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))  
379    (set (make-local-variable 'font-lock-defaults)    (set (make-local-variable 'font-lock-defaults)
380         inferior-sml-font-lock-defaults)         inferior-sml-font-lock-defaults)
381    
382    (make-local-variable 'sml-use-command)    ;; compilation support (used for next-error)
383    (make-local-variable 'sml-cd-command)    (set (make-local-variable 'compilation-error-regexp-alist)
384    (make-local-variable 'sml-prompt-regexp)         sml-error-regexp-alist)
385    (make-local-variable 'sml-error-parser)    (compilation-shell-minor-mode 1)
386    (make-local-variable 'sml-error-regexp)    ;; I'm sure people might kill me for that
387      (setq compilation-error-screen-columns nil)
388      (make-local-variable 'sml-endof-error-alist)
389      ;;(make-local-variable 'sml-error-overlay)
390    
391    (setq major-mode 'inferior-sml-mode)    (setq major-mode 'inferior-sml-mode)
392    (setq mode-name "Inferior ML")    (setq mode-name "Inferior ML")
393    (setq mode-line-process '(": %s"))    (setq mode-line-process '(": %s"))
394    (use-local-map inferior-sml-mode-map)    (use-local-map inferior-sml-mode-map)
395    (add-hook 'kill-emacs-hook 'sml-proc-tidy)    ;;(add-hook 'kill-emacs-hook 'sml-temp-tidy)
396    
397    (run-hooks 'inferior-sml-mode-hook))    (run-hooks 'inferior-sml-mode-hook))
398    
# Line 542  Line 427 
427    "Run the ML program CMD with given arguments ARGS.    "Run the ML program CMD with given arguments ARGS.
428  This usually updates `sml-buffer' to a buffer named *CMD*."  This usually updates `sml-buffer' to a buffer named *CMD*."
429    (let* ((pname (file-name-nondirectory cmd))    (let* ((pname (file-name-nondirectory cmd))
          (bname (format "*%s*" pname))  
430           (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))  
431        ;; and this -- to keep these as defaults even if        ;; and this -- to keep these as defaults even if
432        ;; they're set in the mode hooks.        ;; they're set in the mode hooks.
433        (setq sml-program-name cmd)        (setq sml-program-name cmd)
434        (setq sml-default-arg arg))))      (setq sml-default-arg arg)
435        (setq sml-buffer (apply 'make-comint pname cmd nil args))
436    
437        (set-buffer sml-buffer)
438        (message (format "Starting \"%s\" in background." pname))
439        (inferior-sml-mode)
440        (goto-char (point-max))
441        sml-buffer))
442    
443  (defun sml-args-to-list (string)  (defun sml-args-to-list (string)
444    (let ((where (string-match "[ \t]" string)))    (let ((where (string-match "[ \t]" string)))
# Line 573  Line 453 
453                     (sml-args-to-list (substring string pos                     (sml-args-to-list (substring string pos
454                                                  (length string)))))))))                                                  (length string)))))))))
455    
 (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))  
   
456  ;;;###autoload  ;;;###autoload
457  (defun switch-to-sml (eob-p)  (defun switch-to-sml (eob-p)
458    "Switch to the ML process buffer.    "Switch to the ML process buffer.
459  With prefix argument, positions cursor at point, otherwise at end of buffer."  With prefix argument, positions cursor at point, otherwise at end of buffer."
460    (interactive "P")    (interactive "P")
   (if (sml-noproc) (save-excursion (run-sml t)))  
461    (pop-to-buffer (sml-proc-buffer))    (pop-to-buffer (sml-proc-buffer))
462    (cond ((not eob-p)    (cond ((not eob-p)
463           (push-mark (point) t)           (push-mark (point) t)
# Line 599  Line 470 
470    "Send current region to the inferior ML process.    "Send current region to the inferior ML process.
471  Prefix argument means switch-to-sml afterwards.  Prefix argument means switch-to-sml afterwards.
472    
473  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
474  `sml-use-command' is defined, the region is written out to a temporary file  is sent to the compiler.
475  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'."  
476    (interactive "r\nP")    (interactive "r\nP")
477    (if (sml-noproc) (save-excursion (run-sml t)))    (if (= start end)
478    (cond ((equal start end)        (message "The region is zero (ignored)")
479           (message "The region is zero (ignored)"))      (let* ((buf (sml-proc-buffer))
480          ((and sml-use-command             (file (buffer-file-name))
481                (numberp sml-temp-threshold)             (marker (copy-marker start))
482                (< sml-temp-threshold (- end start)))             (tmp (make-temp-file "sml")))
483           ;; Just in case someone is still reading from sml-temp-file:        (write-region start end tmp nil 'silently)
484           (if (file-exists-p sml-temp-file)        (with-current-buffer buf
485               (delete-file sml-temp-file))          (when sml-temp-file
486           (write-region start end sml-temp-file nil 'silently)            (ignore-errors (delete-file (car sml-temp-file)))
487           (sml-update-barrier (buffer-file-name (current-buffer)) start)            (set-marker (cdr sml-temp-file) nil))
488           (sml-update-cursor (sml-proc-buffer))          (setq sml-temp-file (cons tmp marker))
489           (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))))  
490    
491  ;; 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.
492  ;; Anyone coming up with an algorithm to recognise fun & local  ;; Anyone coming up with an algorithm to recognise fun & local
# Line 667  Line 502 
502      (sml-send-region (point) (mark)))      (sml-send-region (point) (mark)))
503    (if and-go (switch-to-sml nil)))    (if and-go (switch-to-sml nil)))
504    
505    (defvar sml-source-modes '(sml-mode)
506      "*Used to determine if a buffer contains ML source code.
507    If it's loaded into a buffer that is in one of these major modes, it's
508    considered an ML source file by `sml-load-file'. Used by these commands
509    to determine defaults.")
510    
511  ;;;###autoload  ;;;###autoload
512  (defun sml-send-buffer (&optional and-go)  (defun sml-send-buffer (&optional and-go)
513    "Send buffer to inferior shell running ML process.    "Send buffer to inferior shell running ML process.
# Line 695  Line 536 
536    
537  ;; simplified from frame.el in Emacs: special-display-popup-frame...  ;; simplified from frame.el in Emacs: special-display-popup-frame...
538    
539  (defun sml-proc-frame ()  ;; (defun sml-proc-frame ()
540    "Returns the current ML process buffer's frame, or creates one first."  ;;   "Returns the current ML process buffer's frame, or creates one first."
541    (let ((buffer (sml-proc-buffer)))  ;;   (let ((buffer (sml-proc-buffer)))
542      (window-frame (display-buffer 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))))))  
   
543    
544  ;;; 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
545    
546  ;; Only these two functions have to dance around the inane differences  ;; Only these two functions have to dance around the inane differences
547  ;; between Emacs and XEmacs (fortunately)  ;; between Emacs and XEmacs (fortunately)
548    
549  (defun sml-warp-mouse (frame)  ;; (defun sml-warp-mouse (frame)
550    "Warp the pointer across the screen to upper right corner of FRAME."  ;;   "Warp the pointer across the screen to upper right corner of FRAME."
551    (raise-frame frame)  ;;   (raise-frame frame)
552    (cond ((string-match "\\(Lucid\\|XEmacs\\)" emacs-version)  ;;   (cond ((string-match "\\(Lucid\\|XEmacs\\)" emacs-version)
553           ;; LUCID (19.10) or later... set-m-pos needs a WINDOW  ;;          ;; LUCID (19.10) or later... set-m-pos needs a WINDOW
554           (set-mouse-position (frame-root-window frame) (1- (frame-width)) 0))  ;;          (set-mouse-position (frame-root-window frame) (1- (frame-width)) 0))
555          (t  ;;         (t
556           ;; GNU, post circa 19.19... set-m-pos needs a FRAME  ;;          ;; GNU, post circa 19.19... set-m-pos needs a FRAME
557           (set-mouse-position frame (1- (frame-width)) 0)  ;;          (set-mouse-position frame (1- (frame-width)) 0)
558           ;; probably not needed post 19.29  ;;          ;; probably not needed post 19.29
559           (if (fboundp 'unfocus-frame) (unfocus-frame)))))  ;;          (if (fboundp 'unfocus-frame) (unfocus-frame)))))
560    
561  (defun sml-drag-region (event)  (defun sml-drag-region (event)
562    "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.
# Line 767  Line 594 
594    
595  ;;; LOADING AND IMPORTING SOURCE FILES:  ;;; LOADING AND IMPORTING SOURCE FILES:
596    
597  (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  
598    "Caches the (directory . file) pair used in the last `sml-load-file'    "Caches the (directory . file) pair used in the last `sml-load-file'
599  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.")
600    
# Line 786  Line 607 
607  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
608  automatically."  automatically."
609    (interactive "P")    (interactive "P")
610    (if (sml-noproc) (save-excursion (run-sml t)))    (let ((file (car (comint-get-source
611    (if sml-use-command                      "Load ML file: " sml-prev-dir/file sml-source-modes t))))
612        (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))))  
613          ;; Check if buffer needs saved. Should (save-some-buffers) instead?          ;; Check if buffer needs saved. Should (save-some-buffers) instead?
614          (comint-check-source file)          (comint-check-source file)
615          (setq sml-prev-l/c-dir/file        (setq sml-prev-dir/file
616                (cons (file-name-directory file) (file-name-nondirectory file)))                (cons (file-name-directory file) (file-name-nondirectory file)))
617          (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)))  
618    
619  (defun sml-cd (dir)  (defun sml-cd (dir)
620    "Change the working directory of the inferior ML process.    "Change the working directory of the inferior ML process.
# Line 808  Line 623 
623  be executed to change the compiler's working directory\; a trailing  be executed to change the compiler's working directory\; a trailing
624  \"\;\\n\" will be added automatically."  \"\;\\n\" will be added automatically."
625    (interactive "DSML Directory: ")    (interactive "DSML Directory: ")
626    (let* ((buf (sml-proc-buffer))    (let ((dir (expand-file-name dir)))
627           (proc (get-buffer-process buf))      (with-current-buffer (sml-proc-buffer)
628           (dir (expand-file-name dir))        (sml-send-string (format sml-cd-command dir) t)
629           (string (concat (format sml-cd-command dir) ";\n")))        (setq default-directory dir))
630      (save-excursion      (setq sml-prev-dir/file (cons dir nil))))
631        (set-buffer buf)  
632    (defun sml-send-string (str &optional print and-go)
633      (let ((proc (sml-proc))
634            (str (concat str ";\n"))
635            (win (get-buffer-window (current-buffer) 'visible)))
636        (when win (select-window win))
637        (goto-char (point-max))        (goto-char (point-max))
638        (insert string)      (when print (insert str))
639        (set-marker (process-mark proc) (point))      (sml-update-cursor)
640        (if sml-cd-command (process-send-string proc string))      (set-marker (process-mark proc) (point-max))
641        (cd dir))      (setq compilation-last-buffer (current-buffer))
642      (setq sml-prev-l/c-dir/file (cons dir nil))))      (comint-send-string proc str)
643        (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)))  
644    
645  (defun sml-make (command)  (defun sml-compile (command)
646    "re-make a system using (by default) CM.    "re-make a system using (by default) CM.
647     The exact command used can be specified by providing a prefix argument."     The exact command used can be specified by providing a prefix argument."
648    (interactive    (interactive
649     ;; code taken straight from compile.el     ;; code taken straight from compile.el
650     (if (or current-prefix-arg (not sml-make-command))     (if (or compilation-read-command current-prefix-arg)
651         (list (read-from-minibuffer "Compile command: "         (list (read-from-minibuffer "Compile command: "
652                                   sml-make-command nil nil                                   sml-compile-command nil nil
653                                   '(compile-history . 1)))                                   '(compile-history . 1)))
654       (list sml-make-command)))       (list sml-compile-command)))
655    (setq sml-make-command command)    (setq sml-compile-command command)
656    ;; try to find a makefile up the sirectory tree    (save-some-buffers (not compilation-ask-about-save) nil)
657    (let ((dir (and sml-make-file-name (expand-file-name default-directory))))    ;; try to find a makefile up the directory tree
658      (let ((dir (when sml-make-file-name default-directory)))
659      (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))))
660        (let ((newdir (file-name-directory (directory-file-name dir))))        (let ((newdir (file-name-directory (directory-file-name dir))))
661          (setq dir (if (equal newdir dir) nil newdir))))          (setq dir (unless (equal newdir dir) newdir))))
662      (sml-send-command command dir)))      (unless dir (setq dir default-directory))
663        (with-current-buffer (sml-proc-buffer)
664          (setq default-directory dir)
665          (sml-send-string (concat (format sml-cd-command dir) "; " command) t t))))
666    
667  ;;; PARSING ERROR MESSAGES  ;;; PARSING ERROR MESSAGES
668    
669  ;; This should need no modification to support other compilers.  ;; This should need no modification to support other compilers.
670    
671  ;;;###autoload  ;; Update the buffer-local error-cursor in proc-buffer to be its
672  (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)))  
673    
674  (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  
675    
676  (defun sml-skip-errors ()  (defun sml-update-cursor ()
677    "Skip past the rest of the errors."    ;; update buffer local variable
678    (interactive)    (set-marker sml-error-cursor (1- (process-mark (sml-proc))))
679    (if (memq major-mode sml-source-modes) (sml-error-overlay 'undo))    (setq sml-endof-error-alist nil)
680    (sml-update-cursor (sml-proc-buffer))    (compilation-forget-errors)
681    (if (eq major-mode 'sml-inferior-mode) (goto-char (point-max))))    (setq compilation-parsing-end sml-error-cursor))
682    
683  ;;; Set up the inferior mode keymap, using sml-mode bindings...  (defun sml-make-error (f c)
684      (let ((err (point-marker))
685  (cond ((not inferior-sml-mode-map)          (linenum (string-to-number c))
686         (setq inferior-sml-mode-map (nconc (make-sparse-keymap) comint-mode-map))          (filename (list (first f) (second f)))
687         (install-sml-keybindings inferior-sml-mode-map)          (column (string-to-number (compile-buffer-substring (third f)))))
688         (define-key inferior-sml-mode-map "\C-c\C-s" 'run-sml)      ;; record the end of error, if any
689         (define-key inferior-sml-mode-map "\t"       'comint-dynamic-complete)))      (when (fourth f)
690          (let* ((endline (string-to-number (compile-buffer-substring (fourth f))))
691                 (endcol (string-to-number (compile-buffer-substring (fifth f))))
692                 (linediff (- endline linenum)))
693            (push (list err linediff (if (= 0 linediff) (- endcol column) endcol))
694                  sml-endof-error-alist)))
695        ;; build the error descriptor
696        (if (string= (car sml-temp-file) (first f))
697            ;; special case for code sent via sml-send-region
698            (let ((marker (cdr sml-temp-file)))
699              (with-current-buffer (marker-buffer marker)
700                (goto-char marker)
701                (forward-line (1- linenum))
702                (forward-char (1- column))
703                (cons err (point-marker))))
704          ;; taken from compile.el
705          (list err filename linenum column))))
706    
707    (defadvice compilation-goto-locus (after sml-endof-error activate)
708      (let* ((next-error (ad-get-arg 0))
709             (err (car next-error))
710             (pos (cdr next-error))
711             (endof (with-current-buffer (marker-buffer err)
712                      (assq err sml-endof-error-alist))))
713        (if (not endof) (sml-error-overlay 'undo)
714          (with-current-buffer (marker-buffer pos)
715            (goto-char pos)
716            (let ((linediff (second endof))
717                  (coldiff (third endof)))
718              (when (> 0 linediff) (forward-line linediff))
719              (forward-char coldiff))
720            (sml-error-overlay nil pos (point))
721            (push-mark nil t (not sml-error-overlay))
722            (goto-char pos)))))
723    
724    (defun sml-error-overlay (undo &optional beg end)
725      "Move `sml-error-overlay' so it surrounds the text region in the
726    current buffer. If the buffer-local variable `sml-error-overlay' is
727    non-nil it should be an overlay \(or extent, in XEmacs speak\)\; this
728    function moves the overlay over the current region. If the optional
729    BUFFER argument is given, move the overlay in that buffer instead of
730    the current buffer.
731    
732    Called interactively, the optional prefix argument UNDO indicates that
733    the overlay should simply be removed: \\[universal-argument] \
734    \\[sml-error-overlay]."
735      (interactive "P")
736      (when sml-error-overlay
737        (unless (overlayp sml-error-overlay)
738          (let ((ol sml-error-overlay))
739            (setq sml-error-overlay (make-overlay 0 0))
740            (overlay-put sml-error-overlay 'face (if (symbolp ol) ol 'region))))
741        (if undo
742            (move-overlay sml-error-overlay 1 1 (current-buffer))
743          ;; if active regions, signals mark not active if no region set
744          (let ((beg (or beg (region-beginning)))
745                (end (or end (region-end))))
746            (move-overlay sml-error-overlay beg end (current-buffer))))))
747    
748    ;; ;;;###autoload
749    ;; (defun sml-next-error (skip)
750    ;;   "Find the next error by parsing the inferior ML buffer.
751    ;; A prefix argument means `sml-skip-errors' (qv) instead.
752    
753    ;; Move the error message on the top line of the window\; put the cursor
754    ;; \(point\) at the beginning of the error source.
755    
756    ;; If the error message specifies a range, and `sml-error-parser' returns
757    ;; the range, the mark is placed at the end of the range. If the variable
758    ;; `sml-error-overlay' is non-nil, the region will also be highlighted.
759    
760    ;; If `sml-error-parser' returns a fifth component this is assumed to be
761    ;; a string to indicate the nature of the error: this will be echoed in
762    ;; the minibuffer.
763    
764    ;; Error interaction only works if there is a real file associated with
765    ;; the input -- though of course it also depends on the compiler's error
766    ;; messages \(also see documantation for `sml-error-parser'\).
767    
768    ;; However: if the last text sent went via `sml-load-file' (or the temp
769    ;; file mechanism), the next error reported will be relative to the start
770    ;; of the region sent, any error reports in the previous output being
771    ;; forgotten. If the text went directly to the compiler the succeeding
772    ;; error reported will be the next error relative to the location \(in
773    ;; the output\) of the last error. This odd behaviour may have a use...?"
774    ;;   (interactive "P")
775    ;;   (if skip (sml-skip-errors) (sml-do-next-error)))
776    
777    ;; (defun sml-do-next-error ()
778    ;;   "The business end of `sml-next-error' (qv)"
779    ;;   (let ((case-fold-search nil)
780    ;;         ;; set this variable iff we called sml-next-error in a SML buffer
781    ;;         (sml-window (if (memq major-mode sml-source-modes) (selected-window)))
782    ;;         (proc-buffer (sml-proc-buffer)))
783    ;;     ;; undo (don't destroy) the previous overlay to be tidy
784    ;;     (sml-error-overlay 'undo 1 1
785    ;;                        (and sml-error-file (get-file-buffer sml-error-file)))
786    ;;     ;; go to interaction buffer but don't raise it's frame
787    ;;     (pop-to-buffer (sml-proc-buffer))
788    ;;     ;; go to the last remembered error, and search for the next one.
789    ;;     (goto-char sml-error-cursor)
790    ;;     (if (not (re-search-forward sml-error-regexp (point-max) t))
791    ;;         ;; no more errors -- move point to the sml prompt at the end
792    ;;         (progn
793    ;;           (goto-char (point-max))
794    ;;           (if sml-window (select-window sml-window)) ;return there, perhaps
795    ;;           (message "No error message(s) found."))
796    ;;       ;; error found: point is at end of last match; set the cursor posn.
797    ;;       (set-marker sml-error-cursor (point))
798    ;;       ;; move the SML window's text up to this line
799    ;;       (set-window-start (get-buffer-window proc-buffer) (match-beginning 0))
800    ;;       (let* ((pos)
801    ;;              (parse (funcall sml-error-parser (match-beginning 0)))
802    ;;              (file (nth 0 parse))
803    ;;              (line0 (nth 1 parse))
804    ;;              (col0 (nth 2 parse))
805    ;;              (line/col1 (nth 3 parse))
806    ;;              (msg (nth 4 parse)))
807    ;;         ;; Give up immediately if the error report is scribble
808    ;;         (if (or (null file) (null line0))
809    ;;             (error "Failed to parse/locate this error properly!"))
810    ;;         ;; decide what to do depending on the file returned
811    ;;         (when (string= file "std_in")
812    ;;        ;; presently a fundamental limitation i'm afraid.
813    ;;        (error "Sorry, can't locate errors on std_in."))
814    ;;      ;; jump to the beginning
815    ;;      (if (string= file (car sml-temp-file))
816    ;;          (let* ((maker (cdr sml-temp-file))
817    ;;                 (buf (marker-buffer marker)))
818    ;;            (display-buffer buf)
819    ;;            (set-buffer buf)
820    ;;            (goto-char marker))
821    ;;        (unless (file-readable-p file) (error "Can't read %s" file))
822    ;;           ;; instead of (find-file-other-window file) to lookup the file
823    ;;           (find-file-other-window file)
824    ;;           ;; no good if the buffer's narrowed, still...
825    ;;           (goto-char (point-min)))
826    ;;      ;; jump to the error
827    ;;      (forward-line (1- line0))
828    ;;      (forward-char (1- col0))
829    ;;      ;; point is at start of error text; seek the end.
830    ;;      (let ((start (point))
831    ;;            (end (and line/col1
832    ;;                      (condition-case nil
833    ;;                          (progn (eval line/col1) (point))
834    ;;                        (error nil)))))
835    ;;        ;; return to start anyway
836    ;;        (goto-char start)
837    ;;        ;; if point went to end, put mark there, and maybe highlight
838    ;;        (if end (progn (push-mark end t)
839    ;;                       (sml-error-overlay nil start end)))
840    ;;        (setq sml-error-file file)   ; remember this for next time
841    ;;        (if msg (message msg))))))) ; echo the error/warning message
842    
843    ;; (defun sml-skip-errors ()
844    ;;   "Skip past the rest of the errors."
845    ;;   (interactive)
846    ;;   (if (memq major-mode sml-source-modes) (sml-error-overlay 'undo))
847    ;;   (with-current-buffer (sml-proc-buffer) (sml-update-cursor))
848    ;;   (if (eq major-mode 'sml-inferior-mode) (goto-char (point-max))))
849    
850  ;;; 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
851    
# Line 999  Line 862 
862  (run-hooks 'inferior-sml-load-hook)  (run-hooks 'inferior-sml-load-hook)
863    
864  ;;; Here is where sml-proc.el ends  ;;; Here is where sml-proc.el ends
865    (provide 'sml-proc)

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

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