Following a recent discussion on the
emacs-devel mailing list, I’ve added a way in Sweep to extract a goal from the body of a clause into a separate predicate. That can be useful when you want to reuse a complex goal somewhere else.
Here’s an example:
Here’s another example, this time using the mouse:
It aims to be robust, and I think it should work pretty well in most cases. If anybody gives it a try and finds a way to break their code with it, please do tell.
In particular, it’s smart enough to detect cuts that are not safe to extract, and warn you about them.
It also knows about DCGs, and creates a non terminal if you extract a part of a non terminal body.
The relevant documentation in the Sweep manual is here: Extract Goal (Sweep: SWI-Prolog Embedded in Emacs)