Eshel Yaron [Sun, 27 Nov 2022 19:08:14 +0000 (21:08 +0200)]
ENHANCED: use argument names for holes in predicate completion
* sweep.pl (predicate_argument_names/2): new predicate.
(sweep_format_predicate/2): use it, and revise into...
(sweep_format_predicate/4): new predicate.
(sweep_predicate_completion_candidates): use it.
Eshel Yaron [Sat, 26 Nov 2022 14:10:04 +0000 (16:10 +0200)]
ADDED: make flymake optionally complain about implicit autoloads
* sweeprolog.el (sweeprolog-note-implicit-autoloads): new user-option.
(sweeprolog-analyze-fragment-flymake): use it.
* README.org ("Managing Dependencies"): mention it.
Eshel Yaron [Fri, 25 Nov 2022 21:01:40 +0000 (23:01 +0200)]
Adjust arity of predicates according to completion context
* sweep.pl (sweep_context_callable): track required arity adjustment.
(sweep_predicate_completion_candidates): take arity difference as
argument, adjust and filter candidates according to it.
* sweeprolog.el (sweeprolog-predicate-completion-at-point): use it.
* sweeprolog-tests.el: test it.
Eshel Yaron [Wed, 23 Nov 2022 19:25:39 +0000 (21:25 +0200)]
ADDED: PlUnit tests block skeleton and command for inserting it
* sweeprolog.el (sweeprolog-format-string-as-atom): new function.
(sweeprolog-module-header-skeleton): use define-skeleton, making it a
command instead of a defconst.
(sweeprolog-plunit-testset-skeleton): new skeleton and command.
* sweeprolog-tests: test it.
* README.org ("Writing Tests"): new section.
("Using templates for creating new modules"): rename to "Creating New
Modules".
Eshel Yaron [Tue, 22 Nov 2022 18:14:46 +0000 (20:14 +0200)]
Handle module-qualification in next-clause insertion
* sweeprolog.el (sweeprolog-definition-at-point): also return module
name when the head term is qualified.
(sweeprolog-maybe-insert-next-clause): pass module name to...
(sweeprolog-insert-clause): new argument module.
* sweeprolog-tests.el: add a couple of relevant test cases.
Eshel Yaron [Tue, 22 Nov 2022 10:59:41 +0000 (12:59 +0200)]
FIXED: sweeprolog-beginning-of-next-top-term: other possible loop
* sweeprolog.el (sweeprolog-beginning-of-next-top-term): don't loop
when called in the last term of the buffer
* sweeprolog-tests.el (beginning-of-next-top-term-at-last-clause): new
test case
Eshel Yaron [Sun, 20 Nov 2022 19:31:11 +0000 (21:31 +0200)]
Support DCG and SSU rules in sweeprolog-insert-next-clause
* sweeprolog.el (sweeprolog-definition-at-point): also return kind of
neck.
(sweeprolog-maybe-insert-next-clause): pass it to...
(sweeprolog-insert-next-clause): new argument NECK used instead of
hardcoded ":-", use "Body" for clause body instead of "_".
(sweeprolog-identifier-at-point): handle raw meta goals.
* sweeprolog-tests.el: add tests for sweeprolog-insert-term-dwim
inserting clauses with different neck kinds.
Eshel Yaron [Sat, 19 Nov 2022 16:38:32 +0000 (18:38 +0200)]
FIXED: exporting predicates in presence of exported operators
* sweep.pl (sweep_exportable_predicates/2): new predicate.
* sweeprolog.el (sweeprolog--module-term)
(sweeprolog--exportable-predicates)
(sweeprolog-analyze-start-exportable)
(sweeprolog-analyze-fragment-exportable): no longer used, deleted.
(sweeprolog-exportable-predicates): new function.
(sweeprolog-read-exportable-predicate): use it.
(sweeprolog-export-predicate): handle exported operators.
Eshel Yaron [Tue, 15 Nov 2022 22:43:51 +0000 (00:43 +0200)]
Don't highlight syntax error at the end of the buffer
* sweeprolog.el (sweeprolog--analyze-point): new buffer local
variable.
(sweeprolog-analyze-buffer, sweeprolog-analyze-some-terms): let-bind
it.
(sweeprolog-analyze-fragment-to-faces): check it before applying
sweeprolog-syntax-error-face.
Eshel Yaron [Tue, 15 Nov 2022 21:45:02 +0000 (23:45 +0200)]
Start the top-level TCP server just-in-time
* sweeprolog.el (sweeprolog-init): do not start TCP server
unconditionally
(sweeprolog-top-level): start it here instead, on demand.
* sweep.pl (sweep_top_level_server/2): wait for TCP server thread to
start before returning control to Emacs.
* README.org (The Prolog Top-Level): add implementation note.
Eshel Yaron [Mon, 14 Nov 2022 16:19:31 +0000 (18:19 +0200)]
ADDED: minor mode for automatic whitespace insertion
* sweep.pl (sweep_context_callable/2): only consider the context to be
callable if a neck is present up the tree, i.e. not in the head.
* sweeprolog.el (sweeprolog-context-callable-p): new function,
extracted from (sweeprolog-predicate-completion-at-point)
(sweeprolog-electric-layout-post-self-insert-function): new function.
(sweeprolog-electric-layout-mode): new minor mode.
Eshel Yaron [Sat, 12 Nov 2022 20:38:54 +0000 (22:38 +0200)]
ENHANCED: revise predicate completion at point
Completion at point now detects whether predicate completion is
appropriate, by parsing Prolog code back from point to determine the
context of point. If predicate completion is not appropriate,
fallback to atom completion.
Eshel Yaron [Fri, 11 Nov 2022 10:39:58 +0000 (12:39 +0200)]
ADDED: user option specifying where to define new predicates
* sweeprolog.el (sweeprolog-default-new-predicate-location)
(sweeprolog-new-predicate-location-above-current): new functions.
(sweeprolog-new-predicate-location-function): new user option.
(sweeprolog-maybe-define-predicate): use it.
Eshel Yaron [Tue, 25 Oct 2022 06:44:46 +0000 (09:44 +0300)]
ADDED: completion-at-point for variable names
* sweeprolog.el (sweeprolog-local-variables-collection,
sweeprolog-variable-completion-at-point): new
functions. (sweeprolog-mode): add to
completion-at-point-functions. (sweeprolog-mode-syntax-table): update
according to char_type(Char, prolog_symbol).
Eshel Yaron [Sat, 22 Oct 2022 16:10:08 +0000 (19:10 +0300)]
ADDED: context-based command for inserting new clauses or terms
* sweeprolog.el (sweeprolog--forward-hole, sweeprolog--backward-hole):
new functions.
(sweeprolog-forward-hole): new command.
(sweeprolog-end-of-predicate-definition,sweeprolog-insert-clause,
sweeprolog-maybe-insert-next-clause,
sweeprolog-maybe-define-predicate): new functions.
(sweeprolog-insert-term-functions): new hook.
(sweeprolog-insert-term-dwim): new command.
(sweeprolog-mode-map): bind new commands.
* sweeprolog-tests.el (dwim-define-predicate): new test case.
* README.org (Context-Based Term Insertion): new section.
Eshel Yaron [Fri, 21 Oct 2022 08:32:10 +0000 (11:32 +0300)]
ENHANCED: add predicate properties list in help buffers
* sweep.pl (sweep_predicate_properties/2): new predicate.
* sweeprolog.el (sweeprolog--render-predicate-properties): new
function.
(sweeprolog--describe-predicate): use it.
Eshel Yaron [Thu, 20 Oct 2022 19:38:43 +0000 (22:38 +0300)]
ENHANCED: load and initialize sweep-module just-in-time
Instead of loading sweep-module and initializing Prolog as part of
loading sweeprolog.el (subject to the user option
sweeprolog-init-on-load), this commit introduces just-in-time loading
and initialization of Prolog. Suggested by Stefan Monnier.
* sweeprolog.el: (sweeprolog--open-query): new function, wraps
sweeprolog-open-query and initializes Prolog on the first call. Used
in place of sweeprolog-open-query throughout.
(sweeprolog-init-on-load): make variable obsolete.
Eshel Yaron [Wed, 19 Oct 2022 05:38:34 +0000 (08:38 +0300)]
ENHANCED: teach sweep to jump to C code for built-in predicates
* sweeprolog.el:
- sweeprolog-swipl-sources: new user option.
- sweeprolog-native-predicate-location: new function.
- sweeprolog-predicate-location: use it.
- README.org: Built-in Native Predicates: new section.
Eshel Yaron [Mon, 17 Oct 2022 07:56:27 +0000 (10:56 +0300)]
ADDED: new command for showing help for Prolog predicates
* sweep.pl: sweep_predicate_html_documentation/2: new predicate
* sweeprolog.el:
- sweeprolog-read-predicate-history: new variable.
- sweeprolog-read-predicate: use it, and default to the predicate at
point.
- sweeprolog--colour-term-to-faces: quote symbol
- sweeprolog-describe-predicate: new command.
- sweeprolog-help-prefix-map: bind it.
* README.org: Prolog Help: mention it.