[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Delete multiple repositories programmatically from elisp by supplyin

From: Emanuel Berg
Subject: Re: Delete multiple repositories programmatically from elisp by supplying `y' as the answer to an interactively called function.
Date: Wed, 08 Dec 2021 11:47:31 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

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:

(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 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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]