unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: "Philip K." <philip@warpmail.net>
To: "Basil L. Contovounesios" <contovob@tcd.ie>
Cc: 41890@debbugs.gnu.org, dgutov@yandex.ru, juri@linkov.net
Subject: bug#41890: 28.0.50; [PATCH]: Add bindings for project.el
Date: Thu, 18 Jun 2020 20:50:46 +0200	[thread overview]
Message-ID: <87mu50b43d.fsf@warpmail.net> (raw)
In-Reply-To: <874kr8jnl2.fsf@tcd.ie> (contovob@tcd.ie)

[-- Attachment #1: Type: text/plain, Size: 265 bytes --]


Thanks, the fixed patch is below.

Another minor change to the last patch is settign
project-switch-use-entire-map to nil, so that by default not all keys in
project-prefix-map are usable, as to avoid the potential for confusion
mentioned before.

-- 
	Philip K.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Use-same-keys-in-project-switch-project-as-in-projec.patch --]
[-- Type: text/x-diff, Size: 4137 bytes --]

From 8418074a6f73ad5dcafe1fbcbfc847155dc4c485 Mon Sep 17 00:00:00 2001
From: Philip K <philip@warpmail.net>
Date: Thu, 18 Jun 2020 16:06:19 +0200
Subject: [PATCH] Use same keys in project-switch-project as in
 project-prefix-map

* project.el (project-switch-commands): Convert to user option and
change structure.
(project-switch-use-entire-map): Add new option.
(project--keymap-prompt): Adapt to change in project-switch-commands.
(project-switch-project): Use project-prefix-map instead of
project-switch-commands to query valid commands.
---
 lisp/progmodes/project.el | 63 +++++++++++++++++++++++++--------------
 1 file changed, 41 insertions(+), 22 deletions(-)

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index e24d81c1b4..cf214719e5 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -900,27 +900,46 @@ project-prompt-project-dir
 ;;; Project switching
 
 ;;;###autoload
-(defvar project-switch-commands
-  '((?f "Find file" project-find-file)
-    (?g "Find regexp" project-find-regexp)
-    (?d "Dired" project-dired)
-    (?v "VC-Dir" project-vc-dir)
-    (?e "Eshell" project-eshell))
-  "Alist mapping keys to project switching menu entries.
+(defcustom project-switch-commands
+  '((project-find-file . "Find file")
+    (project-find-regexp . "Find regexp")
+    (project-dired . "Dired")
+    (project-vc-dir . "VC-Dir")
+    (project-shell . "Shell")
+    (project-eshell . "Eshell"))
+  "Alist mapping commands to descriptions.
 Used by `project-switch-project' to construct a dispatch menu of
 commands available upon \"switching\" to another project.
 
-Each element looks like (KEY LABEL COMMAND), where COMMAND is the
-command to run when KEY is pressed.  LABEL is used to distinguish
-the choice in the dispatch menu.")
+Each element looks like (COMMAND . LABEL), where COMMAND should be
+bound in `project-prefix-map'.  LABEL is used to distinguish the
+choice in the dispatch menu."
+  :type '(alist :key-type function
+                :value-type string)
+  :options (mapcan (lambda (ent)
+                     (and (commandp (cdr ent))
+                          (list (cdr ent))))
+                   (cdr project-prefix-map))
+  :version "28.1")
+
+(defcustom project-switch-use-entire-map nil
+  "Make `project-switch-project' use entire `project-prefix-map'.
+If nil, `project-switch-project' will only recognize commands
+listed in `project-switch-commands', and signal an error when
+others are invoked.  Otherwise, all keys in
+`project-switch-commands' are legal even if they aren't listed
+in the minibuffer."
+  :type 'bool
+  :version "28.1")
 
 (defun project--keymap-prompt ()
   "Return a prompt for the project swithing dispatch menu."
   (mapconcat
-   (pcase-lambda (`(,key ,label))
-     (format "[%s] %s"
-             (propertize (key-description `(,key)) 'face 'bold)
-             label))
+   (pcase-lambda (`(,cmd . ,label))
+     (let ((key (where-is-internal cmd project-prefix-map t)))
+       (format "[%s] %s"
+               (propertize (key-description key) 'face 'bold)
+               label)))
    project-switch-commands
    "  "))
 
