unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Delete multiple repositories programmatically from elisp by supplying `y' as the answer to an interactively called function.
@ 2021-12-07 13:16 Hongyi Zhao
  2021-12-07 17:05 ` Robert Pluim
  2021-12-07 22:20 ` Michael Heerdegen
  0 siblings, 2 replies; 13+ messages in thread
From: Hongyi Zhao @ 2021-12-07 13:16 UTC (permalink / raw)
  To: help-gnu-emacs

The straight package manager [1] supplies the following interactive
function, which can be used to delete the unused repositories:
straight-remove-unused-repos. As we all know, the normal way to call
this function is `M-x straight-remove-unused-repos RET package-name
RET`. However, the above method can only delete one repository at a
time. If I have many unused repositories that I want to clean up now,
this method is very inefficient.

In order to achieve a more efficient way, I want to loop over the
following command programmatically from elisp, and supply `y' as the
answer repeatedly:

(call-interactively #'straight-remove-unused-repos)

But I still can't figure out the code snippet for doing the above
work. Any hints will be greatly appreciated.

[1] https://github.com/raxod502/straight.el

Regards,
HZ



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Delete multiple repositories programmatically from elisp by supplying `y' as the answer to an interactively called function.
  2021-12-07 13:16 Delete multiple repositories programmatically from elisp by supplying `y' as the answer to an interactively called function Hongyi Zhao
@ 2021-12-07 17:05 ` Robert Pluim
  2021-12-07 19:14   ` Emanuel Berg via Users list for the GNU Emacs text editor
                     ` (2 more replies)
  2021-12-07 22:20 ` Michael Heerdegen
  1 sibling, 3 replies; 13+ messages in thread
From: Robert Pluim @ 2021-12-07 17:05 UTC (permalink / raw)
  To: Hongyi Zhao; +Cc: help-gnu-emacs

>>>>> On Tue, 7 Dec 2021 21:16:00 +0800, Hongyi Zhao <hongyi.zhao@gmail.com> said:

    Hongyi> The straight package manager [1] supplies the following interactive
    Hongyi> function, which can be used to delete the unused repositories:
    Hongyi> straight-remove-unused-repos. As we all know, the normal way to call
    Hongyi> this function is `M-x straight-remove-unused-repos RET package-name
    Hongyi> RET`. However, the above method can only delete one repository at a
    Hongyi> time. If I have many unused repositories that I want to clean up now,
    Hongyi> this method is very inefficient.

    Hongyi> In order to achieve a more efficient way, I want to loop over the
    Hongyi> following command programmatically from elisp, and supply `y' as the
    Hongyi> answer repeatedly:

    Hongyi> (call-interactively #'straight-remove-unused-repos)

    Hongyi> But I still can't figure out the code snippet for doing the above
    Hongyi> work. Any hints will be greatly appreciated.

    Hongyi> [1] https://github.com/raxod502/straight.el

That function takes a 'force' argument, so if you manage to supply any
prefix arg at all it will delete all the repos without prompting. One
way to do that is by using `current-prefix-arg':

(let ((current-prefix-arg '(4)))
  (call-interactively #'straight-remove-unused-repos))

Robert
-- 



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Delete multiple repositories programmatically from elisp by supplying `y' as the answer to an interactively called function.
  2021-12-07 17:05 ` Robert Pluim
@ 2021-12-07 19:14   ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-12-08  9:41     ` Robert Pluim
  2021-12-07 23:35   ` Hongyi Zhao
  2021-12-08  2:56   ` Hongyi Zhao
  2 siblings, 1 reply; 13+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-12-07 19:14 UTC (permalink / raw)
  To: help-gnu-emacs

Robert Pluim wrote:

> That function takes a 'force' argument, so if you manage to
> supply any prefix arg at all it will delete all the repos
> without prompting. One way to do that is by using
> `current-prefix-arg':
>
> (let ((current-prefix-arg '(4)))
>   (call-interactively #'straight-remove-unused-repos))

Why does it have to be used interactively?

That's often not a good sign ...

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Delete multiple repositories programmatically from elisp by supplying `y' as the answer to an interactively called function.
  2021-12-07 13:16 Delete multiple repositories programmatically from elisp by supplying `y' as the answer to an interactively called function Hongyi Zhao
  2021-12-07 17:05 ` Robert Pluim
@ 2021-12-07 22:20 ` Michael Heerdegen
  2021-12-07 23:49   ` Hongyi Zhao
  1 sibling, 1 reply; 13+ messages in thread
From: Michael Heerdegen @ 2021-12-07 22:20 UTC (permalink / raw)
  To: help-gnu-emacs

Hongyi Zhao <hongyi.zhao@gmail.com> writes:

> But I still can't figure out the code snippet for doing the above
> work. Any hints will be greatly appreciated.
>
> [1] https://github.com/raxod502/straight.el

Best solution: a feature request.  I don't use that package manager but
your wish doesn't sound far-fetched.  The authors may want to add a "!"
choice meaning "confirm all" or something like that.

Second best: use a hack to make the code work as you want.  May involve
advising and/or other changes of symbol function bindings.  Only
advisable if you understand what that means and how it works.

Michael.




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Delete multiple repositories programmatically from elisp by supplying `y' as the answer to an interactively called function.
  2021-12-07 17:05 ` Robert Pluim
  2021-12-07 19:14   ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-12-07 23:35   ` Hongyi Zhao
  2021-12-08  2:56   ` Hongyi Zhao
  2 siblings, 0 replies; 13+ messages in thread
From: Hongyi Zhao @ 2021-12-07 23:35 UTC (permalink / raw)
  To: Robert Pluim; +Cc: help-gnu-emacs

On Wed, Dec 8, 2021 at 1:05 AM Robert Pluim <rpluim@gmail.com> wrote:
> That function takes a 'force' argument, so if you manage to supply any
> prefix arg at all it will delete all the repos without prompting. One
> way to do that is by using `current-prefix-arg':
>
> (let ((current-prefix-arg '(4)))
>   (call-interactively #'straight-remove-unused-repos))

Thank you for pointing this out. It does the trick.

HZ



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Delete multiple repositories programmatically from elisp by supplying `y' as the answer to an interactively called function.
  2021-12-07 22:20 ` Michael Heerdegen
@ 2021-12-07 23:49   ` Hongyi Zhao
  0 siblings, 0 replies; 13+ messages in thread
From: Hongyi Zhao @ 2021-12-07 23:49 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: help-gnu-emacs

On Wed, Dec 8, 2021 at 6:21 AM Michael Heerdegen
<michael_heerdegen@web.de> wrote:
>
> Hongyi Zhao <hongyi.zhao@gmail.com> writes:
>
> > But I still can't figure out the code snippet for doing the above
> > work. Any hints will be greatly appreciated.
> >
> > [1] https://github.com/raxod502/straight.el
>
> Best solution: a feature request.  I don't use that package manager but
> your wish doesn't sound far-fetched.  The authors may want to add a "!"
> choice meaning "confirm all" or something like that.

I filed the feature request here:

https://github.com/raxod502/straight.el/issues/898

HZ



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Delete multiple repositories programmatically from elisp by supplying `y' as the answer to an interactively called function.
  2021-12-07 17:05 ` Robert Pluim
  2021-12-07 19:14   ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-12-07 23:35   ` Hongyi Zhao
@ 2021-12-08  2:56   ` Hongyi Zhao
  2021-12-08  3:15     ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-12-08  9:07     ` Robert Pluim
  2 siblings, 2 replies; 13+ messages in thread
From: Hongyi Zhao @ 2021-12-08  2:56 UTC (permalink / raw)
  To: Robert Pluim; +Cc: help-gnu-emacs

On Wed, Dec 8, 2021 at 1:05 AM Robert Pluim <rpluim@gmail.com> wrote:
> That function takes a 'force' argument, so if you manage to supply any
> prefix arg at all it will delete all the repos without prompting. One
> way to do that is by using `current-prefix-arg':
>
> (let ((current-prefix-arg '(4)))
>   (call-interactively #'straight-remove-unused-repos))

The author told me the following solution here [1]:

==========

Please see: https://www.gnu.org/software/emacs/manual/html_node/emacs/Arguments.html

You can pass the universal argument to the command and force will be non-nil.

And if you wish to use the command in an elisp program you can just
pass the force argument you desire:

(straight-remove-unused-repos 'force)

==========

[1] https://github.com/raxod502/straight.el/issues/898#issuecomment-988352840

Regards,
HZ



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Delete multiple repositories programmatically from elisp by supplying `y' as the answer to an interactively called function.
  2021-12-08  2:56   ` Hongyi Zhao
@ 2021-12-08  3:15     ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-12-08  3:45       ` Hongyi Zhao
  2021-12-08  9:07     ` Robert Pluim
  1 sibling, 1 reply; 13+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-12-08  3:15 UTC (permalink / raw)
  To: help-gnu-emacs

Hongyi Zhao wrote:

> You can pass the universal argument to the command and force
> will be non-nil.
>
> And if you wish to use the command in an elisp program you
> can just pass the force argument you desire:
>
> (straight-remove-unused-repos 'force)

Told you so ...

Just

  (straight-remove-unused-repos t)

will do.

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Delete multiple repositories programmatically from elisp by supplying `y' as the answer to an interactively called function.
  2021-12-08  3:15     ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-12-08  3:45       ` Hongyi Zhao
  0 siblings, 0 replies; 13+ messages in thread
From: Hongyi Zhao @ 2021-12-08  3:45 UTC (permalink / raw)
  To: Emanuel Berg, help-gnu-emacs

On Wed, Dec 8, 2021 at 11:15 AM Emanuel Berg via Users list for the
GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote:
>
> Hongyi Zhao wrote:
>
> > You can pass the universal argument to the command and force
> > will be non-nil.
> >
> > And if you wish to use the command in an elisp program you
> > can just pass the force argument you desire:
> >
> > (straight-remove-unused-repos 'force)
>
> Told you so ...
>
> Just
>
>   (straight-remove-unused-repos t)

Yes. Anything non-nil will do the trick.

HZ



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Delete multiple repositories programmatically from elisp by supplying `y' as the answer to an interactively called function.
  2021-12-08  2:56   ` Hongyi Zhao
  2021-12-08  3:15     ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-12-08  9:07     ` Robert Pluim
  2021-12-08  9:13       ` Emanuel Berg via Users list for the GNU Emacs text editor
  1 sibling, 1 reply; 13+ messages in thread
From: Robert Pluim @ 2021-12-08  9:07 UTC (permalink / raw)
  To: Hongyi Zhao; +Cc: help-gnu-emacs

>>>>> On Wed, 8 Dec 2021 10:56:12 +0800, Hongyi Zhao <hongyi.zhao@gmail.com> said:

    Hongyi> On Wed, Dec 8, 2021 at 1:05 AM Robert Pluim <rpluim@gmail.com> wrote:
    >> That function takes a 'force' argument, so if you manage to supply any
    >> prefix arg at all it will delete all the repos without prompting. One
    >> way to do that is by using `current-prefix-arg':
    >> 
    >> (let ((current-prefix-arg '(4)))
    >> (call-interactively #'straight-remove-unused-repos))

    Hongyi> The author told me the following solution here [1]:

    Hongyi> ==========

    Hongyi> Please see: https://www.gnu.org/software/emacs/manual/html_node/emacs/Arguments.html

    Hongyi> You can pass the universal argument to the command and force will be non-nil.

    Hongyi> And if you wish to use the command in an elisp program you can just
    Hongyi> pass the force argument you desire:

    Hongyi> (straight-remove-unused-repos 'force)

    Hongyi> ==========

    Hongyi> [1] https://github.com/raxod502/straight.el/issues/898#issuecomment-988352840

Yes, that works for `straight-remove-unused-repos', because it only
cares about the argument being non-nil. There are commands that care
about the actual value of `current-prefix-arg', and then you have to
bind it via `let'.

Robert
-- 



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Delete multiple repositories programmatically from elisp by supplying `y' as the answer to an interactively called function.
  2021-12-08  9:07     ` Robert Pluim
@ 2021-12-08  9:13       ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 0 replies; 13+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-12-08  9:13 UTC (permalink / raw)
  To: help-gnu-emacs

Robert Pluim wrote:

>> (straight-remove-unused-repos 'force)
>
> Yes, that works for `straight-remove-unused-repos', because
> it only cares about the argument being non-nil. There are
> commands that care about the actual value of
> `current-prefix-arg', and then you have to bind it via
> `let'.

Well, it is a good idea to do anyway :)

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Delete multiple repositories programmatically from elisp by supplying `y' as the answer to an interactively called function.
  2021-12-07 19:14   ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-12-08  9:41     ` Robert Pluim
  2021-12-08 10:47       ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 13+ messages in thread
From: Robert Pluim @ 2021-12-08  9:41 UTC (permalink / raw)
  To: help-gnu-emacs

>>>>> On Tue, 07 Dec 2021 20:14:12 +0100, Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> said:

    Emanuel> Robert Pluim wrote:
    >> That function takes a 'force' argument, so if you manage to
    >> supply any prefix arg at all it will delete all the repos
    >> without prompting. One way to do that is by using
    >> `current-prefix-arg':
    >> 
    >> (let ((current-prefix-arg '(4)))
    >> (call-interactively #'straight-remove-unused-repos))

    Emanuel> Why does it have to be used interactively?

    Emanuel> That's often not a good sign ...

In this case it doesnʼt. Other commands inspect the value of
current-prefix-arg, not just the value produced by their `interactive'
spec, and then you have to use this particular hammer.

Robert
-- 



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Delete multiple repositories programmatically from elisp by supplying `y' as the answer to an interactively called function.
  2021-12-08  9:41     ` Robert Pluim
@ 2021-12-08 10:47       ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 0 replies; 13+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-12-08 10:47 UTC (permalink / raw)
  To: help-gnu-emacs

Robert Pluim wrote:

>>> (let ((current-prefix-arg '(4)))
>>>   (call-interactively #'straight-remove-unused-repos))
>>
>> Why does it have to be used interactively?
>> That's often not a good sign ...
>
> In this case it doesn't. Other commands inspect the value of
> current-prefix-arg, not just the value produced by their
> `interactive' spec, and then you have to use this
> particular hammer.

In the function body, in my experience it is best to refer to
the formal parameter, if one desires a default value one can
examine if it is unset and set it in a `let', then use the
let binding. Do this before anything else happens ...

Like below [last], it it works from Lisp without an argument,
from Lisp with an argument, interactively without an argument,
and interactively with a (prefix) argument.

It is often less complicated tho ... like this

  (defun some-fun (&optional n)
    (interactive "P")
    (let ((num (or n 12)))
      (message "move it! %d" num) ))

  (some-fun)                 ; 12, the default
  (some-fun 10)              ; 10
  ;; C-u 7 M-x some-fun RET  ;  7
  ;; M-x some-fun RET        ; 12, again

Anyway ...

;;; -*- lexical-binding: t -*-
;;;
;;; this file:
;;;   http://user.it.uu.se/~embe8573/emacs-init/string.el
;;;   https://dataswamp.org/~incal/emacs-init/string.el

(defun hline (&optional char)
  (interactive "P")
  (let ((len (- (window-width) (or (current-column) 0) 1))
        (c   (or (and (listp char) (car char))
                 (and (numberp char) char)
                 ?-) ))
    (insert (make-string len c)) ))
(defalias 'hl #'hline)

(when nil
  (hline)----------------------------------------------------------------------
  (hline 42)*******************************************************************
  (hline ?+)+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  M-x hline RET----------------------------------------------------------------
  C-u C-u C-u M-x hline RET@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  C-u 59 M-x hline RET;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
)

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2021-12-08 10:47 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-07 13:16 Delete multiple repositories programmatically from elisp by supplying `y' as the answer to an interactively called function Hongyi Zhao
2021-12-07 17:05 ` Robert Pluim
2021-12-07 19:14   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-12-08  9:41     ` Robert Pluim
2021-12-08 10:47       ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-12-07 23:35   ` Hongyi Zhao
2021-12-08  2:56   ` Hongyi Zhao
2021-12-08  3:15     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-12-08  3:45       ` Hongyi Zhao
2021-12-08  9:07     ` Robert Pluim
2021-12-08  9:13       ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-12-07 22:20 ` Michael Heerdegen
2021-12-07 23:49   ` Hongyi Zhao

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