From: Eshel Yaron Date: Sun, 15 Oct 2023 10:37:36 +0000 (+0200) Subject: Sort predicate completion candidates by functor length X-Git-Tag: V9.1.17-0.25.5~7 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=79b2bb3a8a72a10a7959093fb02ec3139b4cedf2;p=sweep.git Sort predicate completion candidates by functor length * sweeprolog.el (sweeprolog-predicate-completion-sort): New function. (sweeprolog-predicate-completion-candidates): Use it as `display-sort-function`. --- diff --git a/sweeprolog.el b/sweeprolog.el index 9a0f064..a90baeb 100644 --- a/sweeprolog.el +++ b/sweeprolog.el @@ -1436,6 +1436,13 @@ list even when found in the current clause." (push (match-string-no-properties 0) vars))))))) vars)) +(defun sweeprolog-predicate-completion-sort (candidates) + "Sort predicate completion CANDIDATES by functor length." + (sort candidates + (lambda (a b) + (< (or (string-search "(" a) (length a)) + (or (string-search "(" b) (length b)))))) + (defun sweeprolog-predicate-completion-candidates (beg end cxt) (let ((col (sweeprolog--query-once "sweep" "sweep_heads_collection" @@ -1443,7 +1450,13 @@ list even when found in the current clause." (sweeprolog--qualyfing-module beg) (buffer-substring-no-properties beg (point)) (buffer-substring-no-properties (point) end))))) - (list beg end col + (list beg end + (lambda (s p a) + (if (eq a 'metadata) + '(metadata + (display-sort-function . sweeprolog-predicate-completion-sort) + (cycle-sort-function . sweeprolog-predicate-completion-sort)) + (complete-with-action a col s p))) :exclusive 'no :annotation-function (lambda (_) " Predicate functor") :exit-function