[climacs-devel] command handlers for parse errors
Andreas Fuchs
asf at boinkor.net
Wed May 3 18:09:39 UTC 2006
Today, Christophe Rhodes <csr21 at cam.ac.uk> wrote:
> but I think I have a better way, buried in amongst all the other
> mutations I have accumulated.
>
> The trick is to define a stream-accept method for the ESA
> minibuffer: something like
>
> (defmethod stream-accept :around ((pane minibuffer-pane) type &rest args)
> (declare (ignore args))
> ;; FIXME: this isn't the friendliest way of indicating a parse
> ;; error: there's no feedback, unlike emacs' quite nice "[no
> ;; match]".
> (loop
> (handler-case
> (return (call-next-method))
> (parse-error ()
> nil))))
>
> This causes the failing accept to be re-entered, which does almost
> the right thing; with my command processor it clears the window and
> re-prompts, but it doesn't re-insert the text the user entered
> because there's no documented way of getting hold of that in a
> parse-error (completion-error, input-not-of-required-type -- well,
> the latter /might/ allow for getting hold of the string; it's not
> completely clear to me).
As stream-accept operates on extended input streams, we should be able
to use the extended input stream protocol to get the string content of
the stream:
(defun save-input-line (stream frame)
(when (current-receiver frame)
(let ((buffer (stream-input-buffer stream)))
(setf (incomplete-input (current-receiver frame))
(with-output-to-string (s)
(loop for elt across buffer
if (characterp elt)
do (write-char elt s))))
(incomplete-input (current-receiver frame)))))
is what we use in beirc. Stream corresponds to the pane's extended
input stream, of course, and if that works, you can do with the input
whatever you want. (:
In beirc, we have to replace the input with :rescan t, which will barf
again on malformed input, but I'm sure your command reader is smart
enough not to do that (:
Cheers,
--
Andreas Fuchs, (http://|im:asf@|mailto:asf@)boinkor.net, antifuchs
More information about the climacs-devel
mailing list