all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Emanuel Berg <incal@dataswamp.org>
To: help-gnu-emacs@gnu.org
Subject: Re: shell-command-on-region but with command line arguments
Date: Wed, 09 Nov 2022 11:37:51 +0100	[thread overview]
Message-ID: <87v8noza4g.fsf@dataswamp.org> (raw)
In-Reply-To: 636b5b28.050a0220.b181b.e9bc@mx.google.com

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	other threads:[~2022-11-09 10:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-07 15:51 shell-command-on-region but with command line arguments Luca Ferrari
2022-11-07 17:22 ` Emanuel Berg
2022-11-07 19:21 ` Bruno Barbier
2022-11-08  0:13   ` Emanuel Berg
2022-11-09  7:21   ` Luca Ferrari
2022-11-09  7:53     ` Bruno Barbier
2022-11-09 10:37       ` Emanuel Berg [this message]
2022-11-09 11:40       ` Luca Ferrari

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87v8noza4g.fsf@dataswamp.org \
    --to=incal@dataswamp.org \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.