[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Fontification of the interactive prompt string?
From: |
Drew Adams |
Subject: |
RE: Fontification of the interactive prompt string? |
Date: |
Fri, 5 Jun 2015 15:34:03 -0700 (PDT) |
> I have an (interactive "cprompt\n") call, and I'd like the prompt to
> list possible characters (they define a few options for my function,
> and I have good reasons to implement it this way and not with C-u etc.)
> I'd like to have the relevant characters highlighted, like in:
> "file: _n_ew, _o_pen, _c_lose" where the underscores mean that
> something is e.g. in a different color.
>
> Is it possible?
Yes.
The value of variable `minibuffer-prompt-properties' is applied to
the prompt. And by default the value is this, which applies a face:
`(read-only t face minibuffer-prompt)'.
So you will want to bind that variable to a value that does not
have any entry for property `face' - e.g., to just `(read-only t)'.
Then you can use whatever propertized prompt string you like.
Here is something quick-&-dirty, to give you an idea what I mean:
;; Substitute for `completing-read'. It just binds
;; `minibuffer-prompt-properties', to stop it from imposing its
;; single default face.
;;
(defun my-compl-read (prompt collection &optional predicate
require-match initial-input hist def
inherit-input-method)
(let ((minibuffer-prompt-properties '(read-only t)))
(completing-read prompt collection predicate require-match
initial-input hist def inherit-input-method)))
(defun my-prompt (string.face-alist)
(apply #'concat (mapcar (lambda (s.f)
(if (cdr s.f)
(propertize (car s.f) 'face (cdr s.f))
(car s.f)))
string.face-alist)))
(my-compl-read (my-prompt '(("Plain and ")
("highlighted " . font-lock-comment-face)
("text ")
("IS " . font-lock-keyword-face)
("possible: ")))
'(a b c d e))
Obviously, you can construct the prompt string in other ways.
And instead of defining a function like `my-compl-read' you could
use variable `completing-read-function' or advise `completing-read'.