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: Fri, 01 Nov 2024 10:31:20 +0100 Message-ID: <8734kbz4ev.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> <87bjz0yliz.fsf@ledu-giraud.fr> <86r07v1l1l.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="22971"; 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 Fri Nov 01 10:32:28 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 1t6o16-0005qt-83 for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 01 Nov 2024 10:32:28 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t6o0q-0002Sa-PO; Fri, 01 Nov 2024 05:32:13 -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 1t6o0h-0002SB-IL for bug-gnu-emacs@gnu.org; Fri, 01 Nov 2024 05:32:05 -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 1t6o0g-0001re-Ax for bug-gnu-emacs@gnu.org; Fri, 01 Nov 2024 05:32:03 -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=BZpP3aohf00klkDJPJSFlWgCtoUwdXxG4ue62bGv07g=; b=WELcBLeqn//gVB6YE2acpNlqVhqfD1XrO7wVj4SlaI9Vqzv5bcTuPJNfkH/ET6qFzfH7dfM78n6EHjQXTDmcpQ9h+SkJV7vWbBrRhSjllrEYGDNQv42j4r6jWw2S880F6uBlJZQkluYdqIwwul+6WfdheW8686vlHFhW6ZEuLVPni+PBupj5KiBeleYbhkcZR3V3IfnnczAkZ85oyAQ4Phh91s1y9uiWV4elppNok/5xZnupgnw6hnXRycakRt+touM7ROogcQXiSpqcGG44v0TmkVHEZNQFdWQhmPsQlAfnY75skt3ueQJwLCkNmcq38ULMqQ7uYGtkF1bc897+/A==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1t6o0f-0001ZG-QW for bug-gnu-emacs@gnu.org; Fri, 01 Nov 2024 05:32:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Manuel Giraud Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 01 Nov 2024 09:32:01 +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.17304534876011 (code B ref 74111); Fri, 01 Nov 2024 09:32:01 +0000 Original-Received: (at 74111) by debbugs.gnu.org; 1 Nov 2024 09:31:27 +0000 Original-Received: from localhost ([127.0.0.1]:48140 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t6o06-0001Yt-Ao for submit@debbugs.gnu.org; Fri, 01 Nov 2024 05:31:26 -0400 Original-Received: from ledu-giraud.fr ([51.159.28.247]:22299) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t6o04-0001Yn-2X for 74111@debbugs.gnu.org; Fri, 01 Nov 2024 05:31:25 -0400 DKIM-Signature: v=1; a=ed25519-sha256; c=simple/simple; s=ed25519; bh=EcAQJb77 QuyLkbj98LEvRyAkqZrwtq0kxCcV63Q32ks=; h=date:references:in-reply-to: subject:cc:to:from; d=ledu-giraud.fr; b=LNXt4gXRJENFL4J9QSwGmFON3WK2hA wkwoGXDQNE9B0F0eZB+aTEydmDxBCfKwDiUopKcFa1iPr7QPb2P1dmBA== DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=rsa; bh=EcAQJb77QuyLkbj9 8LEvRyAkqZrwtq0kxCcV63Q32ks=; h=date:references:in-reply-to:subject: cc:to:from; d=ledu-giraud.fr; b=V85FNK1XUIEHYQdy7hPo7x+72nO0uA9GAwZS// 2HLX35vBDHKBosDBhX1LPhvBwqbtuyaCuLbhabPncRXenhj+xwyVdiF5dgIf6+XMQnzqgo 1HhpjBogDwlvG+s0xiMFrMjmp+80bE4Vj+bsexTwN/maGl5sTE7a7fzkmAFheDvai/DtM/ 6ZoLQHCn45zqxl8TRja5ExpPqfL92Zv0Qgrt0944bOGElIEM0mAMwdDW0YZtc9NsRrF4Km nboIRiN4M7l3hYL47bKxcxiUBzncUeDk6DirDCZEcHYNdb250W9bSicVbNIjJL2Bj293Gx 1typJs3nGpE3JwySGlAhWbvw== Original-Received: from computer ( [10.1.1.1]) by ledu-giraud.fr (OpenSMTPD) with ESMTPSA id f0b629e0 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 1 Nov 2024 10:31:21 +0100 (CET) In-Reply-To: <86r07v1l1l.fsf@gnu.org> (Eli Zaretskii's message of "Fri, 01 Nov 2024 09:16:06 +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:294671 Archived-At: --=-=-= Content-Type: text/plain Hi, I think I have address all the left issues with this patch. I've also updated the log: tell me what you think and feel free to reword it if needed. Thanks. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-New-tmm-menubar-shortcut-display-style.patch >From 28102a18a9edbdcc85ffd5254a8968611a25615d 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 highlighted inside the menu entry's string. (tmm-add-one-shortcut): Compute the new shortcut style. (tmm-add-prompt, tmm-completion-prompt): Adapt the completion prompt according to the shortcut display style. (tmm-prompt): Adapt the prompt regexp. (tmm-shortcut): Simplify default case and make it work with this change. * etc/NEWS: Announce the option. --- etc/NEWS | 5 ++++ lisp/tmm.el | 73 ++++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 58 insertions(+), 20 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..80991b246b6 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 first menu-entry's character that acts as a shortcut +will be highlighted 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,34 @@ 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) @@ -328,7 +353,7 @@ tmm-define-keys (define-key map "\ev" 'tmm-goto-completions) (define-key map "\C-n" 'next-history-element) (define-key map "\C-p" 'previous-history-element) - ;; Previous menu shortcut (see `tmm-prompt') + ;; Previous menu shortcut (see `tmm-prompt'). (define-key map "^" 'self-insert-and-exit)) (prog1 (current-local-map) (use-local-map (append map (current-local-map)))))) @@ -384,7 +409,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 +436,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 --=-=-=--