From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Manuel Giraud via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#74111: [PATCH] New `tmm-menubar' shortcut display style Date: Thu, 31 Oct 2024 23:07:00 +0100 Message-ID: <87bjz0yliz.fsf@ledu-giraud.fr> References: <87r07xtuot.fsf@ledu-giraud.fr> <86sesc37x4.fsf@gnu.org> <87msikin17.fsf@ledu-giraud.fr> <86ikt835sc.fsf@gnu.org> <87ikt8ijc1.fsf@ledu-giraud.fr> <86a5ek2vtv.fsf@gnu.org> <87frocz2bd.fsf@ledu-giraud.fr> <861pzw2osq.fsf@gnu.org> Reply-To: Manuel Giraud Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="23659"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 74111@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Oct 31 23:08:21 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1t6dL3-0005yQ-Fo for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 31 Oct 2024 23:08:21 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t6dKm-0004h9-TS; Thu, 31 Oct 2024 18:08:05 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t6dKk-0004go-LR for bug-gnu-emacs@gnu.org; Thu, 31 Oct 2024 18:08:02 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t6dKk-0003tF-Cx for bug-gnu-emacs@gnu.org; Thu, 31 Oct 2024 18:08:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=MBZrjuh7YkmExbMhGv/7WuzgJ9nyXO8oz/NSiW51YRY=; b=p3fuePihyXJdEboOaNxNAUnXMoAsTy+/3DpUJqB0CWXzcftg81g1/V5MlVcuAK5xVvt7CrSTPgLRdtJed1aaOadkwj9WDGOGMKkg3EddP3m3GmGQwxmZGbzWarQUoqOlffDbXHKfAyHMygFYjncCiBWKQf9IRb4PL0zZPtonVgYjZEWwbJtf/Fgq4GXfyTxudil8xf3zQ7yYmTjikytZJ2NbLzA2xm2xo6t1U8A124xe4eDcDRqUxh+7wlEh0yo+l9udMEHbyahZ6grJlRO1Ei7xCW9DbL6zdU39yzuAWnsamhoGLRXBaDnUtYM5QFyqkeMyL8m38AJMtGNo4pP1sw==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1t6dKk-0003Nw-5s for bug-gnu-emacs@gnu.org; Thu, 31 Oct 2024 18:08:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Manuel Giraud Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 31 Oct 2024 22:08:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74111 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 74111-submit@debbugs.gnu.org id=B74111.173041242912956 (code B ref 74111); Thu, 31 Oct 2024 22:08:02 +0000 Original-Received: (at 74111) by debbugs.gnu.org; 31 Oct 2024 22:07:09 +0000 Original-Received: from localhost ([127.0.0.1]:44634 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t6dJt-0003Mu-5V for submit@debbugs.gnu.org; Thu, 31 Oct 2024 18:07:09 -0400 Original-Received: from ledu-giraud.fr ([51.159.28.247]:40692) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t6dJq-0003Mm-TP for 74111@debbugs.gnu.org; Thu, 31 Oct 2024 18:07:08 -0400 DKIM-Signature: v=1; a=ed25519-sha256; c=simple/simple; s=ed25519; bh=gyFK6RtR nX+x06g0L0LNcBpaflCIMtgkuC2kQNN3WrA=; h=date:references:in-reply-to: subject:cc:to:from; d=ledu-giraud.fr; b=nZjKPASufZiqonE2dxChsBHeAL1LJ/ TLC7BzUtw97K5nkVZ+MozHxyj1cwbK0IQEzTJLDmRz59mivY/BnOJ7BA== DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=rsa; bh=gyFK6RtRnX+x06g0 L0LNcBpaflCIMtgkuC2kQNN3WrA=; h=date:references:in-reply-to:subject: cc:to:from; d=ledu-giraud.fr; b=wGPUMH+ROk+cx3umbnL4uJCx6Z7DrDp36Uw0Yt +hJDpSjh8HGmuXeEDUQAiQ27bc2k6PaaBLl8FNsfZWh3uaaZy4fvtC0AtEON3D7UHrLjTu 99fCtJW1Dy73RUzZTLVuCS5+uN6BQa2CZ6f1Nxii+VioRYcAKNQrsnXv0iT4nvVFbROoNz 4BwH76SHRF/xUVz/n2KNXfLe1qT4za0Bd/YcB1Aa+S7D9itK/XcmQ71CZnv8pxA7Ot8CJC theYB+K4U5NEL9/gLNeO/E5eAK+Sg0alkzwFDKoAjobML9ZSs+i16BKMh0vwXazKk18Rwe CWoasGYryKSoLJjcl3sFjWUQ== Original-Received: from computer ( [10.1.1.1]) by ledu-giraud.fr (OpenSMTPD) with ESMTPSA id ed8742d5 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 31 Oct 2024 23:07:03 +0100 (CET) In-Reply-To: <861pzw2osq.fsf@gnu.org> (Eli Zaretskii's message of "Thu, 31 Oct 2024 18:57:25 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:294639 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: >> From: Manuel Giraud >> Cc: 74111@debbugs.gnu.org >> Date: Thu, 31 Oct 2024 17:04:22 +0100 >> >> >> Maybe we could change it to "highlighted letters (or digits)". But >> >> FWIW, "marked letters" was not really more clear before this patch. So >> >> I think we could try to rewrite tmm-completion-prompt with something >> >> clearer that work for both options. WDYT? >> > >> > I agree, please suggest a better text that caters to both cases. >> >> What do you think of this new version of the patch? > > LGTM, thanks. > >> I removed the >> "PageUp" comment as it does not seem to work (while 'M-v' is) > > PageUp does work here, so I think we should leave that sentence, but > modify it to say "M-v/PageUp". > >> +*** New user option 'tmm-shortcut-inside-entry'. >> +When non-nil, insert the character shortcut of a menu entry inside its > > The "insert...inside its string" is not really accurate, is it? The > code tries to highlight a character that already exists in the choice > string, and prepends a digit if it fails to find such a character. > >> +(defcustom tmm-shortcut-inside-entry nil >> + "Place the shortcut character into the menu entry's string. >> +When non-nil, the shortcut character will be inserted into its menu >> +entry string with a different face to help identifying it. The >> +`tmm-mid-prompt' string is not used then." > > Same here. Here is a new version taking your remarks into account. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-New-tmm-menubar-shortcut-display-style.patch >From dbaf9698dc176b8eb64c3373808943cede2b4bce Mon Sep 17 00:00:00 2001 From: Manuel Giraud Date: Wed, 30 Oct 2024 17:24:24 +0100 Subject: [PATCH] New `tmm-menubar' shortcut display style Bug#74111 * lisp/tmm.el (tmm-shortcut-inside-entry): New user option to control if the shortcut character is placed inside the menu entry's string. (tmm-add-one-shortcut): Compute the new shortcut style. (tmm-prompt): Adapt the prompt regexp. (tmm-shortcut): Simplify and make it work with this change. * etc/NEWS: Announce the option. --- etc/NEWS | 5 ++++ lisp/tmm.el | 69 ++++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 55 insertions(+), 19 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index d1c7303f976..db13a1dd971 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -584,6 +584,11 @@ instead. *** A new shortcut to navigate to previous menu. The hardcoded '^' shortcut gets you back to the previous menu. +--- +*** New user option 'tmm-shortcut-inside-entry'. +When non-nil, highlight the character shortcut in the menu entry's +string instead of preprending it and `tmm-mid-prompt' to said entry. + ** Foldout --- diff --git a/lisp/tmm.el b/lisp/tmm.el index 252c1e45afa..1992ff0f73c 100644 --- a/lisp/tmm.el +++ b/lisp/tmm.el @@ -83,11 +83,11 @@ tmm-mid-prompt string)) (defcustom tmm-completion-prompt - "Press PageUp key to reach this buffer from the minibuffer. -Alternatively, you can use Up/Down keys (or your History keys) to change + "Press M-v/PageUp key to reach this buffer from the minibuffer. +Alternatively, You can use Up/Down keys (or your History keys) to change the item in the minibuffer, and press RET when you are done, or press -the marked letters to pick up your choice. Type ^ to go to the parent -menu. Type C-g or ESC ESC ESC to cancel. +the %s to pick up your choice. +Type ^ to go to the parent menu. Type C-g or ESC ESC ESC to cancel. " "Help text to insert on the top of the completion buffer. To save space, you can set this to nil, @@ -108,6 +108,13 @@ tmm-shortcut-words specify nil for this variable." :type '(choice integer (const nil))) +(defcustom tmm-shortcut-inside-entry nil + "Highlight the shortcut character in the menu entry's string. +When non-nil, the shortcut character will be highlighted into its menu +entry's string with the `highlight' face to help identifying it. The +`tmm-mid-prompt' string is not used then." + :type 'boolean) + (defface tmm-inactive '((t :inherit shadow)) "Face used for inactive menu items.") @@ -198,7 +205,8 @@ tmm-prompt (setq tail (cdr tail))))) (let ((prompt (concat "^" - (if (stringp tmm-mid-prompt) + (if (and (stringp tmm-mid-prompt) + (not tmm-shortcut-inside-entry)) (concat "." (regexp-quote tmm-mid-prompt)))))) (setq tmm--history @@ -283,7 +291,7 @@ tmm-add-one-shortcut (t (let* ((str (car elt)) (paren (string-search "(" str)) - (pos 0) (word 0) char) + (word 0) pos char) (catch 'done ; ??? is this slow? (while (and (or (not tmm-shortcut-words) ; no limit on words (< word tmm-shortcut-words)) ; try n words @@ -299,17 +307,32 @@ tmm-add-one-shortcut (if (not (memq char tmm-short-cuts)) (throw 'done char)))) (setq word (1+ word)) (setq pos (match-end 0))) + ;; A nil value for pos means that the shortcut is not inside the + ;; string of the menu entry + (setq pos nil) (while (<= tmm-next-shortcut-digit ?9) ; no letter shortcut, pick a digit (setq char tmm-next-shortcut-digit) (setq tmm-next-shortcut-digit (1+ tmm-next-shortcut-digit)) (if (not (memq char tmm-short-cuts)) (throw 'done char))) (setq char nil)) (if char (setq tmm-short-cuts (cons char tmm-short-cuts))) - (cons (concat (if char (concat (char-to-string char) tmm-mid-prompt) - ;; keep them lined up in columns - (make-string (1+ (length tmm-mid-prompt)) ?\s)) - str) - (cdr elt)))))) + (cons + (if tmm-shortcut-inside-entry + (if char + (if pos + ;; A character inside the menu entry + (let ((res (copy-sequence str))) + (aset res pos char) + (add-text-properties pos (1+ pos) '(face highlight) res) + res) + ;; A fallback digit character: place it in front of the menu entry + (concat (propertize (char-to-string char) 'face 'highlight) " " str)) + (make-string 2 ?\s)) + (concat (if char (concat (char-to-string char) tmm-mid-prompt) + ;; keep them lined up in columns + (make-string (1+ (length tmm-mid-prompt)) ?\s)) + str)) + (cdr elt)))))) ;; This returns the old map. (defun tmm-define-keys (minibuffer) @@ -384,7 +407,12 @@ tmm-add-prompt (let ((inhibit-read-only t) (window (get-buffer-window "*Completions*"))) (goto-char (point-min)) - (insert tmm-completion-prompt) + (insert + (if tmm-shortcut-inside-entry + (format tmm-completion-prompt + (concat (propertize "highlighted" 'face 'highlight) " character")) + (format tmm-completion-prompt + (concat "character right before '" tmm-mid-prompt "' ")))) (when window ;; Try to show everything just inserted and preserve height of ;; *Completions* window. This should fix a behavior described @@ -406,13 +434,16 @@ tmm-shortcut (choose-completion)) ;; In minibuffer (delete-region (minibuffer-prompt-end) (point-max)) - (dolist (elt tmm-km-list) - (if (string= - (substring (car elt) 0 - (min (1+ (length tmm-mid-prompt)) - (length (car elt)))) - (concat (char-to-string c) tmm-mid-prompt)) - (setq s (car elt)))) + (dolist (elt tmm-km-list) + (let ((str (car elt)) + (index 0)) + (when tmm-shortcut-inside-entry + (if (get-char-property 0 'face str) + (setq index 0) + (let ((next (next-single-char-property-change 0 'face str))) + (setq index (if (= (length str) next) 0 next))))) + (if (= (aref str index) c) + (setq s str)))) (insert s) (exit-minibuffer))))) -- 2.47.0 --=-=-= Content-Type: text/plain -- Manuel Giraud --=-=-=--