Eshel Yaron [Fri, 20 Oct 2023 18:14:01 +0000 (20:14 +0200)]
Expand Top-level documentation
* sweep.texi (Top-level Interaction): New section, replaces...
(Top-level Completion): Remove.
(The Prolog Top-level): Update menu and document ANSI
escape sequence handling.
Eshel Yaron [Fri, 20 Oct 2023 15:58:47 +0000 (17:58 +0200)]
Emit highlighted messages in the top-level
* sweep.pl: Ensure 'library(ansi_term)' gets loaded.
(sweep_top_level_client/4): Set the flag 'verbose' to 'normal' in
order to enable informational messages, and set 'color_term' to 'true'
to enable highlighting when using a pty.
Eshel Yaron [Fri, 20 Oct 2023 14:51:15 +0000 (17:51 +0300)]
Set Prolog flag 'tty_control' to 'true' when using pty
When 'sweeprolog-top-level-use-pty' is non-nil, let the Prolog
top-level thread know that it controls the tty. This affects some
aspects of the top-level interaction, namely in the presence of choice
points. A significant benefit is that Prolog ensures that the tty
does not echo input, so we can stop setting 'comint-process-echoes'
which had the adverse effect of blocking Emacs when output stalls on
non-echoing terminals.
* sweep.pl (sweep_top_level_client/3): Become
'sweep_top_level_client/4'. New argument says whether the top-level
controls the tty.
(sweep_top_level_pty_client/1,sweep_top_level_server_loop_/2): Adjust.
* sweeprolog.el (sweeprolog-top-level-buffer): Stop setting
'comint-process-echoes'.
(sweeprolog-top-level--post-self-insert-function): When using a tty,
send single character responses directly and assume that the top-level
echoes them back.
Teach 'sweeprolog-extract-region-to-predicate' about existentially
quantified goals and lambda terms.
* sweep.pl (sweep_term_variable_names/2): Remove from export list.
* sweep.pl (sweep_extract_goal/2): New public predicate.
* sweeprolog.el (sweeprolog-extract-region-to-predicate): Use it.
* sweeprolog-tests.el: Test it.
* sweep.texi (Extract Goal): Update documentation.
* sweeprolog.el (sweeprolog-query-replace-term-prompt-old)
(sweeprolog-query-replace-term-prompt-new): New faces.
(sweeprolog-query-replace-term): Use them instead of 'diff-mode'
faces.
; Fix filtering of the just created body when extracting goal
* sweeprolog (sweeprolog-extract-region-to-predicate): When searching
and replacing other goals subsumed by the extracted goal, use a more
robust check to filter out the newly created body term from the search
matches.
Extract subsumed goals when extracting goal to predicate
Extend 'sweeprolog-extract-region-to-predicate' with the ability to
replace other goals in the current buffer that are subsumed by the
extracted goal with calls to the predicate this command creates.
'sweeprolog-extract-region-to-predicate' now does this when it is
called with a prefix argument. Also make
'sweeprolog-insert-term-dwim' propagate the prefix argument to
functions in 'sweeprolog-insert-term-functions'.
* sweeprolog.el (sweeprolog-insert-term-dwim): Add ARG argument and
pass it to functions listed...
(sweeprolog-insert-term-functions): ...here. Adjust docstring.
(sweeprolog-maybe-insert-next-clause)
(sweeprolog-maybe-define-predicate)
(sweeprolog-maybe-extract-region-to-predicate): Adjust accordingly.
(sweeprolog-default-new-predicate-location): Go to end of line in case
there's a comment on the last line of the current predicate
definition.
(sweeprolog-query-replace-term-include-match-function): New variable.
(sweeprolog-query-replace-term): Use it.
(sweeprolog-extract-region-to-predicate): Add ALL argument. When
non-nil, suggest replacing all goals in the buffer that are subsumbed
by the extracted goal with calls to the newly defined predicate.
* sweep.texi (Top, Editing Prolog Code): Mention "Term Replace" in
menus.
(Main Features, Architecture, Alternatives): Mark as sections rather
than chapters.
ADDED: new command 'sweeprolog-query-replace-term'
This patch extends the Term Search infrastructure to support
search-and-replace operations. Namely, we replace the predicate
'sweep_term_search/2' with a new predicate 'sweep_term_replace/2' that
subsumes the functionality of the former. The command
'sweeprolog-term-search' is greatly simplified and adjusted to work
with this new predicate, and we introduce a new command,
'sweeprolog-query-replace-term', that exposes the new
search-and-replace facility of 'sweep_term_replace/2' in an
interactive UI inspired by 'query-replace'.
* sweep.pl (sweep_term_search/2): Remove in favor of...
(sweep_term_replace/2): New predicate.
* sweeprolog.el: (sweeprolog-term-replace-edits): New function.
(sweeprolog-term-search): Rewrite.
(sweeprolog-term-search-last-search)
(sweeprolog-term-search-overlays)
(sweeprolog-term-search-repeat-count)
(sweeprolog-term-search-repeat-backward)
(sweeprolog-term-search-repeat-forward)
(sweeprolog-term-search-abort)
(sweeprolog-term-search-in-buffer)
(sweeprolog-term-search-next)
(sweeprolog-term-search-map): Remove, unused.
(sweeprolog-query-replace-term): New command.
(sweeprolog-mode-map): Bind it.
* sweeprolog-tests.el (term-search)
* sweep.texi (Term Search): Adjust.
(Term Replace): New section.
ENHANCED: Support pty top-level communication instead of TCP
Add the ability for top-level buffers to communicate with their
backing threads via pty instead of a local TCP connection. This is
controlled by a new user option, enabled by default on systems where
Emacs can creates a pty.
* sweep.pl (sweep_top_level_start_pty/2): New predicate.
* sweeprolog.el (sweeprolog-top-level-use-pty): New user option.
(sweeprolog-top-level-buffer): Use it.
* sweep.texi (The Prolog Top-level): Document it.
Only extract goals to separate predicates, not data terms
* sweeprolog.el (sweeprolog-context-menu-for-region)
(sweeprolog-maybe-extract-region-to-predicate): Check that the region
starts in a callable position.
(sweeprolog-extract-region-to-predicate): Reanalyze the buffer as a
last step.
* sweep.texi: Adjust.
Only enable right-click actions on region when click is in region
* sweeprolog.el (sweeprolog-context-menu-region-beg-at-click)
(sweeprolog-context-menu-region-end-at-click): New variables.
(sweeprolog-context-menu-function): Let-bind them.
(sweeprolog-context-menu-for-region): Use them to reliably check that
click is actually inside the selected region.
ADDED: New command 'sweeprolog-extract-region-to-predicate'
Add a command for extracting a part of a clause body into a separate
predicate.
* sweep.pl (sweep_term_variable_names/2)
(sweep_goal_may_cut/2): New helper predicates.
* sweeprolog.el (sweeprolog-extract-region-to-predicate): New command.
(sweeprolog-maybe-extract-region-to-predicate): New function.
(sweeprolog-insert-term-functions): Add it.
* sweep.texi (Insert Term DWIM, Extract Goal): Document it.
Eshel Yaron [Thu, 17 Aug 2023 21:39:58 +0000 (23:39 +0200)]
Use 'without-restriction'.
* sweeprolog.el (sweeprolog-analyze-buffer)
(sweeprolog--buffer-string)
(sweeprolog-export-predicate): Use 'without-restriction' instead of
'save-restriction' and 'widen'.
Eshel Yaron [Tue, 8 Aug 2023 18:29:35 +0000 (21:29 +0300)]
Fix feedback in 'sweeprolog-set-prolog-flag'
Similarly to the previous fix for 'sweeprolog-pack-install', this
makes 'sweeprolog-set-prolog-flag' actually report its result, instead
of reporting failure even when successful.
* sweep.pl (sweep_set_prolog_flag/2): Bind the output argument to
non-nil on success.
Eshel Yaron [Mon, 7 Aug 2023 15:48:48 +0000 (18:48 +0300)]
Fix feedback in 'sweeprolog-pack-install'
Have 'sweeprolog-pack-install' actually report its result, instead of
reporting failure even when successful.
* sweep.pl (sweep_pack_install/2): Bind the output argument to non-nil
on success.
* sweeprolog.el (sweeprolog-pack-description-max-width): New user
option.
(sweeprolog-read-pack-name): Use display text properties for alignment
instead of repeated spaces.
This command has been documented since Sweep version 0.6.0 but its
implementation was unintentionally committed. This fixes that.
* sweeprolog.el (sweeprolog-submit-bug-report): New command.
(sweeprolog-menu): Add entry for 'sweeprolog-submit-bug-report'.
* README.org (Setting up Sweep for local development): Capitalize.
(Submitting patches and bug reports): Update.
When a keymap is autoloaded (and the definition is copied over to the
-autoloads.el file), and the function are sharp-quoted, Emacs can
complain about undefined symbols, especially in combination with
'package-quickstart'.
Refactor and enhance 'completion-at-point' support
Replace 'sweeprolog-completion-at-point-functions' with a single
function 'sweeprolog-completion-at-point' that implements a much more
refined context-sensitive decision tree to determine what kind of
completion to perform.