unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: Marcin Borkowski <mbork@mbork.pl>,
	Help Gnu Emacs mailing list <help-gnu-emacs@gnu.org>
Subject: RE: Fontification of the interactive prompt string?
Date: Fri, 5 Jun 2015 15:34:03 -0700 (PDT)	[thread overview]
Message-ID: <938d697f-dbf7-4325-b745-ce1ad74038a8@default> (raw)
In-Reply-To: <87vbf17rtx.fsf@mbork.pl>

> 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'.




      parent reply	other threads:[~2015-06-05 22:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-05 21:44 Fontification of the interactive prompt string? Marcin Borkowski
2015-06-05 22:12 ` Tassilo Horn
2015-06-05 22:34 ` Drew Adams [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=938d697f-dbf7-4325-b745-ce1ad74038a8@default \
    --to=drew.adams@oracle.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=mbork@mbork.pl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).