* project.el switch project improvements
@ 2021-09-04 14:11 Jiacai Liu
0 siblings, 0 replies; 5+ messages in thread
From: Jiacai Liu @ 2021-09-04 14:11 UTC (permalink / raw)
To: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 223 bytes --]
Hi,
project-switch-project command in master will prompt a list of
commands after choose
one project, it would be nice to just call it directly when length
of project-switch-commands is 1.
Any idea about this change?
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: project.patch --]
[-- Type: text/x-patch, Size: 701 bytes --]
diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index e420a4ccca..52289d3ccc 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -1409,7 +1409,9 @@ project-switch-project
(when-let ((cmd (nth 0 row))
(keychar (nth 2 row)))
(define-key temp-map (vector keychar) cmd)))))
- command)
+ (command (when (= 1 (length commands-menu))
+ ;; pick first command when only have one choice
+ (caar commands-menu))))
(while (not command)
(let* ((overriding-local-map commands-map)
(choice (read-key-sequence (project--keymap-prompt))))
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: project.el switch project improvements
[not found] <m1ilzgfn1k.fsf@liujiacai.net>
@ 2021-09-04 18:49 ` Dmitry Gutov
2021-09-05 3:46 ` Jiacai Liu
[not found] ` <m11r63smzb.fsf@liujiacai.net>
0 siblings, 2 replies; 5+ messages in thread
From: Dmitry Gutov @ 2021-09-04 18:49 UTC (permalink / raw)
To: Jiacai Liu, emacs-devel
Hi!
On 04.09.2021 17:11, Jiacai Liu wrote:
> project-switch-project command in master will prompt a list of commands
> after choose
> one project, it would be nice to just call it directly when length of
> project-switch-commands is 1.
>
> Any idea about this change?
Looks good.
Do you want to maybe go a step further and handle this case by having
project-switch-commands possibly be a symbol?
Then the user who doesn't want the prompt could just
(setq project-switch-commands #'project-find-file)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: project.el switch project improvements
2021-09-04 18:49 ` project.el switch project improvements Dmitry Gutov
@ 2021-09-05 3:46 ` Jiacai Liu
[not found] ` <m11r63smzb.fsf@liujiacai.net>
1 sibling, 0 replies; 5+ messages in thread
From: Jiacai Liu @ 2021-09-05 3:46 UTC (permalink / raw)
To: Dmitry Gutov; +Cc: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 361 bytes --]
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.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: project.patch --]
[-- Type: text/x-patch, Size: 5035 bytes --]
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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: project.el switch project improvements
[not found] ` <m11r63smzb.fsf@liujiacai.net>
@ 2021-09-07 1:47 ` Dmitry Gutov
2021-09-07 15:24 ` Jiacai Liu
0 siblings, 1 reply; 5+ messages in thread
From: Dmitry Gutov @ 2021-09-07 1:47 UTC (permalink / raw)
To: Jiacai Liu; +Cc: emacs-devel
On 05.09.2021 06:46, Jiacai Liu wrote:
>
>
> 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!
I've pushed the feature in b52cafe496 with a somewhat rewritten patch,
to minimize the diff (to have better vc-annotate output in the future)
and add more documentation. Check it out.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: project.el switch project improvements
2021-09-07 1:47 ` Dmitry Gutov
@ 2021-09-07 15:24 ` Jiacai Liu
0 siblings, 0 replies; 5+ messages in thread
From: Jiacai Liu @ 2021-09-07 15:24 UTC (permalink / raw)
To: Dmitry Gutov; +Cc: emacs-devel
On Tue, Sep 07, 2021 at 09:47:38 AM +0800, Dmitry Gutov wrote:
> I've pushed the feature in b52cafe496 with a somewhat rewritten
> patch, to minimize the diff
Good work!
Thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-09-07 15:24 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <m1ilzgfn1k.fsf@liujiacai.net>
2021-09-04 18:49 ` project.el switch project improvements Dmitry Gutov
2021-09-05 3:46 ` Jiacai Liu
[not found] ` <m11r63smzb.fsf@liujiacai.net>
2021-09-07 1:47 ` Dmitry Gutov
2021-09-07 15:24 ` Jiacai Liu
2021-09-04 14:11 Jiacai Liu
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).