* sweep.pl (sweep_format_head/2): new predicate.
* sweeprolog.el (sweeprolog-insert-clause): use it.
sweep_interrupt/0,
sweep_string_to_atom/2,
sweep_file_path_in_library/2,
- sweep_file_missing_dependencies/2
+ sweep_file_missing_dependencies/2,
+ sweep_format_head/2
]).
:- use_module(library(pldoc)).
{ term_string(PI0, PI)
},
[[Path, PI, Kind]].
+
+
+sweep_format_head([F0|A], R) :-
+ atom_string(F, F0),
+ pi_head(F/A, H),
+ sweep_current_module(M),
+ sweep_format_predicate(M, 0, H, R).
"
))))
+(ert-deftest dwim-next-clause-args ()
+ "Tests inserting new clause with arguments."
+ (let ((temp (make-temp-file "sweeprolog-test"
+ nil
+ "pl"
+ "
+%! foo(+Bar) is det.
+
+foo(bar) :- bar.
+"
+ )))
+ (find-file-literally temp)
+ (sweeprolog-mode)
+ (goto-char (point-max))
+ (sweeprolog-insert-term-dwim)
+ (should (string= (buffer-string)
+ "
+%! foo(+Bar) is det.
+
+foo(bar) :- bar.
+foo(Bar) :- Body.
+
+"))))
+
(ert-deftest dwim-next-clause-module-qualified ()
"Tests inserting new module-qualified clause."
(let ((temp (make-temp-file "sweeprolog-test"
font-lock-face)))
(defun sweeprolog-insert-clause (functor arity &optional neck module)
- (let ((point nil)
- (neck (or neck ":-")))
+ (let ((point (point))
+ (neck (or neck ":-"))
+ (head-format (sweeprolog--query-once "sweep" "sweep_format_head"
+ (cons functor arity))))
(combine-after-change-calls
(insert "\n"
(if module
(concat module ":")
"")
- functor)
- (setq point (point))
- (when (< 0 arity)
- (insert "(")
- (dotimes (_ (1- arity))
- (insert (sweeprolog--hole) ", "))
- (insert (sweeprolog--hole) ")"))
+ (car head-format))
+ (pcase (cdr head-format)
+ (`(compound
+ "term_position"
+ 0 ,length
+ ,_fbeg ,_fend
+ ,holes)
+ (with-silent-modifications
+ (dolist (hole holes)
+ (pcase hole
+ (`(compound "-" ,hbeg ,hend)
+ (add-text-properties
+ (- (point) length (- hbeg))
+ (- (point) length (- hend))
+ (list
+ 'sweeprolog-hole t
+ 'font-lock-face (list (sweeprolog-hole-face))
+ 'rear-nonsticky '(sweeprolog-hole
+ cursor-sensor-functions
+ font-lock-face)))))))))
(insert " " neck " " (sweeprolog--hole "Body") ".\n"))
(goto-char point)
(sweeprolog-forward-hole)))