[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/sweeprolog adca929818 3/4: Only extract goals to separate
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/sweeprolog adca929818 3/4: Only extract goals to separate predicates, not data terms |
Date: |
Sat, 9 Sep 2023 04:00:18 -0400 (EDT) |
branch: elpa/sweeprolog
commit adca9298186deb836662c07a2ff753bf3965db4a
Author: Eshel Yaron <me@eshelyaron.com>
Commit: Eshel Yaron <me@eshelyaron.com>
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.
---
sweep.texi | 23 ++++++++++++++---------
sweeprolog.el | 19 ++++++++++++-------
2 files changed, 26 insertions(+), 16 deletions(-)
diff --git a/sweep.texi b/sweep.texi
index bd8c459977..820f741b82 100644
--- a/sweep.texi
+++ b/sweep.texi
@@ -2129,8 +2129,8 @@ By default, @code{sweeprolog-insert-term-dwim} tries the
following
insertion functions, in order:
@defun sweeprolog-maybe-extract-region-to-predicate
-If the region is active, extract the selected goal into a separate
-predicate. @xref{Extract Goal}.
+If the region is active and selects a goal, extract the selected goal
+into a separate predicate. @xref{Extract Goal}.
@end defun
@defun sweeprolog-maybe-insert-next-clause
@@ -2334,12 +2334,13 @@ position, and the position of the mouse click. It
should alter the
menu according to that context.
@end defvar
-To enable Context Menu, type @kbd{M-x context-menu-mode @key{RET}} or
-add a call to @code{(context-menu-mode)} in your Emacs initialization
-file to enable it in all future sessions. You access the context menu
-by right-clicking anywhere in Emacs. If you do it in a Sweep Prolog
-mode buffer, you can invoke several Prolog-specific commands based on
-where you click in the buffer.
+To enable Context Menu mode, type @kbd{M-x context-menu-mode
+@key{RET}}. To have Context Menu mode enabled automatically when
+Emacs starts, place a call to @code{(context-menu-mode)} in your Emacs
+initialization file. You can access the context menu by
+right-clicking anywhere in Emacs. If you do it in a Sweep Prolog mode
+buffer, you can invoke several Prolog-specific commands based on where
+you click in the buffer.
If you right-click on a Prolog file specification or module name,
Sweep suggests visiting it either in the current window or in another.
@@ -2347,7 +2348,7 @@ If you right-click on a predicate, it lets you view its
documentation
in a dedicated buffer (@pxref{Prolog Help}). For variables, it
enables the @samp{Rename Variable} menu entry that you can use to
rename the variable you click on across its containing clause
-(@pxref{Renaming Variables, , Renaming Variables}).
+(@pxref{Renaming Variables}).
You can further extend and customize the context menu that Sweep
Prolog mode provides by adding functions to the variable
@@ -2548,6 +2549,10 @@ result of being extracted from the current clause,
@code{sweeprolog-extract-region-to-predicate} warns you about it and
asks you to confirm before continuing.
+If you call @code{sweeprolog-extract-region-to-predicate} when the
+region does not contain a valid Prolog term, this command complains
+and refuses to extract the invalid term.
+
By default, @code{sweeprolog-extract-region-to-predicate} is not bound
directly to any key in Sweep Prolog mode; instead, you can invoke it
by typing @kbd{M-@key{RET}} (@code{sweeprolog-insert-term-dwim}) when
diff --git a/sweeprolog.el b/sweeprolog.el
index fbdb9b949a..c3fe6c80ab 100644
--- a/sweeprolog.el
+++ b/sweeprolog.el
@@ -6000,11 +6000,14 @@ POINT is the buffer position of the mouse click."
(<= sweeprolog-context-menu-region-beg-at-click
point
sweeprolog-context-menu-region-end-at-click))
- (define-key menu [sweeprolog-extract-region-to-predicate]
- `(menu-item "Extract to New Predicate"
- sweeprolog-extract-region-to-predicate
- :help "Extract the selected goal into a separate
predicate"
- :keys
"\\[sweeprolog-extract-region-to-predicate]"))))
+ (when (sweeprolog-context-callable-p
+ sweeprolog-context-menu-region-beg-at-click)
+ (define-key
+ menu [sweeprolog-extract-region-to-predicate]
+ `(menu-item "Extract to New Predicate"
+ sweeprolog-extract-region-to-predicate
+ :help "Extract the selected goal into a separate predicate"
+ :keys "\\[sweeprolog-insert-term-dwim] in active
region")))))
(defvar sweeprolog-context-menu-functions
'(sweeprolog-context-menu-for-clause
@@ -6895,10 +6898,12 @@ where in the buffer to insert the newly created
predicate."
body
".\n"))
(indent-region-line-by-line def-beg (point))
- (goto-char def-beg)))))))
+ (goto-char def-beg)
+ (sweeprolog-analyze-buffer)))))))
(defun sweeprolog-maybe-extract-region-to-predicate (&rest _)
- (when (use-region-p)
+ (when (and (use-region-p)
+ (sweeprolog-context-callable-p (use-region-beginning)))
(sweeprolog-extract-region-to-predicate
(use-region-beginning)
(use-region-end)