* bug#13625: 24.1; Enable 'package-menu-execute being non-interactive
@ 2013-02-03 23:49 Yves Baumes
2013-02-04 3:39 ` Stefan Monnier
2013-02-05 16:38 ` bug#13625: Rép : " Yves Baumes
0 siblings, 2 replies; 9+ messages in thread
From: Yves Baumes @ 2013-02-03 23:49 UTC (permalink / raw)
To: 13625
Hi,
I was trying to make a little program to upgrade automatically my
packages archives. Basically something looking like that:
(progn
(list-packages)
(with-current-buffer "*Packages*"
(package-menu-mark-upgrades)
(package-menu-execute)
(kill-buffer)))
The 'package-menu-execute implementation relies on the user to,
interactively, answer yes-or-no to a question asking him to confirm
he wants to upgrade the packages needing an upgrade.
Well, from my point of view the implementation must be silent when
called non interactively. And proceed with the packages upgrades.
Here is a modification that I made that suit my needs:
(defun package-menu-execute ()
...
(when install-list
(if (or
(not (called-interactively-p 'any))
(yes-or-no-p
...
;; Delete packages, prompting if necessary.
(when delete-list
(if (or
(not (called-interactively-p 'any))
(yes-or-no-p
...
Then, first, I am a newbie in Emacs Lisp modifications. Secondly, the
changelog suggests that package.el has not been modified for a while
ago. Since I could not believe I would be the first needing that
modification in five years, I guess that I maybe wrong somewhere, and
that there must be an easier way to perform what I am trying to do. Then
my question is basically what is a correct behavior according to you and
is my "solution" acceptable?
Regards
Yves
^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#13625: 24.1; Enable 'package-menu-execute being non-interactive
2013-02-03 23:49 bug#13625: 24.1; Enable 'package-menu-execute being non-interactive Yves Baumes
@ 2013-02-04 3:39 ` Stefan Monnier
2013-02-04 11:18 ` Yves Baumes
2013-02-05 16:38 ` bug#13625: Rép : " Yves Baumes
1 sibling, 1 reply; 9+ messages in thread
From: Stefan Monnier @ 2013-02-04 3:39 UTC (permalink / raw)
To: Yves Baumes; +Cc: 13625
> Well, from my point of view the implementation must be silent when
> called non interactively.
As a general rule, I tend to agree.
> Here is a modification that I made that suit my needs:
> (defun package-menu-execute ()
> ...
> (when install-list
> (if (or
> (not (called-interactively-p 'any))
> (yes-or-no-p
> ...
> ;; Delete packages, prompting if necessary.
> (when delete-list
> (if (or
> (not (called-interactively-p 'any))
> (yes-or-no-p
> ...
Better would be to move those questions to the `interactive' spec, so
you don't even need called-interactively-p.
But you'd also want to check if there are callers of this function that
would need to be adjusted.
Stefan
^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#13625: 24.1; Enable 'package-menu-execute being non-interactive
2013-02-04 3:39 ` Stefan Monnier
@ 2013-02-04 11:18 ` Yves Baumes
2013-02-04 15:13 ` Stefan Monnier
0 siblings, 1 reply; 9+ messages in thread
From: Yves Baumes @ 2013-02-04 11:18 UTC (permalink / raw)
To: Stefan Monnier; +Cc: 13625
Le 4 févr. 2013 à 04:39, Stefan Monnier a écrit :
> Better would be to move those questions to the `interactive' spec, so
> you don't even need called-interactively-p.
Ok. I've read the Emacs Lisp Reference manual. As you told, they say an alternative to `called-interactively-p' is possible with `interactive'. Note sure if I understand it all with this example:
(defun test (&optional print-msg)
(interactive "p")
(if print-msg
(message "IS INTERACTIVE")
(message "IS *NOT* INTERACTIVE")))
So, if I understand it all, it would imply to add an extra argument to the `package-menu-execute' function, right? To me it sounds weird, but then it may be an usual idiom in Emacs Lisp I am not used to. If so just confirm me please :-).
> But you'd also want to check if there are callers of this function that
> would need to be adjusted.
>
I've checked inside the package.el file. And this function is never called. It is only defined, and referenced (when building the keymap).
As a side note: I didn't checked in other Elpa/Marmalade/etc packages. I guess it doesn't make sense to try to research potential callers everywhere in the world. I don't even know if there is a simple way to do that.
I am checking right now the emacs savannah homepage for contribution. How to checkout the latest bazzar code and what to provide along the patch. I will try to find an issue in the bug tracker corrrectly formatted. I keep you in touch :-)
Regards
Yves
^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#13625: 24.1; Enable 'package-menu-execute being non-interactive
2013-02-04 11:18 ` Yves Baumes
@ 2013-02-04 15:13 ` Stefan Monnier
2013-02-04 17:59 ` Yves Baumes
0 siblings, 1 reply; 9+ messages in thread
From: Stefan Monnier @ 2013-02-04 15:13 UTC (permalink / raw)
To: Yves Baumes; +Cc: 13625
>> Better would be to move those questions to the `interactive' spec, so
>> you don't even need called-interactively-p.
> Ok. I've read the Emacs Lisp Reference manual. As you told, they say
> an alternative to `called-interactively-p' is possible with
> `interactive'. Note sure if I understand it all with this example:
> (defun test (&optional print-msg)
> (interactive "p")
> (if print-msg
> (message "IS INTERACTIVE")
> (message "IS *NOT* INTERACTIVE")))
That's one option: it doesn't move the questions to the interactive
spec, but it removes the use of called-interactively-p.
What I was suggesting was more like:
(defun test ()
(interactive
(if (yes-or-no-p ...) ... ...)))
but I see that it's probably not applicable to package-menu-execute.
Maybe the best option here is to add an optional `dont-query' argument.
Stefan
^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#13625: 24.1; Enable 'package-menu-execute being non-interactive
2013-02-04 15:13 ` Stefan Monnier
@ 2013-02-04 17:59 ` Yves Baumes
2013-02-04 19:44 ` Stefan Monnier
0 siblings, 1 reply; 9+ messages in thread
From: Yves Baumes @ 2013-02-04 17:59 UTC (permalink / raw)
To: Stefan Monnier; +Cc: 13625
[-- Attachment #1: Type: text/plain, Size: 3948 bytes --]
Le 4 févr. 2013 à 16:13, Stefan Monnier a écrit :
> Maybe the best option here is to add an optional `dont-query' argument.
I've fiddled around a little bit, so tell me if my reasoning is ok.
I've found that whatever you do, an interactive call provide a
numeric value of '1'. Reading the Emacs Lisp Reference Manual,
I didn't find a way to negate the boolean value with `interactive'. As a matter
of fact I would suggest that `dont-query' must not be a good name since its value
would be 'true' when the function is called interactively while we want the user
to be queried in that case.
I made my modification with `prompt-user' as a parameter name.
One could think as another alternative, such as `query-user'.
Would it be more appropriate? I can't tell which one sounds better actually.
I am not fluent in english.. :-/
So here is the diff:
=== modified file 'lisp/emacs-lisp/package.el'
--- lisp/emacs-lisp/package.el 2013-01-01 09:11:05 +0000
+++ lisp/emacs-lisp/package.el 2013-02-04 17:17:41 +0000
@@ -1588,11 +1588,11 @@
(length upgrades)
(if (= (length upgrades) 1) "" "s")))))
-(defun package-menu-execute ()
+(defun package-menu-execute (&optional prompt-user)
"Perform marked Package Menu actions.
Packages marked for installation are downloaded and installed;
packages marked for deletion are removed."
- (interactive)
+ (interactive "p")
(unless (derived-mode-p 'package-menu-mode)
(error "The current buffer is not in Package Menu mode"))
(let (install-list delete-list cmd id)
@@ -1611,26 +1611,30 @@
(push (car id) install-list))))
(forward-line)))
(when install-list
- (if (yes-or-no-p
- (if (= (length install-list) 1)
- (format "Install package `%s'? " (car install-list))
- (format "Install these %d packages (%s)? "
- (length install-list)
- (mapconcat 'symbol-name install-list ", "))))
+ (if (or
+ (not prompt-user)
+ (yes-or-no-p
+ (if (= (length install-list) 1)
+ (format "Install package `%s'? " (car install-list))
+ (format "Install these %d packages (%s)? "
+ (length install-list)
+ (mapconcat 'symbol-name install-list ", ")))))
(mapc 'package-install install-list)))
;; Delete packages, prompting if necessary.
(when delete-list
- (if (yes-or-no-p
- (if (= (length delete-list) 1)
- (format "Delete package `%s-%s'? "
- (caar delete-list)
- (cdr (car delete-list)))
- (format "Delete these %d packages (%s)? "
- (length delete-list)
- (mapconcat (lambda (elt)
- (concat (car elt) "-" (cdr elt)))
- delete-list
- ", "))))
+ (if (or
+ (not prompt-user)
+ (yes-or-no-p
+ (if (= (length delete-list) 1)
+ (format "Delete package `%s-%s'? "
+ (caar delete-list)
+ (cdr (car delete-list)))
+ (format "Delete these %d packages (%s)? "
+ (length delete-list)
+ (mapconcat (lambda (elt)
+ (concat (car elt) "-" (cdr elt)))
+ delete-list
+ ", ")))))
(dolist (elt delete-list)
(condition-case-unless-debug err
(package-delete (car elt) (cdr elt))
The new code in this patch negates the `prompt-user' value since we want to
apply the changes when the user is not prompted *or* in the case he must be
prompted then he must reply 'yes'.
Maybe a good Changelog line could be:
"* emacs-lisp/package.el(package-menu-execute): Don't prompt for the user when `package-menu-execute' is called non-interactively."
Tell me if I forget something, or if something is wrong for you.
Regards
Yves
[-- Attachment #2: Type: text/html, Size: 8474 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#13625: 24.1; Enable 'package-menu-execute being non-interactive
2013-02-04 17:59 ` Yves Baumes
@ 2013-02-04 19:44 ` Stefan Monnier
2013-02-04 22:09 ` Yves Baumes
0 siblings, 1 reply; 9+ messages in thread
From: Stefan Monnier @ 2013-02-04 19:44 UTC (permalink / raw)
To: Yves Baumes; +Cc: 13625
> I've found that whatever you do, an interactive call provide a numeric
> value of '1'. Reading the Emacs Lisp Reference Manual, I didn't find
> a way to negate the boolean value with `interactive'.
But since it's an optional parameter, you can just not provide it, in
which case it defaults to nil.
> -(defun package-menu-execute ()
> +(defun package-menu-execute (&optional prompt-user)
^^^^^^^^^^^
dont-query
> "Perform marked Package Menu actions.
> Packages marked for installation are downloaded and installed;
> packages marked for deletion are removed."
> - (interactive)
> + (interactive "p")
Leave it as (interactive) which will not provide any argument, so
dont-query will be nil for interactive calls. And for your own calls,
you can pass a non-nil argument.
Stefan
^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#13625: 24.1; Enable 'package-menu-execute being non-interactive
2013-02-04 19:44 ` Stefan Monnier
@ 2013-02-04 22:09 ` Yves Baumes
0 siblings, 0 replies; 9+ messages in thread
From: Yves Baumes @ 2013-02-04 22:09 UTC (permalink / raw)
To: Stefan Monnier; +Cc: 13625
Ok! I was stuck, with the `interactive' ... Then here is the revised diff:
=== modified file 'lisp/emacs-lisp/package.el'
--- lisp/emacs-lisp/package.el 2013-01-01 09:11:05 +0000
+++ lisp/emacs-lisp/package.el 2013-02-04 21:49:41 +0000
@@ -1588,7 +1588,7 @@
(length upgrades)
(if (= (length upgrades) 1) "" "s")))))
-(defun package-menu-execute ()
+(defun package-menu-execute (&optional dont-query)
"Perform marked Package Menu actions.
Packages marked for installation are downloaded and installed;
packages marked for deletion are removed."
@@ -1611,26 +1611,30 @@
(push (car id) install-list))))
(forward-line)))
(when install-list
- (if (yes-or-no-p
- (if (= (length install-list) 1)
- (format "Install package `%s'? " (car install-list))
- (format "Install these %d packages (%s)? "
- (length install-list)
- (mapconcat 'symbol-name install-list ", "))))
+ (if (or
+ dont-query
+ (yes-or-no-p
+ (if (= (length install-list) 1)
+ (format "Install package `%s'? " (car install-list))
+ (format "Install these %d packages (%s)? "
+ (length install-list)
+ (mapconcat 'symbol-name install-list ", ")))))
(mapc 'package-install install-list)))
;; Delete packages, prompting if necessary.
(when delete-list
- (if (yes-or-no-p
- (if (= (length delete-list) 1)
- (format "Delete package `%s-%s'? "
- (caar delete-list)
- (cdr (car delete-list)))
- (format "Delete these %d packages (%s)? "
- (length delete-list)
- (mapconcat (lambda (elt)
- (concat (car elt) "-" (cdr elt)))
- delete-list
- ", "))))
+ (if (or
+ dont-query
+ (yes-or-no-p
+ (if (= (length delete-list) 1)
+ (format "Delete package `%s-%s'? "
+ (caar delete-list)
+ (cdr (car delete-list)))
+ (format "Delete these %d packages (%s)? "
+ (length delete-list)
+ (mapconcat (lambda (elt)
+ (concat (car elt) "-" (cdr elt)))
+ delete-list
+ ", ")))))
(dolist (elt delete-list)
(condition-case-unless-debug err
(package-delete (car elt) (cdr elt))
As you wrote in previous emails, every possible call to
`package-menu-execute' remains compatible as is.
And I just needed to add a `t' parameter in my script.
Just perfect. :-)
Regards
Yves
Le 4 févr. 2013 à 20:44, Stefan Monnier a écrit :
>> I've found that whatever you do, an interactive call provide a numeric
>> value of '1'. Reading the Emacs Lisp Reference Manual, I didn't find
>> a way to negate the boolean value with `interactive'.
>
> But since it's an optional parameter, you can just not provide it, in
> which case it defaults to nil.
>
>> -(defun package-menu-execute ()
>> +(defun package-menu-execute (&optional prompt-user)
> ^^^^^^^^^^^
> dont-query
>
>> "Perform marked Package Menu actions.
>> Packages marked for installation are downloaded and installed;
>> packages marked for deletion are removed."
>> - (interactive)
>> + (interactive "p")
>
> Leave it as (interactive) which will not provide any argument, so
> dont-query will be nil for interactive calls. And for your own calls,
> you can pass a non-nil argument.
>
>
> Stefan
^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#13625: Rép : bug#13625: 24.1; Enable 'package-menu-execute being non-interactive
2013-02-03 23:49 bug#13625: 24.1; Enable 'package-menu-execute being non-interactive Yves Baumes
2013-02-04 3:39 ` Stefan Monnier
@ 2013-02-05 16:38 ` Yves Baumes
2013-02-13 5:01 ` Glenn Morris
1 sibling, 1 reply; 9+ messages in thread
From: Yves Baumes @ 2013-02-05 16:38 UTC (permalink / raw)
To: 13625
[-- Attachment #1: Bzr bundle for the bug#16325. --]
[-- Type: text/plain, Size: 5235 bytes --]
# Bazaar merge directive format 2 (Bazaar 0.90)
# revision_id: ybaumes@gmail.com-20130205153237-82xdt2b5f4i85bv2
# target_branch: bzr://bzr.savannah.gnu.org/emacs/trunk/
# testament_sha1: 509b0f8920808cc725a441fb32877e16e6ec513f
# timestamp: 2013-02-05 16:34:09 +0100
# source_branch: bzr://bzr.savannah.gnu.org/emacs/trunk
# base_revision_id: jan.h.d@swipnet.se-20130205122155-exqwhauamc0k0y1a
#
# Begin patch
=== modified file 'lisp/ChangeLog'
--- lisp/ChangeLog 2013-02-05 12:16:35 +0000
+++ lisp/ChangeLog 2013-02-05 15:32:37 +0000
@@ -1,3 +1,8 @@
+2013-02-05 Yves Baumes <ybaumes@gmail.com>
+
+ * lisp/emacs-lisp/package.el (package-menu-execute): Don't query
+ for the user input when called non-interactively (bug#13625).
+
2013-02-05 Jan Djärv <jan.h.d@swipnet.se>
* cus-start.el (all): Add ns-use-native-fullscreen.
=== modified file 'lisp/emacs-lisp/package.el'
--- lisp/emacs-lisp/package.el 2013-01-01 09:11:05 +0000
+++ lisp/emacs-lisp/package.el 2013-02-05 15:32:37 +0000
@@ -1588,7 +1588,7 @@
(length upgrades)
(if (= (length upgrades) 1) "" "s")))))
-(defun package-menu-execute ()
+(defun package-menu-execute (&optional dont-query)
"Perform marked Package Menu actions.
Packages marked for installation are downloaded and installed;
packages marked for deletion are removed."
@@ -1611,26 +1611,30 @@
(push (car id) install-list))))
(forward-line)))
(when install-list
- (if (yes-or-no-p
- (if (= (length install-list) 1)
- (format "Install package `%s'? " (car install-list))
- (format "Install these %d packages (%s)? "
- (length install-list)
- (mapconcat 'symbol-name install-list ", "))))
+ (if (or
+ dont-query
+ (yes-or-no-p
+ (if (= (length install-list) 1)
+ (format "Install package `%s'? " (car install-list))
+ (format "Install these %d packages (%s)? "
+ (length install-list)
+ (mapconcat 'symbol-name install-list ", ")))))
(mapc 'package-install install-list)))
;; Delete packages, prompting if necessary.
(when delete-list
- (if (yes-or-no-p
- (if (= (length delete-list) 1)
- (format "Delete package `%s-%s'? "
- (caar delete-list)
- (cdr (car delete-list)))
- (format "Delete these %d packages (%s)? "
- (length delete-list)
- (mapconcat (lambda (elt)
- (concat (car elt) "-" (cdr elt)))
- delete-list
- ", "))))
+ (if (or
+ dont-query
+ (yes-or-no-p
+ (if (= (length delete-list) 1)
+ (format "Delete package `%s-%s'? "
+ (caar delete-list)
+ (cdr (car delete-list)))
+ (format "Delete these %d packages (%s)? "
+ (length delete-list)
+ (mapconcat (lambda (elt)
+ (concat (car elt) "-" (cdr elt)))
+ delete-list
+ ", ")))))
(dolist (elt delete-list)
(condition-case-unless-debug err
(package-delete (car elt) (cdr elt))
# Begin bundle
IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWVO9iMYAAuR/gDD0FALb9//3
3iQAIP////BQBd5ytjWgaU0UAAQklNFMZR5TI2jTRPTKekxHqNAAABoBzAEYJiAYBME0ZDQwCYIx
MJTUaUYU2oPQhkAA0GCAGg0ABzAEYJiAYBME0ZDQwCYIxMJJATQIZMiaZMg01MmintU/SmATBPUb
KYFoE19fHbwg8lMd+/YHZy5U77T+j+S0OoYZvoxXqLHKhDnqQnnO4ezaIxfOghA5CPpX6BzLrmD8
xrBDMVlctQ76o4iyexYM11MkC+M4TRn0THKL1ogsivQIRdKUVq22ykLhaM9xLUQ5d91ncewQ6S6S
IzWKQImQyUiMmIFgfPSciX89uyMSmVF/huCIs4GAnIFOfsEtYesTNkTJZeGGSCWMxDmVJIQ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38RDwrRBw
VaoigOCCXvlrNaRWlix2TRRi0CTDl2CLDQlV5MKaoCw0GuyUFCwlFEQaAwTvN71GKHeYOeqgmpkD
aHv/seEqJhwyZkmXDiUDV9cj23JHyKVDIeru5UPr1FxcckOSyctUDgLdDMKj1OLM83sMG4mq8At3
/L0qlmKXo6zUM3spGd6bgOHg5DI63pWd9FLwuqSze+B8ouBmYYX3o7BwzCJ7nL0DMuwZWmxDFQYV
wFRkGsTpi+Acz87zIBxePXgMDUCgWgT7oHUE0qpjDIfoibAr8gcFedmk24l6K1FmYMcDUw9Vp+e1
G5d0QTV6C4uVJgeoTuLV9jNFpcrTMvCwIloeoFSREwWYyONZjMmMGoymcuaiO+qI/8XckU4UJBTv
YjGA
[-- Attachment #2: Type: text/plain, Size: 64 bytes --]
Attached is a bzr bundle for the modifications.
Regards
Yves
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2013-02-13 5:01 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-02-03 23:49 bug#13625: 24.1; Enable 'package-menu-execute being non-interactive Yves Baumes
2013-02-04 3:39 ` Stefan Monnier
2013-02-04 11:18 ` Yves Baumes
2013-02-04 15:13 ` Stefan Monnier
2013-02-04 17:59 ` Yves Baumes
2013-02-04 19:44 ` Stefan Monnier
2013-02-04 22:09 ` Yves Baumes
2013-02-05 16:38 ` bug#13625: Rép : " Yves Baumes
2013-02-13 5:01 ` Glenn Morris
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.