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.
Eshel Yaron [Tue, 27 Jun 2023 18:36:45 +0000 (21:36 +0300)]
Add grouping and affixation functions for module completion
This adds a 'group-function' and an 'affixation-function' to
'sweeprolog-module-completion-table', for Emacs 28+
The affixation API allows us to compute the appropriate padding to
insert before annotations in a cleaner way. Modules are group
according to their classes.
* sweep.pl (sweep_module_class/2): New predicate.
* sweeprolog.el (sweeprolog-module-minibuffer-annotation-1):
Extract helper function from...
(sweeprolog-module-minibuffer-annotation): ...here. Adapt.
(sweeprolog-module-minibuffer-affixation)
(sweeprolog-module-minibuffer-group): New functions.
(sweeprolog-module-completion-table): Use them.
* sweeprolog.el (sweeprolog-module-completion-table)
(sweeprolog-module-p, sweeprolog-module-minibuffer-annotation)
(sweeprolog-module-annotation): New functions.
(sweeprolog-modules-collection)
(sweeprolog-read-module-name): Adapt.
(sweeprolog-find-module): Improve feedback for modules that are not
backed by files.
Eshel Yaron [Fri, 23 Jun 2023 08:59:18 +0000 (11:59 +0300)]
MODIFIED: Replace "faces styles" with a theme emulating PceEmacs
This adds a custom theme called 'sweeprolog-pce' that mimics the
highlighting of SWI-Prolog's built-in editor, PceEmacs. It obsoletes
the "faces styles" feature that Sweep provided thus far. For backward
compatibility, The user option 'sweeprolog-faces-style' is retained
and mostly still respected.
Thanks to Stefan Monnier for suggesting this approach for simplifying
Sweep's code and making it more conformant with Emacs conventions.
* sweeprolog-pce-theme.el: New file.
* sweeprolog.el: Remove 'sweeprolog-defface' macro its
'sweeprolog-*-face' functions, use plain face definitions and refer to
them directly by their names instead. Also extend
'custom-theme-load-path' to include the new sweeprolog-pce-theme.el.
* README.org (Semantic Highlighting): Replace "Available Styles"
subsection with new subsection "PceEmacs Theme".
Eshel Yaron [Sun, 18 Jun 2023 19:32:33 +0000 (22:32 +0300)]
ADDED: Persistent history for Sweep top-levels
This adds a new user option that controls the value of
'comint-input-ring-file-name' in Sweep top-level buffers.
* sweeprolog.el (sweeprolog-top-level-persistent-history): New user
option.
(sweeprolog-top-level-sentinel)
(sweeprolog-top-level-setup-history): New functions.
(sweeprolog-top-level-setup-buffer): Call
'sweeprolog-top-level-setup-history' when creating a new top-level
buffer.
Eshel Yaron [Wed, 14 Jun 2023 07:37:02 +0000 (10:37 +0300)]
FIXED: Correctly recognize DCG grammar rules in 'C-c C-d'
* sweeprolog.el (sweeprolog-beginning-of-predicate-at-point): Also
return the module and neck operator of the predicate at point.
(sweeprolog-insert-predicate-documentation)
(sweeprolog-read-predicate-documentation-function)
(sweeprolog-read-predicate-documentation-with-holes)
(sweeprolog-read-predicate-documentation-default-function)
(sweeprolog-read-predicate-documentation)
(sweeprolog-document-predicate-at-point): Adapt to support DCGs and
non-local predicates.
Eshel Yaron [Tue, 13 Jun 2023 15:54:50 +0000 (18:54 +0300)]
Simplify 'sweeprolog-beginning-of-top-term'
Extract the core of 'sweeprolog-beginning-of-top-term' to
'sweeprolog-beginning-of-top-term-once' and make it leave point at the
very beginning of the top term, rather than at the following
character.
* sweeprolog.el (sweeprolog-beginning-of-top-term-once): New function.
(sweeprolog-beginning-of-top-term): Use it.
(sweeprolog-local-variables-collection)
(sweeprolog-analyze-term)
(sweeprolog-analyze-some-terms)
(sweeprolog-beginning-of-predicate-at-point)
(sweeprolog-terms-at-point): Adapt.
Eshel Yaron [Sun, 11 Jun 2023 18:05:13 +0000 (21:05 +0300)]
ENHANCED: Guess argument names for DCG grammar rules
* sweeprolog.el (sweeprolog-predicate-completion-at-point)
(sweeprolog-insert-clause): Support guessing argument names from
documentation also for DCG grammar rules.
Allow finding modules and predicates in another window with prefix
argument. Also improve prompt for 'sweeprolog-find-predicate'.
* sweeprolog.el (sweeprolog-read-predicate-prompt): Remove trailing
colon and space.
(sweeprolog-predicate-visible-p-function): New user option.
(sweeprolog-read-predicate): Use it, and format PROMPT with predicate
at point as the default argument.
(sweeprolog-find-module)
(sweeprolog-find-predicate): Add optional argument OTHER-WINDOW.
(sweeprolog-describe-predicate): Adapt PROMPT argument passed to
'sweeprolog-read-predicate'.
Eshel Yaron [Thu, 8 Jun 2023 17:46:45 +0000 (20:46 +0300)]
ENHANCED: Improve DCG support
Take into account DCG grammar rules and ensure they're supported all
around. Crucially, allow 'sweeprolog-describe-predicate' to display
documentation for DCG grammar rules.
Eshel Yaron [Thu, 8 Jun 2023 17:33:55 +0000 (20:33 +0300)]
Give a better name to 'sweeprolog--mfn-to-functor-arity'
* sweeprolog.el (sweeprolog--pi-to-functor-arity): New function,
renamed from 'sweeprolog--mfn-to-functor-arity'.
(sweeprolog-native-predicate-location): Use it.
* sweeprolog.el (sweeprolog-declaration-option): New face, used in...
(sweeprolog-analyze-fragment-to-faces): ...for 'decl_option' frags.
(sweeprolog--help-echo-for-declaration-option): New function.
(sweeprolog-analyze-fragment-help-echo): Use it.
Eshel Yaron [Tue, 30 May 2023 19:29:34 +0000 (22:29 +0300)]
ADDED: command for inserting example usage comments
* sweeprolog.el (sweeprolog-top-level-example-mode): New minor mode.
(sweeprolog-make-example-usage-comment): New command.
(sweeprolog-mode-map): Bind it.
* README.org (Example Usage Comments): New section.