For further details, please consult the manual:
<https://eshelyaron.com/sweep.html>.
+* Version 0.8.6 on 2022-11-11
+
+** New user option ~sweeprolog-new-predicate-location-function~
+
+This user option specifies a function to be called from
+~sweeprolog-insert-term-dwim~ when defining a new predicate to choose
+the location of the new predicate definition. The default value of
+the option is a function ~sweeprolog-default-new-predicate-location~
+which preserves the current behavior of placing the new predicate
+right below the current predicate. Other options include the new
+function ~sweeprolog-new-predicate-location-above-current~ which places
+the new predicate above the current one.
+
+** Fixes
+
+- Fixed issue where ~sweeprolog-describe-predicate~ would throw an error
+ when describing predicates that were cross referenced but not loaded.
+
* Version 0.8.5 on 2022-11-10
** New command ~sweeprolog-xref-project-source-files~
source files in the current project. Bound to ~X~ in
~sweeprolog-prefix-map~.
-** Minor bug fixed
+** Minor bug fixes
- Fixed issue where ~sweeprolog-predicate-location~ sometimes returned a
file importing the predicate in question, rather than actually
#+FINDEX: sweeprolog-maybe-insert-next-clause
#+FINDEX: sweeprolog-maybe-define-predicate
+#+VINDEX: sweeprolog-new-predicate-location-function
- ~sweeprolog-maybe-insert-next-clause~ :: If the last token before
point is a fullstop ending a predicate clause, insert a new clause
below it.
- ~sweeprolog-maybe-define-predicate~ :: If point is over a call to an
- undefined predicate, insert a definition for that predicate below
- the last clause of the current predicate definition.
+ undefined predicate, insert a definition for that predicate. By
+ default, the new predicate definition is inserted right below the
+ last clause of the current predicate definition. The user option
+ ~sweeprolog-new-predicate-location-function~ can be customized to
+ control where this function inserts new predicate definitions.
*** Filling Holes
:PROPERTIES:
bar :- foo.
"))))
+
+(ert-deftest dwim-define-predicate-above ()
+ "Tests adherence to `sweeprolog-new-predicate-location-function'."
+ (with-temp-buffer
+ (sweeprolog-mode)
+ (insert "
+%! foo is det.
+
+foo :- bar.
+")
+ (backward-word)
+ (let ((sweeprolog-new-predicate-location-function
+ #'sweeprolog-new-predicate-location-above-current))
+ (sweeprolog-insert-term-dwim))
+ (call-interactively #'kill-region)
+ (insert "foo")
+ (should (string= (buffer-string)
+ "
+bar :- foo.
+
+%! foo is det.
+
+foo :- bar.
+"))))
+
(ert-deftest end-of-top-term-with-univ ()
"Tests detecting the fullstop in presence of `=..'."
(with-temp-buffer
;; Maintainer: Eshel Yaron <~eshel/dev@lists.sr.ht>
;; Keywords: prolog languages extensions
;; URL: https://git.sr.ht/~eshel/sweep
-;; Package-Version: 0.8.5
+;; Package-Version: 0.8.6
;; Package-Requires: ((emacs "28.1"))
;; This file is NOT part of GNU Emacs.
:type 'boolean
:group 'sweeprolog)
+(defcustom sweeprolog-new-predicate-location-function
+ #'sweeprolog-default-new-predicate-location
+ "Function used to choose a location for a new predicate definition.
+It should take one argument, the name of the new predicate given
+as a string, and move point to a suitable position in the current
+buffer where the new predicate defintion should be inserted."
+ :package-version '((sweeprolog "0.8.6"))
+ :type '(choice (const :tag "Below Current Predicate"
+ sweeprolog-default-new-predicate-location)
+ (const :tag "Above Current Predicate"
+ sweeprolog-new-predicate-location-above-current)
+ (function :tag "Custom Function"))
+ :group 'sweeprolog)
+
+
;;;; Keymaps
(sweeprolog-insert-clause functor arity)
t))
+(defun sweeprolog-default-new-predicate-location (_pred)
+ (sweeprolog-end-of-predicate-at-point))
+
+(defun sweeprolog-new-predicate-location-above-current (_pred)
+ (sweeprolog-beginning-of-predicate-at-point)
+ (let ((last (or (caddr (sweeprolog-last-token-boundaries))
+ (point-min))))
+ (while (re-search-backward (rx bol "%" (or "%" "!")) last t))))
+
(defun sweeprolog-maybe-define-predicate (point _kind _beg _end)
(when-let ((pred (sweeprolog-identifier-at-point point)))
(unless (sweeprolog-predicate-properties pred)
- (push-mark)
- (sweeprolog-end-of-predicate-at-point)
+ (funcall sweeprolog-new-predicate-location-function pred)
(let ((functor-arity (sweeprolog--mfn-to-functor-arity pred)))
(sweeprolog-insert-clause (car functor-arity)
(cdr functor-arity)))