Eshel Yaron [Thu, 16 Feb 2023 12:34:45 +0000 (14:34 +0200)]
ADDED: mode line indication for loaded buffers
* sweep.pl (sweep_source_file_load_time/2): new predicate.
(sweep_load_buffer/2): also update source modification time based.
* sweeprolog.el (sweeprolog-buffer-load-time)
(sweeprolog-buffer-loaded-since-last-modification-p): new functions.
(sweeprolog-load-buffer): use it.
(sweeprolog-mode): add mode line indication if buffer is loaded.
Eshel Yaron [Mon, 13 Feb 2023 18:35:10 +0000 (20:35 +0200)]
MODIFIED: sweeprolog-update-dependencies choice of directives
* sweeprolog.el (sweeprolog-dependency-directive): New user option.
Determines which directive to use in...
(sweeprolog-update-dependencies): Fix edge cases in finding where to
insert new directives. Optionally infer directive to add based on
current buffer contents.
Eshel Yaron [Tue, 7 Feb 2023 19:57:30 +0000 (21:57 +0200)]
ADDED: new commands for managing numbered variables
* sweeprolog.el (sweeprolog-increment-numbered-variables)
(sweeprolog-decrement-numbered-variables): new commands.
(sweeprolog-mode-map): bind them to C-c C-+ and C-c C--.
(sweeprolog-context-menu-for-variable): allow calling these new
commands from context menus for numbered variables.
* sweeprolog-tests.el: add test for incrementing numbered variables.
* README.org (Numbered Variables): new manual section.
Eshel Yaron [Sat, 4 Feb 2023 21:09:23 +0000 (23:09 +0200)]
ENHANCED: handle renaming variables to existing variable names
* sweeprolog.el (sweeprolog-rename-variable-allow-existing): new user
option, used by...
(sweeprolog-read-new-variable-try): new command, exists the minibuffer
if it contains a valid variable name. It checks if the selected
variable name already exists. Used by...
(sweeprolog-read-new-variable): new function, reads a Prolog variable
name in the minibuffer with a dedicated exit command.
(sweeprolog-rename-variable): use it.
Eshel Yaron [Wed, 1 Feb 2023 18:09:39 +0000 (20:09 +0200)]
Avoid moving cursor while renaming variables from context menu
* sweeprolog.el (sweeprolog-analyze-term-at-point): new optional
argument POINT.
(sweeprolog-rename-variable): use it instead of moving point during
prompting to avoid the cursor being displayed at the click position
when called from the context menu.
Eshel Yaron [Wed, 1 Feb 2023 16:28:09 +0000 (18:28 +0200)]
ENHANCED: provide exact buffer positions for cross references
* sweep.pl (reference_span/5): new predicate.
(sweep_predicate_references/2): use it to find exact character offset of
predicate references.
* sweeprolog.el (xref-backend-references): adapt accordingly.
Eshel Yaron [Sun, 29 Jan 2023 21:35:33 +0000 (23:35 +0200)]
ADDED: command for renaming a variable in Prolog term
* sweeprolog.el (sweeprolog-rename-variable): new command.
(sweeprolog-context-menu-rename-variable): new command used in context
menus for variables.
(sweeprolog-context-menu-for-variable): new function, used in...
(sweeprolog-context-menu-functions): add it to the list.
(sweeprolog-mode-map): bind it to C-c C-r.
* README.org (Renaming Variables): new section.
Eshel Yaron [Sat, 28 Jan 2023 16:38:00 +0000 (18:38 +0200)]
ENHANCED: use docs from the SWI-Prolog manual to guess hole names
* sweep.pl (predicate_argument_names/2): also consult the SWI-Prolog
manual via pldoc_man:load_man_object/4 to find argument names for
built-in predicates.
Eshel Yaron [Thu, 26 Jan 2023 15:21:09 +0000 (17:21 +0200)]
ADDED: numeric argument for sweeprolog-forward/backward-hole
* sweeprolog.el (sweeprolog-count-holes): new command, counts holes
in the current buffer.
(sweeprolog-forward-hole, sweeprolog-backward-hole): new numeric
argument, corresponding to the prefix argument when called
interactively. With positive/negative numeric argument, move over
that many holes. With zero numeric argument, call
sweeprolog-count-holes instead.
Eshel Yaron [Mon, 23 Jan 2023 18:20:02 +0000 (20:20 +0200)]
yank holes back as plain variables
* sweeprolog.el (sweeprolog-mode): add sweeprolog-hole to
yank-excluded-properties buffer-locally.
* sweeprolog-tests.el: test it.
* README.org (Holes): mention it.
Eshel Yaron [Sun, 22 Jan 2023 06:13:15 +0000 (08:13 +0200)]
ADDED: command to pipe output of Prolog goals to Emacs buffers
* sweep.c (sweep_open_channel(), sweep_fd_open()): new helper
functions for obtaining Prolog streams from Emacs pipe buffers.
* sweep.pl (sweep_async_goal/2, sweep_interrupt_async_goal/2): new
predicates.
* sweeprolog.el (sweeprolog-async-goal): new command, executes a goal
in a separate thread and redirects its output to a buffer with mode..
(sweeprolog-async-goal-output-mode): new major mode, derived from
Compilation mode.
(sweeprolog-mode-map, sweeprolog-prefix-map, sweeprolog-menu): bind
sweeprolog-async-goal.
* README.org (Executing Prolog Asynchronously): new manual section.
Eshel Yaron [Fri, 20 Jan 2023 18:45:14 +0000 (20:45 +0200)]
ENHANCED: consult with library index for finding predicate defs
* sweep.pl (sweep_predicate_location_/4): also check library_index/3.
* sweeprolog-tests.el: add test for finding the source location of a
predicate in the package clib.
Eshel Yaron [Thu, 19 Jan 2023 09:15:35 +0000 (11:15 +0200)]
ADDED: right-click context menus in sweeprolog-mode
* sweeprolog.el (sweeprolog-context-menu-find-module)
(sweeprolog-context-menu-find-module-other-window)
(sweeprolog-context-menu-describe-module)
(sweeprolog-context-menu-find-file)
(sweeprolog-context-menu-find-file-other-window)
(sweeprolog-context-menu-describe-predicate): new commands, add to context menus by...
(sweeprolog-context-menu-for-predicate)
(sweeprolog-context-menu-for-module)
(sweeprolog-context-menu-for-file): new functions, used in...
(sweeprolog-context-menu-functions): new abnormal hook, used by...
(sweeprolog-context-menu-function): new function.
(sweeprolog-mode): add it to context-menu-functions.
Eshel Yaron [Mon, 16 Jan 2023 19:02:03 +0000 (21:02 +0200)]
ADDED: short description for tokens on mouse hover (help-echo)
* sweep.pl (sweep_predicate_dependencies/2): new predicate.
* sweeprolog.el (sweeprolog-enable-help-echo): new user-option, when
non-nil sweeprolog-analyze-region-start-hook and
sweeprolog-analyze-region-fragment-hook are extended with...
(sweeprolog-analyze-start-help-echo)
(sweeprolog-analyze-fragment-help-echo): new functions, manage the
help-echo text property for Prolog text.
* README.org ("Hover for Help"): new section about help-echo.
Eshel Yaron [Mon, 16 Jan 2023 18:58:31 +0000 (20:58 +0200)]
ENHANCED: improve semantic highlighting for several constructs
* sweep.pl (sweep_color_normalized_/4): fix handling of non-callable
terms, propagate type error expected type to Elisp.
(sweeprolog_goal_kind_normalized/2): rename to...
(sweep_goal_kind_normalized/2): normalize all goal and head classes.
* sweeprolog.el (sweeprolog-analyze-fragment-to-faces): adapt to new
info from sweep_goal_kind_normalized/2, and highlight some missing
token kinds.
Eshel Yaron [Thu, 12 Jan 2023 11:27:17 +0000 (13:27 +0200)]
ADDED: command for sending a goal to top-level from any buffer
* sweeprolog.el (sweeprolog-top-level): extract buffer setup logic to...
(sweeprolog-top-level-buffer): new function.
(sweeprolog-top-level-send-string): new function, used by...
(sweeprolog-top-level-send-goal): new command, reads a goal from the
minibuffer and sends it to a Prolog top-level buffer.
(sweeprolog-mode-map): bind it to C-c C-q.
(sweeprolog-menu): add "Send Goal to Top-level" entry.
* README.org ("Sending Goals to the Top-level"): new manual section.
Eshel Yaron [Thu, 12 Jan 2023 11:22:21 +0000 (13:22 +0200)]
Support completion when reading a goal from the minibuffer
* sweeprolog.el (sweeprolog-read-goal-map): new keymap, derived from
sweeprolog-read-term-map.
(sweeprolog-goals-at-point): new function, similar to
sweeprolog-terms-at-point but only returns goal terms.
(sweeprolog-read-goal): use them.
Eshel Yaron [Sat, 7 Jan 2023 06:20:01 +0000 (08:20 +0200)]
ENHANCED: use terms at point as "future history" for term-search
* sweep.pl (sweep_terms_at_point/2): new predicate.
* sweeprolog.el (sweeprolog-terms-at-point): new function.
(sweeprolog-read-term): use it for setting the future history.
(sweeprolog-read-goal): new function.
(sweeprolog-term-search): use it for reading a goal when called with
prefix argument.
Eshel Yaron [Fri, 6 Jan 2023 07:16:33 +0000 (09:16 +0200)]
ENHANCED: Support refining term searches with arbitrary goals
* sweep.pl (sweep_term_search/2): extend with an extra goal argument.
* sweeprolog.el (sweeprolog-read-term): new function, similar to
read--expression but for Prolog terms rather than Elisp expressions.
(sweeprolog-term-search): use it, and prompt for goal with prefix arg.
Eshel Yaron [Tue, 3 Jan 2023 22:22:34 +0000 (00:22 +0200)]
ADDED: command for finding terms subsumed by a given term
* sweep.pl (sweep_term_search/2): new predicate.
* sweeprolog.el (sweeprolog-term-search-in-buffer): new function.
(sweeprolog-term-search): new command.
* README.org ("Term Search"): new manual section.
Eshel Yaron [Sun, 1 Jan 2023 12:32:01 +0000 (14:32 +0200)]
ADDED: user option to control predicate documentation composition
* sweeprolog.el
(sweeprolog-insert-pldoc-for-predicate): remove in favor of...
(sweeprolog-insert-predicate-documentation): new function.
(sweeprolog-format-term-with-holes): new utility
function, used by...
(sweeprolog-read-predicate-documentation-with-holes)
(sweeprolog-read-predicate-documentation-default-function): new
functions, used for...
(sweeprolog-read-predicate-documentation-function): new user option,
used by...
(sweeprolog-read-predicate-documentation): new function, used by...
(sweeprolog-document-predicate-at-point): refactor.
Eshel Yaron [Sat, 31 Dec 2022 11:10:17 +0000 (13:10 +0200)]
Avoid excessive analysis in presence of unbalanced quotes
* sweeprolog.el (sweeprolog-analyze-fragment-fullstop): new function,
adds a dedicated text property to fullstops.
(sweeprolog-analyze-region-fragment-hook): add it.
(sweeprolog-at-fullstop-p)
(sweeprolog-end-of-last-fullstop, sweeprolog-end-of-next-fullstop):
new functions.
(sweeprolog-end-of-top-term): use them for restricting to region
between last fullstop and next fullstop.
Eshel Yaron [Thu, 22 Dec 2022 14:51:47 +0000 (16:51 +0200)]
ADDED: New command sweeprolog-insert-term-with-holes
* sweep.pl (sweep_format_term/2, sweep_current_functors/2): new
predicates.
* sweeprolog.el (sweeprolog-read-functor-history): new variable,
history list for...
(sweeprolog-read-functor): new function.
(sweeprolog-forward-hole-repeat-mode): rename to...
(sweeprolog-forward-hole-repeat-map): corrected name for keymap.
(sweeprolog-analyze-end-font-lock): don't rely on
sweeprolog--next-hole to move point.
(sweeprolog-at-hole-p, sweeprolog-beginning-of-hole)
(sweeprolog-end-of-hole): new functions, used by...
(sweeprolog--previous-hole, sweeprolog--next-hole): revise.
(sweeprolog--precedence-at-point): new function, used by...
(sweeprolog-insert-term-with-holes): new command.
(sweeprolog-mode-map): bind it to C-c C-m
* sweeprolog-tests: test it.
* README.org ("Filling Holes"): move to top and rename to...
("Holes"): document sweeprolog-insert-term-with-holes.
Eshel Yaron [Wed, 21 Dec 2022 17:51:48 +0000 (19:51 +0200)]
ENHANCED: highlight holes in incomplete terms
* sweeprolog.el (sweeprolog-predicate-completion-at-point): fontify
holes when inserting them.
(sweeprolog-analyze-start-font-lock): reset font-lock-face in analyzed
region.
(sweeprolog-analyze-fragment-to-faces): fix syntax error handling,
don't highlight holes as it is done by...
(sweeprolog-analyze-end-font-lock): new function, highlights holes in
analyzed region when sweeprolog-highlight-holes is non-nil.
(sweeprolog-analyze-region-end-hook): add it.
(sweeprolog--hole): fix text property used for setting stickiness.
Eshel Yaron [Fri, 16 Dec 2022 22:02:33 +0000 (00:02 +0200)]
Use indent-to instead manually indenting with spaces
* sweeprolog.el (sweeprolog-indent-line): use indent-to.
(sweeprolog-indent-offset): tweak docstring.
(sweeprolog-indent-line-after-prefix): use it instead of hard-coded
offset.
(sweeprolog-export-predicate): don't override indent-tabs-mode.
Eshel Yaron [Sun, 4 Dec 2022 17:09:30 +0000 (19:09 +0200)]
Use built-in file_autoload_directives/3 to update deps
* sweep.pl (sweep_file_missing_dependencies/2): new predicate.
* sweeprolog.el (sweeprolog-update-dependencies): use it.
* sweeprolog-tests.el: add another test case for
sweeprolog-update-dependencies.
Eshel Yaron [Sat, 3 Dec 2022 16:09:18 +0000 (18:09 +0200)]
ADDED: ability to pass command line args directly to swipl
* sweeprolog.el (sweeprolog-handle-command-line-args): new function,
sets up command line argument handling using...
(sweeprolog-command-line-function): new function.
Eshel Yaron [Fri, 2 Dec 2022 11:41:32 +0000 (13:41 +0200)]
ADDED: minor mode for moving to the next hole with TAB
* sweeprolog.el (sweeprolog-forward-hole-on-tab-mode): new minor mode,
binding TAB to...
(sweeprolog-indent-or-forward-hole): new command.
* README.org ("Filling Holes"): rephrase and mention new minor mode.
Eshel Yaron [Fri, 2 Dec 2022 09:47:58 +0000 (11:47 +0200)]
ENHANCED: indentation after infix operators
* sweeprolog.el (sweeprolog-indent-line-after-infix): adhere to last line
indentation even if non-standard, handle DCG RHS contexts and SSU
guards.
* sweeprolog-tests.el: add more tests for indentation.