diff options
author | Thanos Apollo <[email protected]> | 2023-12-29 03:21:22 +0200 |
---|---|---|
committer | Thanos Apollo <[email protected]> | 2023-12-29 03:21:22 +0200 |
commit | 017a7035f46777ee4a9c6c162b666f93e0839362 (patch) | |
tree | 5d539d594c58aeac17f81f114e2340fcd7a5a1b4 | |
parent | ff9eb23a23b59021e307f16f6ba61f104bc7b97e (diff) |
Redo gnosis-completing-read
'gnosis-completing-read' alternative version to completing-read.
Rewritten to just configure text properties of strings.
Display opitons with additional info with text properties, padding &
choosable face.
-rw-r--r-- | gnosis.el | 41 |
1 files changed, 20 insertions, 21 deletions
@@ -101,27 +101,26 @@ Example: (gnosis-mode) ,@body)) -;; TODO: Use gnosis-completing-read to display total notes for review -;; option -(defun gnosis-completing-read (prompt candidates) - "Gnosis `completing-read' alternative. - -`PROMPT' for choice between `CANDIDATES'. -CANDIDATES need to be in a format of ((\"Option1\" \"Additional Info\")). - -WARNING: This function is still under development, DO NOT use this as is now." - (let* ((collection (lambda (str pred action) - (if (eq action 'metadata) - `(metadata - (affixation-function . ,(lambda (cands) - (mapcar - (lambda (cand) - (list cand "" (format " %s" - (or (cdr (assoc cand candidates)) "")))) - cands)))) - (complete-with-action action candidates str pred)))) - (choice (completing-read prompt collection))) - choice)) +(cl-defun gnosis-completing-read (prompt options info &optional (face-for-info 'font-lock-doc-face)) + "A version of `completing-read' with text properties, padding & choosable face. +Returns selected option from OPTIONS. + +PROMPT is a string to prompt with; normally it ends in a colon and a space. +OPTIONS is a list of strings. +INFO is a list of strings, which will be displayed as additional info for option +FACE-FOR-INFO is the face used to display info for option." + (let* ((choices (cl-mapcar 'cons options info)) + (max-choice-length (apply 'max (mapcar 'length options))) + (formatted-choices + (mapcar (lambda (choice) + (cons (concat (format "%s" (car choice)) + (make-string (- max-choice-length (length (car choice))) ? ) + " " + (propertize (format "%s" (cdr choice)) 'face face-for-info)) + (car choice))) + choices))) + (cdr (assoc (completing-read prompt formatted-choices nil t) + formatted-choices)))) (defun gnosis-display--question (id) "Display main row for note ID." |