> Here's a little wishlist item for those minds more capable than
> mine...
> I often run into type mismatch errors in deeply nested type terms (see
> example below, from some typical broken combinator-based parser
> code). I would *love* to have xemacs sml-mode just highlight in red
> that I messed up and am trying to pass a DECL_INFO list instead of a
> simple DECL_INFO. These messages are just too painful and tedious to
> parse and compare by hand! One bright red highlighted term would be
> worth a thousand words :-)
> The general case would likely be hard, but I'd think that a simple
> error message parser with a comparison or unification algorithm would
> be able to identify obvious conflicts. The usual errors I see in my
> development are of the form shown below, with occasional problems due
> to value restriction (can't bind a concrete to a 'Z type).
> While I've seen references to stand-alone type error slicing and
> various little toy tools, I'm wondering if there is a way to integrate
> a simple error message scanner/highlighter into xemacs sml-mode.
The patch below to sml-proc.el does just that: when visiting such an error
with C-x ` (or by clicking on it), the differences between the two types
are highlighted.
This presumes you're using a *very* recent version of Emacs (i.e. built
from
the CVS trunk). If you don't want to build your own Emacs, then you can
try
it with Emacs-22 together with the CVS version of smerge-mode.el which you
can download from
http://cvs.savannah.gnu.org/viewvc/*checkout*/emacs/lisp/smerge-mode.el?revision=HEAD&root=emacs
This has been *very* lightly tested, and I'd like to add it to the next
version of sml-mode, so any feedback is welcome.
Stefan
Index: sml-proc.el
===================================================================
--- sml-proc.el (revision 2721)
+++ sml-proc.el (working copy)
@[EMAIL PROTECTED]
-308,6 +308,29 @[EMAIL PROTECTED]
(progn (call-interactively 'run-sml)
(get-buffer-process (current-buffer)))))
+(defun inferior-sml-next-error-hook ()
+ ;; Try to recognize SML/NJ type error message and to highlight finely
the
+ ;; difference between the two types (in case they're large, it's not
+ ;; always obvious to spot it).
+ (save-current-buffer
+ (when (and (derived-mode-p 'sml-mode 'inferior-sml-mode)
+ (boundp 'next-error-last-buffer)
+ (bufferp next-error-last-buffer)
+ (set-buffer next-error-last-buffer)
+ (derived-mode-p 'inferior-sml-mode)
+ ;; The position of `point' is not guaranteed :-(
+ (looking-at ".*\n operator domain: "))
+ (save-excursion
+ (let ((b1 (match-end 0))
+ e1 b2 e2)
+ (when (re-search-forward "\n in expression:\n" nil t)
+ (setq e2 (match-beginning 0))
+ (when (re-search-backward "\n operand: " b1 t)
+ (setq e1 (match-beginning 0))
+ (setq b2 (match-end 0))
+ (smerge-refine-subst b1 e1 b2 e2
+ '((face .
smerge-refined-change))))))))))
+
(define-derived-mode inferior-sml-mode comint-mode "Inferior-SML"
"Major mode for interacting with an inferior ML process.
@[EMAIL PROTECTED]
-354,7 +377,8 @[EMAIL PROTECTED]
TAB file name completion, as in shell-mode, etc.."
(setq comint-prompt-regexp sml-prompt-regexp)
(sml-mode-variables)
-
+ ;; We have to install it globally, 'cause it's run in the *source*
buffer :-(
+ (add-hook 'next-error-hook 'inferior-sml-next-error-hook)
(set (make-local-variable 'font-lock-defaults)
inferior-sml-font-lock-defaults)
;; For sequencing through error messages:


|