From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jiacai Liu Newsgroups: gmane.emacs.devel Subject: Re: project.el switch project improvements Date: Sun, 05 Sep 2021 11:46:49 +0800 Message-ID: <12094.7059521981$1630821165@news.gmane.org> References: <6c864152-7806-ed4a-1b91-f43ad9fe0116@yandex.ru> 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="19201"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.4.15; emacs 27.2 Cc: emacs-devel@gnu.org To: Dmitry Gutov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Sep 05 07:52:39 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 1mMl54-0004oD-LB for ged-emacs-devel@m.gmane-mx.org; Sun, 05 Sep 2021 07:52:38 +0200 Original-Received: from localhost ([::1]:33120 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mMl52-00078P-0k for ged-emacs-devel@m.gmane-mx.org; Sun, 05 Sep 2021 01:52:36 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:38188) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mMj7b-0003u3-C0 for emacs-devel@gnu.org; Sat, 04 Sep 2021 23:47:07 -0400 Original-Received: from smtpbg587.qq.com ([113.96.223.105]:49248) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mMj7Z-0000a4-2S for emacs-devel@gnu.org; Sat, 04 Sep 2021 23:47:07 -0400 X-QQ-mid: bizesmtp51t1630813611tmb6wy3f Original-Received: from macbook (unknown [112.10.69.6]) by esmtp6.qq.com (ESMTP) with id ; Sun, 05 Sep 2021 11:46:50 +0800 (CST) X-QQ-SSF: 01100000002000E0W000B00A0000000 X-QQ-FEAT: hgUoQuKzM2EebTWUEjaA2Js+S83nSff5y4ot+JfVcauWkvkNxU5WNW0TYVd5F l+sH208HtHrdKLsnA1Ry2X8rWzY2wf+xHD5pJMWuD3U75Y/6LN4vEpqY0hAN8fwQLkRGHnn s8tFSj65WZRvL4ge8H0IFXHK4yP8jSKqyeruLzvrr49zDmTIPH9aUBEphSWgaPCL1rJYt7x a/ndO8KSNCPeaMRt6CuoDthOSe4/5fEtmGB8FFDPnfmpZVs9ySCHWkB+s6rypXCVGf2Voh5 IeJHaXEak0zXs16eZV7A2VtpOP0Wmc1t7PNkHNsrzXWgHjN1fZCJ9hIkejFwpHgXRryA== X-QQ-GoodBg: 0 In-reply-to: <6c864152-7806-ed4a-1b91-f43ad9fe0116@yandex.ru> X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:liujiacai.net:qybgspam:qybgspam3 Received-SPF: none client-ip=113.96.223.105; envelope-from=hello@liujiacai.net; helo=smtpbg587.qq.com X-Spam_score_int: 6 X-Spam_score: 0.6 X-Spam_bar: / X-Spam_report: (0.6 / 5.0 requ) BAYES_20=-0.001, INVALID_MSGID=0.568, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sun, 05 Sep 2021 01:51:56 -0400 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:273991 Archived-At: --=-=-= Content-Type: text/plain; format=flowed On Sun, Sep 05, 2021 at 02:49:27 AM +0800, Dmitry Gutov wrote: > Do you want to maybe go a step further and handle this case by > having project-switch-commands > possibly be a symbol? Hi Gutov, I like this idea. It would be more friendly to users who prefer calling command directly. I attach a new patch. Let me know if there are any issues. Thanks. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=project.patch diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index e420a4ccca..0c131d7929 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -1348,13 +1348,14 @@ project-switch-commands :version "28.1" :group 'project :package-version '(project . "0.6.0") - :type '(repeat - (list - (symbol :tag "Command") - (string :tag "Label") - (choice :tag "Key to press" - (const :tag "Infer from the keymap" nil) - (character :tag "Explicit key"))))) + :type '(choice (symbol :tag "Command") + (repeat + (list + (symbol :tag "Command") + (string :tag "Label") + (choice :tag "Key to press" + (const :tag "Infer from the keymap" nil) + (character :tag "Explicit key")))))) (defcustom project-switch-use-entire-map nil "Make `project-switch-project' use entire `project-prefix-map'. @@ -1393,39 +1394,45 @@ project-switch-project When called in a program, it will use the project corresponding to directory DIR." (interactive (list (project-prompt-project-dir))) - (let* ((commands-menu - (mapcar - (lambda (row) - (if (characterp (car row)) - ;; Deprecated format. - ;; XXX: Add a warning about it? - (reverse row) - row)) - project-switch-commands)) - (commands-map - (let ((temp-map (make-sparse-keymap))) - (set-keymap-parent temp-map project-prefix-map) - (dolist (row commands-menu temp-map) - (when-let ((cmd (nth 0 row)) - (keychar (nth 2 row))) - (define-key temp-map (vector keychar) cmd))))) - command) - (while (not command) - (let* ((overriding-local-map commands-map) - (choice (read-key-sequence (project--keymap-prompt)))) - (when (setq command (lookup-key commands-map choice)) - (unless (or project-switch-use-entire-map - (assq command commands-menu)) - ;; TODO: Add some hint to the prompt, like "key not - ;; recognized" or something. - (setq command nil))) - (let ((global-command (lookup-key (current-global-map) choice))) - (when (memq global-command - '(keyboard-quit keyboard-escape-quit)) - (call-interactively global-command))))) - (let ((default-directory dir) - (project-current-inhibit-prompt t)) - (call-interactively command)))) + (let ((command (if (symbolp project-switch-commands) + project-switch-commands + (let* ((commands-menu + (mapcar + (lambda (row) + (if (characterp (car row)) + ;; Deprecated format. + ;; XXX: Add a warning about it? + (reverse row) + row)) + project-switch-commands)) + (commands-map + (let ((temp-map (make-sparse-keymap))) + (set-keymap-parent temp-map project-prefix-map) + (dolist (row commands-menu temp-map) + (when-let ((cmd (nth 0 row)) + (keychar (nth 2 row))) + (define-key temp-map (vector keychar) cmd))))) + (command (when (= 1 (length commands-menu)) + ;; pick first command when only have one choice + ;; otherwise prompt commands + (caar commands-menu)))) + (while (not command) + (let* ((overriding-local-map commands-map) + (choice (read-key-sequence (project--keymap-prompt)))) + (when (setq command (lookup-key commands-map choice)) + (unless (or project-switch-use-entire-map + (assq command commands-menu)) + ;; TODO: Add some hint to the prompt, like "key not + ;; recognized" or something. + (setq command nil))) + (let ((global-command (lookup-key (current-global-map) choice))) + (when (memq global-command + '(keyboard-quit keyboard-escape-quit)) + (call-interactively global-command))))) + command))) + (default-directory dir) + (project-current-inhibit-prompt t)) + (call-interactively command))) (provide 'project) ;;; project.el ends here --=-=-=--