[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/sweeprolog 89daa53a16 8/9: Add grouping and affixation fun
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/sweeprolog 89daa53a16 8/9: Add grouping and affixation functions for module completion |
Date: |
Tue, 27 Jun 2023 16:03:11 -0400 (EDT) |
branch: elpa/sweeprolog
commit 89daa53a16c3aa2d2d779834c7193709f885d51c
Author: Eshel Yaron <me@eshelyaron.com>
Commit: Eshel Yaron <me@eshelyaron.com>
Add grouping and affixation functions for module completion
This adds a 'group-function' and an 'affixation-function' to
'sweeprolog-module-completion-table', for Emacs 28+
The affixation API allows us to compute the appropriate padding to
insert before annotations in a cleaner way. Modules are group
according to their classes.
* sweep.pl (sweep_module_class/2): New predicate.
* sweeprolog.el (sweeprolog-module-minibuffer-annotation-1):
Extract helper function from...
(sweeprolog-module-minibuffer-annotation): ...here. Adapt.
(sweeprolog-module-minibuffer-affixation)
(sweeprolog-module-minibuffer-group): New functions.
(sweeprolog-module-completion-table): Use them.
---
sweep.pl | 7 ++++++-
sweeprolog.el | 59 +++++++++++++++++++++++++++++++++++++++++++++++------------
2 files changed, 53 insertions(+), 13 deletions(-)
diff --git a/sweep.pl b/sweep.pl
index 72465d7375..2ecebe0773 100644
--- a/sweep.pl
+++ b/sweep.pl
@@ -89,7 +89,8 @@
sweep_breakpoint_file/2,
sweep_expand_macro/2,
sweep_module_annotation/2,
- sweep_is_module/2
+ sweep_is_module/2,
+ sweep_module_class/2
]).
:- use_module(library(pldoc)).
@@ -259,6 +260,10 @@ sweep_documentation_modes([mode(Mode0, Args)|_], OneLiner,
Docs) :-
sweep_documentation_modes([_|T], OneLiner, Docs) :-
sweep_documentation_modes(T, OneLiner, Docs).
+sweep_module_class(M0, C) :-
+ atom_string(M, M0),
+ module_property(M, class(C0)),
+ atom_string(C0, C).
sweep_module_path(ModuleName, Path) :-
atom_string(Module, ModuleName),
diff --git a/sweeprolog.el b/sweeprolog.el
index fd13c27a36..0b65ee36a1 100644
--- a/sweeprolog.el
+++ b/sweeprolog.el
@@ -1184,21 +1184,54 @@ the prefix argument."
FILE is the file name of MODULE and DESC is its description, or nil."
(sweeprolog--query-once "sweep" "sweep_module_annotation" module))
-(defun sweeprolog-module-minibuffer-annotation (module)
- "Annotation function for module completion candidates.
-
-Return a string used to annotate MODULE."
+(defun sweeprolog-module-minibuffer-annotation-1 (module pad)
+ "Return a string used to annotate MODULE while padding to PAD."
(let* ((width (string-width module))
(file-desc (sweeprolog-module-annotation module))
(file (car file-desc))
(desc (cdr file-desc)))
- (concat
- (make-string
- (+ (max (- (or sweeprolog--module-max-width width) width) 0) 2)
- ?\s)
- (when file (concat file (when desc (concat ": "))))
- (replace-regexp-in-string (rx "library(" (+ graph) "): ") ""
- (or desc "")))))
+ (propertize
+ (concat
+ (make-string
+ (+ (- sweeprolog--module-max-width width) 2)
+ ?\s)
+ (when file (concat file
+ (when desc (concat ": "))))
+ (replace-regexp-in-string (rx "library(" (+ graph) "): ") ""
+ (or desc "")))
+ 'face 'sweeprolog-structured-comment)))
+
+(defun sweeprolog-module-minibuffer-annotation (module)
+ "Annotation function for module completion candidates.
+
+Return a string used to annotate MODULE."
+ (sweeprolog-module-minibuffer-annotation-1 module
+ (or sweeprolog--module-max-width
+ (string-width module))))
+
+(defun sweeprolog-module-minibuffer-affixation (completions)
+ "Affixation function for module completion candidates.
+
+Map COMPLETIONS to a list of elements (CAND PRE SUF), where CAND
+is a candidate string, PRE is a prefix string to display before
+the candidate and SUF is its suffix to display after it."
+ (when completions
+ (let ((module-max-width (seq-max (mapcar #'string-width
+ completions))))
+ (mapcar (lambda (cand)
+ (list cand ""
+ (sweeprolog-module-minibuffer-annotation-1
+ cand module-max-width)))
+ completions))))
+
+(defun sweeprolog-module-minibuffer-group (completion transform)
+ "Grouping function for module completion candidates.
+
+See (info \"(elisp)Programmed Completion\") for the meaning of
+COMPLETION and TRANSFORM."
+ (if transform
+ completion
+ (sweeprolog--query-once "sweep" "sweep_module_class" completion)))
(defun sweeprolog-module-p (mod)
"Return non-nil if MOD is a known Prolog module."
@@ -1218,7 +1251,9 @@ STRING, PREDICATE and ACTION."
'(metadata
.
((category . sweeprolog-module)
- (annotation-function . sweeprolog-module-minibuffer-annotation))))
+ (annotation-function . sweeprolog-module-minibuffer-annotation)
+ (affixation-function . sweeprolog-module-minibuffer-affixation)
+ (group-function . sweeprolog-module-minibuffer-group))))
(t (complete-with-action action
(sweeprolog-modules-collection string)
string
- [nongnu] elpa/sweeprolog updated (1e718510d6 -> 0e05fa9545), ELPA Syncer, 2023/06/27
- [nongnu] elpa/sweeprolog 0e05fa9545 9/9: Bump version to 0.21.0, ELPA Syncer, 2023/06/27
- [nongnu] elpa/sweeprolog 1bb64b391c 2/9: * sweeprolog-pce-theme.el: Reformat, ELPA Syncer, 2023/06/27
- [nongnu] elpa/sweeprolog 43683b3ad7 4/9: Fix highlighting for nonexistent Prolog flag names, ELPA Syncer, 2023/06/27
- [nongnu] elpa/sweeprolog 784707cc9f 1/9: * README.org (PceEmacs Theme): Reword and fix typo, ELPA Syncer, 2023/06/27
- [nongnu] elpa/sweeprolog eb04f8414a 5/9: Improve module completion annotations, ELPA Syncer, 2023/06/27
- [nongnu] elpa/sweeprolog f5a1f615ee 6/9: Report correct predicate indicators in 'C-x 4 a', ELPA Syncer, 2023/06/27
- [nongnu] elpa/sweeprolog 89daa53a16 8/9: Add grouping and affixation functions for module completion,
ELPA Syncer <=
- [nongnu] elpa/sweeprolog b89249f0fb 3/9: * sweeprolog.el: Reorganizes 'defface's, ELPA Syncer, 2023/06/27
- [nongnu] elpa/sweeprolog 114482c715 7/9: Announce recent changes in NEWS.org, ELPA Syncer, 2023/06/27