help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: shell-command-on-region but with command line arguments


From: Emanuel Berg
Subject: Re: shell-command-on-region but with command line arguments
Date: Wed, 09 Nov 2022 11:37:51 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

Bruno Barbier wrote:

> Something like:
>
>   (defun my-on-region (where how) ... )

(defun command (cmd &optional args beg end) ...)

where args is a list of arguments, &optional arguments
including args LOL default to nil which in this case is fine
as that is an empty list, i.e., args holds no arguments,
however "beg" and "end" has to be set explicitly, and not just
for interactive use.

Close to this example ...

(defun use-region ()
  (when (use-region-p)
    (list (region-beginning) (region-end)) ))

(defun test-dwim-2 (re &optional beg end)
  (interactive `(,(read-regexp "re: ")
                 ,@(use-region) ))
  (or beg (setq beg (point-min)))
  (or end (setq end (point-max)))
  (message "%d %d %s" beg end re) )

[ That interactive spec couldn't have been fully integrated
  with the "R" code letter (that doesn't exist) anyway since
  there seems to be no code letter for regexps either? ]

Or maybe even better:

  (defun command (cmd &optional beg end &rest args) ... )

That will mean a lot of ugly

  (command "havoc" nil nil "--nuclear")

in Lisp tho, yet another option would be

  (defun command (cmd &optional args beg end) ... )

which is the same as the first suggestion only here args can
be either non-nil that isn't a list, say "-n", in what case
it's the one and only argument, otherwise it'd be a list of
arguments as earlier.

But then one cannot send nil as a single argument, since that
means no arguments? Just do ("nil") then ...

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




reply via email to

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