@@ -930,14 +949,14 @@ project-switch-project
 The available commands are picked from `project-switch-commands'
 and presented in a dispatch menu."
   (interactive)
-  (let ((dir (project-prompt-project-dir))
-        (choice nil))
-    (while (not choice)
-      (setq choice (assq (read-event (project--keymap-prompt))
-                         project-switch-commands)))
-    (let ((default-directory dir)
-          (project-current-inhibit-prompt t))
-      (call-interactively (nth 2 choice)))))
+  (let* ((default-directory (project-prompt-project-dir))
+         (project-current-inhibit-prompt t)
+         (key (read-key-sequence-vector (project--keymap-prompt)))
+         (cmd (lookup-key project-prefix-map key)))
+    (if (and cmd (or project-switch-use-entire-map
+                     (assq cmd project-switch-commands)))
+        (call-interactively cmd)
+      (user-error "%s is undefined" (key-description key)))))
 
 (provide 'project)
 ;;; project.el ends here
-- 
2.20.1


  reply	other threads:[~2020-06-18 18:50 UTC|newest]

Thread overview: 110+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-16  9:49 bug#41890: 28.0.50; [PATCH]: Add bindings for project.el Theodor Thornhill
     [not found] ` <83pn9z13xq.fsf@gnu.org>
2020-06-16 16:44   ` Theodor Thornhill
2020-06-16 17:16     ` Eli Zaretskii
2020-06-16 17:30       ` Theodor Thornhill
2020-06-16 18:14         ` Basil L. Contovounesios
2020-06-16 19:07           ` Theodor Thornhill
2020-06-16 19:12             ` Theodor Thornhill
2020-06-16 21:57               ` Juri Linkov
2020-06-16 22:47                 ` Dmitry Gutov
2020-06-16 23:24                   ` Juri Linkov
2020-06-16 23:42                     ` Dmitry Gutov
2020-06-17 21:23                       ` Juri Linkov
2020-06-17 22:16                         ` Dmitry Gutov
2020-06-17 22:27                           ` Juri Linkov
2020-06-17 22:38                             ` Dmitry Gutov
2020-06-17 23:23                               ` Juri Linkov
2020-06-17 23:36                                 ` Dmitry Gutov
2020-06-18 22:59                                   ` Juri Linkov
2020-06-18 23:08                                     ` Dmitry Gutov
2020-06-20 23:41                                   ` Juri Linkov
2020-06-21  0:25                                     ` Dmitry Gutov
2020-06-17 10:51                 ` Philip K.
2020-06-16 20:31             ` Basil L. Contovounesios
2020-06-17 19:10               ` Theodor Thornhill
2020-06-17 19:40                 ` Basil L. Contovounesios
2020-06-17 23:07                 ` Dmitry Gutov
2020-06-16 21:23       ` Dmitry Gutov
2020-06-16 21:35         ` Dmitry Gutov
2020-06-17 14:28           ` Eli Zaretskii
2020-06-17 14:27         ` Eli Zaretskii
2020-06-17 15:49           ` Dmitry Gutov
2020-06-17 16:33             ` Eli Zaretskii
2020-06-17 22:23               ` Dmitry Gutov
2020-06-18 13:38                 ` Eli Zaretskii
2020-06-18 15:47                   ` Dmitry Gutov
2020-06-18 17:24                     ` Eli Zaretskii
2020-06-18 18:18                       ` Michael Albinus
2020-06-18 16:25       ` Stefan Monnier
2020-06-18 17:30         ` Eli Zaretskii
2020-06-18 18:22           ` Dmitry Gutov
2020-06-18 18:42             ` Eli Zaretskii
2020-06-18 18:54               ` Dmitry Gutov
2020-06-18 19:04                 ` Eli Zaretskii
2020-06-18 21:12                   ` Dmitry Gutov
2020-06-19  6:11                     ` Eli Zaretskii
     [not found] ` <3ad1ecbb-36d6-79c0-7a7b-6ff3a561e512@yandex.ru>
2020-06-18 14:09   ` Philip K.
2020-06-18 17:22     ` Basil L. Contovounesios
2020-06-18 18:50       ` Philip K. [this message]
2020-06-18 22:10         ` Juri Linkov
2020-06-18 23:01           ` Dmitry Gutov
2020-06-18 23:24             ` Juri Linkov
2020-06-18 23:31               ` Dmitry Gutov
2020-06-19 10:15                 ` Simen Heggestøyl
2020-07-11 17:07         ` Sean Whitton
2020-07-12 15:18           ` Dmitry Gutov
2020-07-12 16:24             ` Sean Whitton
2020-07-12 20:12               ` Dmitry Gutov
2020-07-18 16:06                 ` bug#42210: " Sean Whitton
2020-07-19 23:46                   ` Dmitry Gutov
2020-07-20  0:30                     ` Juri Linkov
2020-07-20  1:04                       ` bug#41890: " Dmitry Gutov
2020-07-20 20:47                         ` Juri Linkov
2020-07-20 21:00                           ` Dmitry Gutov
2020-07-20 16:49                     ` Sean Whitton
2020-07-20 20:41                       ` bug#41890: " Juri Linkov
2020-07-20 21:02                         ` Dmitry Gutov
2020-07-20 21:24                         ` bug#41890: " Sean Whitton
2020-07-20 22:00                       ` Dmitry Gutov
2020-07-21  0:33                         ` Sean Whitton
2020-07-21 23:38                           ` Juri Linkov
2020-07-22  0:38                             ` Dmitry Gutov
2020-07-22  1:33                               ` Sean Whitton
2020-07-22 19:28                                 ` bug#41890: " Sean Whitton
2020-07-23 23:46                                   ` Dmitry Gutov
2020-07-24  2:04                                     ` Sean Whitton
2020-07-24  6:01                                       ` bug#41890: " Eli Zaretskii
2020-07-24 15:12                                         ` Sean Whitton
2020-07-24 16:12                                           ` Eli Zaretskii
2020-07-24 21:20                                             ` Sean Whitton
2020-07-24 22:54                                               ` Dmitry Gutov
2020-07-24 23:13                                                 ` Sean Whitton
2020-07-24 23:45                                                   ` Dmitry Gutov
2020-07-25  6:14                                               ` Eli Zaretskii
2020-07-26  5:15                                                 ` bug#41890: " Sean Whitton
2020-07-27  0:01                                                   ` Dmitry Gutov
2020-07-22  1:31                             ` Sean Whitton
2020-07-23  0:32                               ` bug#41890: " Juri Linkov
2020-07-23 15:06                                 ` Sean Whitton
2020-07-20 10:21                   ` Basil L. Contovounesios
2020-07-20 14:45                     ` Eli Zaretskii
2020-07-12 23:48               ` Juri Linkov
2020-07-13  0:13                 ` Dmitry Gutov
2020-07-13  0:23                   ` Juri Linkov
2020-07-13  6:56                     ` Philip K.
2020-07-13 10:47                       ` Dmitry Gutov
2020-07-13 10:50                         ` Dmitry Gutov
2020-07-13 11:02                           ` Philip K.
2020-07-18 15:19                             ` Sean Whitton
2020-07-13 23:49                       ` Juri Linkov
2020-07-14  7:03                         ` Philip K.
2020-07-14 22:34                           ` Juri Linkov
2020-07-14 23:32                             ` Dmitry Gutov
2020-07-15 23:59                               ` Juri Linkov
2020-07-16 13:38                                 ` Dmitry Gutov
2020-07-15 19:21                             ` Philip K.
2020-07-15 23:35                               ` Dmitry Gutov
     [not found]     ` <902001d0-ab1c-b697-bfd0-b8ec195dc65f@yandex.ru>
2020-06-19 10:13       ` Simen Heggestøyl
2020-06-19 10:26         ` Philip K.
2020-06-19 10:50           ` Simen Heggestøyl
2020-06-19 12:25             ` Dmitry Gutov

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=87mu50b43d.fsf@warpmail.net \
    --to=philip@warpmail.net \
    --cc=41890@debbugs.gnu.org \
    --cc=contovob@tcd.ie \
    --cc=dgutov@yandex.ru \
    --cc=juri@linkov.net \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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