~eshel/sweep

1fb6714dbfeebae1379ae56ee10eaa3c27b41b43 — Eshel Yaron 10 months ago ae8f749 + fa99739
Merge branch 'master'
3 files changed, 80 insertions(+), 3 deletions(-)

M sweep.pl
M sweeprolog-tests.el
M sweeprolog.el
M sweep.pl => sweep.pl +11 -0
@@ 307,6 307,16 @@ sweep_short_documentation_head(brace_term_position(Beg, End, _), Head, Neck, Poi
    ;   Arg = 0
    ),
    sweep_short_documentation_(FileName, Mod, Head, Arg, Neck, PIString, Doc, ArgSpan).
sweep_short_documentation_head(term_position(_, _, _, _, [HeadPos, GuardPos]), (Head,Guard), Neck, Point, FileName, Mod, PIString, Doc, ArgSpan) :-
    % SSU guard or DCG pushback
    !,
    (   pos_bounds(HeadPos, HeadBeg, HeadEnd),
        HeadBeg =< Point, Point =< HeadEnd
    ->  sweep_short_documentation_head(HeadPos, Head, Neck, Point, FileName, Mod, PIString, Doc, ArgSpan)
    ;   pos_bounds(GuardPos, GuardBeg, GuardEnd),
        GuardBeg =< Point, Point =< GuardEnd
    ->  sweep_short_documentation_body(GuardPos, Guard, Neck, Point, FileName, Mod, PIString, Doc, ArgSpan)
    ).
sweep_short_documentation_head(term_position(_, _, _, _, [_, Pos]), Mod:Head, Neck, Point, FileName, _, PIString, Doc, ArgSpan) :-
    !,
    sweep_short_documentation_head(Pos, Head, Neck, Point, FileName, Mod, PIString, Doc, ArgSpan).


@@ 1488,6 1498,7 @@ source_arg(load_files, 1).
source_arg(use_module, 1).
source_arg(consult, 1).
source_arg(ensure_loaded, 1).
source_arg(process_create, 1).

callable_arg(N,    N) :- integer(N), !.
callable_arg((^),  0) :- !.

M sweeprolog-tests.el => sweeprolog-tests.el +52 -0
@@ 1846,6 1846,21 @@ body.
head,
  right_hand_context -->
    body.
")
  (sweeprolog-test-indentation
   "/** <module> Foo

This module provides foo bar
 baz spam
  foo bar baz
*/
"
   "/** <module> Foo

This module provides foo bar
baz spam
foo bar baz
*/
"))

(sweeprolog-deftest forward-sexp-with-adjacent-operators ()


@@ 2426,5 2441,42 @@ foo(Bar) --> baz(Bar).
    Skip zero or more white-space characters.
" nil))))

(sweeprolog-deftest eldoc-ssu-guard ()
  "Test `sweep_short_documentation/2' with SSU guard."
  "
:- module(eldocssuguard, []).

:- use_module(library(lists)).
"
  (should (equal (sweeprolog--query-once
                  "sweep" "sweep_short_documentation"
                  (list "foo(X), member(X,_) => true." 15 (buffer-file-name)))
                 '("lists:member/2" "member(?Elem,?List) is unspec.
    True if Elem is a member of List.
"
                   (7 . 12)))))


(sweeprolog-deftest eldoc-dcg-pushback ()
  "Test `sweep_short_documentation/2' with DCG pushback list."
  "
:- module(eldocdcgpushback, []).

%!  foo(-Baz:string)// is det.
%
%   Doit.

foo(_) --> [].

"
  (should (equal (sweeprolog--query-once
                  "sweep" "sweep_short_documentation"
                  (list "foo(X), [1,2,3] --> []." 5 (buffer-file-name)))
                 '("eldocdcgpushback:foo//1" "foo(-Baz:string)// is det.
    Doit.
"
                   (4 . 15)))))



;;; sweeprolog-tests.el ends here

M sweeprolog.el => sweeprolog.el +17 -3
@@ 5297,12 5297,26 @@ accordingly."
          col)))))

(defun sweeprolog-indent-line ()
  "Indent the current line in a `sweeprolog-mode' buffer."
  "Indent the current line in a Sweep Prolog mode buffer."
  (interactive)
  (let ((pos (- (point-max) (point))))
    (back-to-indentation)
    (let ((column (if (nth 8 (syntax-ppss))
                      'noindent
    (let ((column (if-let ((ppss (syntax-ppss))
                           (open (nth 8 ppss)))
                      ;; Inside a comment or a string.
                      (if (nth 4 ppss)
                          ;; It's a comment.  Indent like
                          ;; `indent--default-inside-comment'.
                          (save-excursion
                            (forward-line -1)
                            (skip-chars-forward " \t")
                            (when (< (1- (point)) open (line-end-position))
                              (goto-char open)
                              (when (looking-at comment-start-skip)
                                (goto-char (match-end 0))))
                            (current-column))
                        ;; It's a string.  Don't indent.
                        'noindent)
                    (if-let ((open (and (not (eobp))
                                        (= (sweeprolog-syntax-class-at (point)) 5)
                                        (nth 1 (syntax-ppss)))))