GNU bug report logs -
#45765
[PATCH] 28.0.50; Change default-directory before prompting in project-compile
Previous Next
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 45765 in the body.
You can then email your comments to 45765 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#45765
; Package
emacs
.
(Sun, 10 Jan 2021 12:58:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Kévin Le Gouguec <kevin.legouguec <at> gmail.com>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Sun, 10 Jan 2021 12:58:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Hello,
Unlike project-shell-command, project-compile first prompts for a
command, then binds default-directory and calls compile. Binding
default-directory first makes completion work from the project root,
which is useful for completing on filenames relative to the root, on
targets from the toplevel Makefile, etc.
I see three ways to achieve this:
(1) Rewrite project-compile with call-interactively, the way
project-shell-command is written (see patch #1).
(2) Set COMMAND to nil in the interactive spec, then prompt for it after
binding default-directory (see patch #2).
(3) Let-binding default-directory once in the interactive spec, and
again before calling compile.
I'm assuming (1) is out of the question, given 2020-06-02
"* lisp/progmodes/project.el (project-vc-dir, project-shell): New
commands." (2c1e5b9e77). I'm CC'ing Juri to get his opinion though;
project-compile is new in Emacs 28.1, so its argument list is not yet
set in stone.
I've taken a stab at (2), but my patch changes the semantics of COMMAND
for an edge case: for now calling (project-compile nil) from Lisp causes
(compile nil) to be called (which errors out); with my patch,
(project-compile nil) yields a prompt.
This can be solved using called-interactively-p (or using an optional
INTERACTIVE argument); I just don't know if it's worth the hassle?
I haven't given much thought to (3), so I haven't yet figured out how to
avoid prompting twice for the project (on the rare occasions where
prompting is needed).
Thanks for your time.
[0001-Change-default-directory-before-prompting-in-project-1.patch (text/x-patch, attachment)]
[0001-Change-default-directory-before-prompting-in-project-2.patch (text/x-patch, attachment)]
[Message part 4 (text/plain, inline)]
In GNU Emacs 28.0.50 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.24, cairo version 1.16.0)
of 2021-01-04 built on my-little-tumbleweed
Repository revision: 2c847902522ae74c9b25b2a3fa60565e0187fd0a
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12010000
System Description: openSUSE Tumbleweed
Configured using:
'configure --with-xwidgets --with-cairo'
Configured features:
XPM JPEG TIFF GIF PNG RSVG CAIRO SOUND GPM DBUS GSETTINGS GLIB NOTIFY
INOTIFY ACL LIBSELINUX GNUTLS LIBXML2 FREETYPE HARFBUZZ M17N_FLT LIBOTF
ZLIB TOOLKIT_SCROLL_BARS GTK3 X11 XDBE XIM MODULES THREADS XWIDGETS JSON
PDUMPER LCMS2
Important settings:
value of $LC_CTYPE: en_US.UTF-8
value of $LC_TIME: en_GB.UTF-8
value of $LANG: en_US.UTF-8
value of $XMODIFIERS: @im=local
locale-coding-system: utf-8-unix
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#45765
; Package
emacs
.
(Mon, 11 Jan 2021 00:48:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 45765 <at> debbugs.gnu.org (full text, mbox):
Hi Kevin,
On 10.01.2021 14:57, Kévin Le Gouguec wrote:
> Unlike project-shell-command, project-compile first prompts for a
> command, then binds default-directory and calls compile. Binding
> default-directory first makes completion work from the project root,
> which is useful for completing on filenames relative to the root, on
> targets from the toplevel Makefile, etc.
Thanks for the report.
> I see three ways to achieve this:
>
> (1) Rewrite project-compile with call-interactively, the way
> project-shell-command is written (see patch #1).
>
> (2) Set COMMAND to nil in the interactive spec, then prompt for it after
> binding default-directory (see patch #2).
>
> (3) Let-binding default-directory once in the interactive spec, and
> again before calling compile.
> I'm assuming (1) is out of the question, given 2020-06-02
> "* lisp/progmodes/project.el (project-vc-dir, project-shell): New
> commands." (2c1e5b9e77). I'm CC'ing Juri to get his opinion though;
> project-compile is new in Emacs 28.1, so its argument list is not yet
> set in stone.
I see no strong reason to avoid (1), this new command has never seen an
Emacs release, so we're not bound by compatibility promise yet.
Further, any code that would be calling project-compile in a program
should inline its definition instead, in most of the cases.
Let's see what people think, of course.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#45765
; Package
emacs
.
(Mon, 11 Jan 2021 19:01:02 GMT)
Full text and
rfc822 format available.
Message #11 received at submit <at> debbugs.gnu.org (full text, mbox):
> Unlike project-shell-command, project-compile first prompts for a
> command, then binds default-directory and calls compile. Binding
> default-directory first makes completion work from the project root,
> which is useful for completing on filenames relative to the root, on
> targets from the toplevel Makefile, etc.
>
> I see three ways to achieve this:
>
> (1) Rewrite project-compile with call-interactively, the way
> project-shell-command is written (see patch #1).
(1) has the obvious advantage of avoiding duplication of the
interactive spec of 'compile' in 'project-compile', in addition
to your use case of binding default-directory.
> I'm assuming (1) is out of the question, given 2020-06-02
> "* lisp/progmodes/project.el (project-vc-dir, project-shell): New
> commands." (2c1e5b9e77). I'm CC'ing Juri to get his opinion though;
> project-compile is new in Emacs 28.1, so its argument list is not yet
> set in stone.
Actually, (1) is not out of the question. Quite contrary, (1) is
the cleanest solution. But before rewriting with call-interactively,
we need to find a way to use project-compile in the init files, i.e.
to find a replacement for such configurations:
(define-key my-map "m" ;; mnemonics "make"
(lambda ()
(interactive)
(project-compile
;; Use previous command from history
;; instead of the default from compile-command
(compilation-read-command (car compile-history))
;; Don't use compilation-shell-minor-mode
nil)))
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#45765
; Package
emacs
.
(Mon, 11 Jan 2021 19:14:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 45765 <at> debbugs.gnu.org (full text, mbox):
On 11.01.2021 20:35, Juri Linkov wrote:
> But before rewriting with call-interactively,
> we need to find a way to use project-compile in the init files, i.e.
> to find a replacement for such configurations:
>
> (define-key my-map "m" ;; mnemonics "make"
> (lambda ()
> (interactive)
> (project-compile
> ;; Use previous command from history
> ;; instead of the default from compile-command
> (compilation-read-command (car compile-history))
> ;; Don't use compilation-shell-minor-mode
> nil)))
Is it really possible to solve this without making project-compile a
macro of some sort?
For the above code sample not to exhibit the problem from this report,
it should use project-current and project-root directly.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#45765
; Package
emacs
.
(Mon, 11 Jan 2021 21:25:02 GMT)
Full text and
rfc822 format available.
Message #17 received at 45765 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Dmitry Gutov <dgutov <at> yandex.ru> writes:
> On 11.01.2021 20:35, Juri Linkov wrote:
>> But before rewriting with call-interactively,
>> we need to find a way to use project-compile in the init files, i.e.
>> to find a replacement for such configurations:
>> <snip>
>
> Is it really possible to solve this without making project-compile a
> macro of some sort?
Something like this maybe?
[0001-Change-default-directory-before-prompting-in-project.patch (text/x-patch, attachment)]
[Message part 3 (text/plain, inline)]
(Apologies if I misunderstood what Juri asked, or if my suggestion is
buggy)
We can also stick a "\(fn COMMAND &optional COMINT)" in the docstring if
we don't want to advertise the INTERACTIVE argument.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#45765
; Package
emacs
.
(Tue, 12 Jan 2021 18:52:03 GMT)
Full text and
rfc822 format available.
Message #20 received at 45765 <at> debbugs.gnu.org (full text, mbox):
> Something like this maybe?
>
> +(defun project-compile (command &optional comint interactive)
> +COMMAND and COMINT work as with `compile'. When calling this
> +function from Lisp, you can pretend that it was called
> +interactively by passing a non-nil INTERACTIVE argument."
> + (interactive (list nil nil t))
> + (let ((default-directory (project-root (project-current t))))
> + (if interactive
> + (call-interactively #'compile)
> + (compile command comint))))
>
> (Apologies if I misunderstood what Juri asked, or if my suggestion is
> buggy)
Perfect, thank you for finding the middle ground for different needs.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#45765
; Package
emacs
.
(Wed, 13 Jan 2021 01:07:02 GMT)
Full text and
rfc822 format available.
Message #23 received at 45765 <at> debbugs.gnu.org (full text, mbox):
Hi Juri,
On 12.01.2021 20:46, Juri Linkov wrote:
>> Something like this maybe?
>>
>> +(defun project-compile (command &optional comint interactive)
>> +COMMAND and COMINT work as with `compile'. When calling this
>> +function from Lisp, you can pretend that it was called
>> +interactively by passing a non-nil INTERACTIVE argument."
>> + (interactive (list nil nil t))
>> + (let ((default-directory (project-root (project-current t))))
>> + (if interactive
>> + (call-interactively #'compile)
>> + (compile command comint))))
>>
>> (Apologies if I misunderstood what Juri asked, or if my suggestion is
>> buggy)
> Perfect, thank you for finding the middle ground for different needs.
So you're not worried about compilation-read-command in your code being
called in the wrong directory (exhibiting what the current bug report
aims to fix)?
I think you might as well inline the definition, it's almost as short:
(define-key my-map "m" ;; mnemonics "make"
(lambda ()
(interactive)
(let ((default-directory (project-root (project-current t))))
(compile
;; Use previous command from history
;; instead of the default from compile-command
(compilation-read-command (car compile-history))
;; Don't use compilation-shell-minor-mode
nil))))
But if you really like the new version of project-compile, OK.
I'm not a big fan of the 'interactive' argument. It could be replaced by
using (called-interactively-p 'interactive), though I'm not sure how
idiomatic that is.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#45765
; Package
emacs
.
(Wed, 13 Jan 2021 18:09:02 GMT)
Full text and
rfc822 format available.
Message #26 received at 45765 <at> debbugs.gnu.org (full text, mbox):
> So you're not worried about compilation-read-command in your code being
> called in the wrong directory (exhibiting what the current bug report aims
> to fix)?
>
> I think you might as well inline the definition, it's almost as short:
>
> (define-key my-map "m" ;; mnemonics "make"
> (lambda ()
> (interactive)
> (let ((default-directory (project-root (project-current t))))
> (compile
> ;; Use previous command from history
> ;; instead of the default from compile-command
> (compilation-read-command (car compile-history))
> ;; Don't use compilation-shell-minor-mode
> nil))))
Indeed, this means that let-binding default-directory to
(project-root (project-current t))) is unavoidable in the init file.
So it's easier to just replace 'project-compile' with 'compile'.
This means Kévin's first patch is the way to go.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#45765
; Package
emacs
.
(Wed, 13 Jan 2021 19:47:02 GMT)
Full text and
rfc822 format available.
Message #29 received at 45765 <at> debbugs.gnu.org (full text, mbox):
Dmitry Gutov <dgutov <at> yandex.ru> writes:
> I'm not a big fan of the 'interactive' argument. It could be replaced
> by using (called-interactively-p 'interactive), though I'm not sure
> how idiomatic that is.
Not necessarily a fan either, but my takeaway from recent discussions on
emacs-devel is that the argument is preferred to called-interactively-p,
which should only be used when a function's arglist is set in stone.
<E1k7A3J-0005gG-4K <at> fencepost.gnu.org>
https://lists.gnu.org/archive/html/emacs-devel/2020-08/msg00463.html
<jwvzh6ubtbe.fsf-monnier+emacs <at> gnu.org>
https://lists.gnu.org/archive/html/emacs-devel/2020-08/msg00472.html
I see a few dozen hits for "&optional \([\w-]+ \)*interactive)" under
lisp/, so it seems to be an established practice.
PS: I've just seen Juri's reponse in bug#45765#26; I'm glad there is a
consensus on the first patch, because after looking at more in-tree
examples of optional INTERACTIVE arguments, I found myself agonizing
over spelling the spec (list nil nil t), '(nil nil t), or "i\ni\np".
Reply sent
to
Dmitry Gutov <dgutov <at> yandex.ru>
:
You have taken responsibility.
(Sat, 16 Jan 2021 03:52:01 GMT)
Full text and
rfc822 format available.
Notification sent
to
Kévin Le Gouguec <kevin.legouguec <at> gmail.com>
:
bug acknowledged by developer.
(Sat, 16 Jan 2021 03:52:02 GMT)
Full text and
rfc822 format available.
Message #34 received at 45765-done <at> debbugs.gnu.org (full text, mbox):
On 13.01.2021 21:46, Kévin Le Gouguec wrote:
> Dmitry Gutov <dgutov <at> yandex.ru> writes:
>
>> I'm not a big fan of the 'interactive' argument. It could be replaced
>> by using (called-interactively-p 'interactive), though I'm not sure
>> how idiomatic that is.
>
> Not necessarily a fan either, but my takeaway from recent discussions on
> emacs-devel is that the argument is preferred to called-interactively-p,
> which should only be used when a function's arglist is set in stone.
>
> <E1k7A3J-0005gG-4K <at> fencepost.gnu.org>
> https://lists.gnu.org/archive/html/emacs-devel/2020-08/msg00463.html
>
> <jwvzh6ubtbe.fsf-monnier+emacs <at> gnu.org>
> https://lists.gnu.org/archive/html/emacs-devel/2020-08/msg00472.html
>
> I see a few dozen hits for "&optional \([\w-]+ \)*interactive)" under
> lisp/, so it seems to be an established practice.
All right, that makes sense. It will help the next time such question
comes up.
> PS: I've just seen Juri's reponse in bug#45765#26; I'm glad there is a
> consensus on the first patch, because after looking at more in-tree
> examples of optional INTERACTIVE arguments, I found myself agonizing
> over spelling the spec (list nil nil t), '(nil nil t), or "i\ni\np".
I know the feeling ;-)
Patch installed, closing. Thanks again.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#45765
; Package
emacs
.
(Tue, 19 Jan 2021 17:59:02 GMT)
Full text and
rfc822 format available.
Message #37 received at 45765 <at> debbugs.gnu.org (full text, mbox):
>> PS: I've just seen Juri's reponse in bug#45765#26; I'm glad there is a
>> consensus on the first patch, because after looking at more in-tree
>> examples of optional INTERACTIVE arguments, I found myself agonizing
>> over spelling the spec (list nil nil t), '(nil nil t), or "i\ni\np".
>
> I know the feeling ;-)
>
> Patch installed, closing. Thanks again.
Thanks for installing the patch. I noticed that the similar command
project-execute-extended-command has such line:
(declare (interactive-only command-execute))
Should other interactive-only project commands like project-compile
and project(-async)-shell-command have the same?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#45765
; Package
emacs
.
(Tue, 19 Jan 2021 19:51:02 GMT)
Full text and
rfc822 format available.
Message #40 received at 45765 <at> debbugs.gnu.org (full text, mbox):
On 19.01.2021 19:38, Juri Linkov wrote:
> Should other interactive-only project commands like project-compile
> and project(-async)-shell-command have the same?
Makes sense, added, thank you.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Wed, 17 Feb 2021 12:24:13 GMT)
Full text and
rfc822 format available.
This bug report was last modified 4 years and 137 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.