From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Kangas Newsgroups: gmane.emacs.devel Subject: Re: Consistent face for keys in *Help* and `substitute-command-keys' Date: Wed, 24 Feb 2021 19:56:00 -0600 Message-ID: References: <87h7m5iagw.fsf@gnus.org> <83a6rttnnv.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32412"; mail-complaints-to="usenet@ciao.gmane.io" Cc: larsi@gnus.org, emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Feb 25 02:56:57 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lF5th-0008JD-CO for ged-emacs-devel@m.gmane-mx.org; Thu, 25 Feb 2021 02:56:57 +0100 Original-Received: from localhost ([::1]:60270 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lF5tg-0005eK-En for ged-emacs-devel@m.gmane-mx.org; Wed, 24 Feb 2021 20:56:56 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:43148) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lF5sw-0005Cp-7A for emacs-devel@gnu.org; Wed, 24 Feb 2021 20:56:10 -0500 Original-Received: from mail-pg1-f179.google.com ([209.85.215.179]:33440) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lF5sp-0004zj-Rf; Wed, 24 Feb 2021 20:56:09 -0500 Original-Received: by mail-pg1-f179.google.com with SMTP id g4so2775979pgj.0; Wed, 24 Feb 2021 17:56:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:in-reply-to:references:mime-version:date :message-id:subject:to:cc; bh=rWBIj+SoAv/slbC6kFuv+uvbM9CLro0n840L9DPO6tQ=; b=a+ldHYaSxI0tadP860oBAxIg5WB0zDN4hdySJJRqAFrGntKWYBv5F/UL2MM715mMbP hgnsgw9waTgPFF5+MbEnstZ02JNJgL5VqNQTxcSm7ru9zo2SBa0yWDh7AbGY9bBNZbXq BhD9RUIRg1IO7mu6xwGe7+Yyn4pwl/rmYmvdKjyyRpmHmDDZYPN6npLP0GqJ5ZTc4JwV aTfM31jFaPUEJ+zU69Lx2d0b5qrhmN6MVn2oatScd26AnPzXBlo70CSO6/O96wwqZb+m HrVwr4iCN4RBV6tL2AS9M2n9vCnlBED9heWzdGD5+CYGzHlteW7FjZ7kItU5pNZV6GAZ 4nkQ== X-Gm-Message-State: AOAM5317ten+tJgz44JGyPwdbWTKyom7H/nmj34q0kIHn+W0DrYACSzt 6zVZ+2iz0WDH0D/oGYBxESoTAyYiClVtxMUid8W/I3Df X-Google-Smtp-Source: ABdhPJwczofmQ/+i5gAD6nBhv5NCTIiTS+/1O3hyJ/esoqwSnExlkpYqw3tdOaAJ11YjSlanNt41hi8ES38tHmotKbU= X-Received: by 2002:a63:fd0a:: with SMTP id d10mr751635pgh.345.1614218161932; Wed, 24 Feb 2021 17:56:01 -0800 (PST) Original-Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Wed, 24 Feb 2021 19:56:00 -0600 In-Reply-To: <83a6rttnnv.fsf@gnu.org> Received-SPF: pass client-ip=209.85.215.179; envelope-from=stefankangas@gmail.com; helo=mail-pg1-f179.google.com X-Spam_score_int: -13 X-Spam_score: -1.4 X-Spam_bar: - X-Spam_report: (-1.4 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:265598 Archived-At: Eli Zaretskii writes: > Using Fpropertize here is suboptimal: it does several thing you don't > need when calling it from C, including consing a new string, which is > just a waste of cycles. > > Please use Fadd_text_properties instead. How's this? diff --git a/src/keymap.c b/src/keymap.c index 782931fadf..e38c9b908a 100644 --- a/src/keymap.c +++ b/src/keymap.c @@ -2846,6 +2846,23 @@ DEFUN ("describe-vector", Fdescribe_vector, Sdescribe_vector, 1, 2, 0, return unbind_to (count, Qnil); } +static Lisp_Object fontify_key_properties; + +static Lisp_Object +describe_key_maybe_fontify (Lisp_Object str, Lisp_Object prefix, + bool keymap_p) +{ + Lisp_Object key_desc = Fkey_description (str, prefix); + + if (keymap_p) + return Fadd_text_properties (make_fixnum (0), + make_fixnum (SCHARS (key_desc)), + fontify_key_properties, + key_desc); + else + return key_desc; +} + DEFUN ("help--describe-vector", Fhelp__describe_vector, Shelp__describe_vector, 7, 7, 0, doc: /* Insert in the current buffer a description of the contents of VECTOR. Call DESCRIBER to insert the description of one value found in VECTOR. @@ -3021,7 +3038,7 @@ describe_vector (Lisp_Object vector, Lisp_Object prefix, Lisp_Object args, if (!NILP (elt_prefix)) insert1 (elt_prefix); - insert1 (Fkey_description (kludge, prefix)); + insert1 (describe_key_maybe_fontify (kludge, prefix, keymap_p)); /* Find all consecutive characters or rows that have the same definition. But, if VECTOR is a char-table, we had better @@ -3071,7 +3088,7 @@ describe_vector (Lisp_Object vector, Lisp_Object prefix, Lisp_Object args, if (!NILP (elt_prefix)) insert1 (elt_prefix); - insert1 (Fkey_description (kludge, prefix)); + insert1 (describe_key_maybe_fontify (kludge, prefix, keymap_p)); } /* Print a description of the definition of this character. @@ -3200,6 +3217,12 @@ syms_of_keymap (void) staticpro (&where_is_cache); staticpro (&where_is_cache_keymaps); + DEFSYM (Qfont_lock_face, "font-lock-face"); + DEFSYM (Qhelp_key_binding, "help-key-binding"); + staticpro (&fontify_key_properties); + fontify_key_properties = Fcons (Qfont_lock_face, + Fcons (Qhelp_key_binding, Qnil)); + defsubr (&Skeymapp); defsubr (&Skeymap_parent); defsubr (&Skeymap_prompt);