From: Stefan Monnier <monnier@iro.umontreal.ca>
To: help-gnu-emacs@gnu.org
Subject: Re: M-x call with optional arg; call from Elisp
Date: Mon, 27 May 2013 14:59:57 -0400 [thread overview]
Message-ID: <jwvbo7wdzfh.fsf-monnier+gmane.emacs.help@gnu.org> (raw)
In-Reply-To: 87hahobeac.fsf@VLAN-3434.student.uu.se
> 1. How can I call a function with M-x and provide an optional string
> arg?
You have to put in the `interactive' spec a description of what value
to pass.
> 2. Why do I get 0 when I call from Elisp?
Because that's the value of the last expression.
> (Is it the return code - $? - and not the output?)
Yes.
> (defvar count-cmd)
> (setq count-cmd (format "wc %s" (if (stringp opts) opts "-w")))
`defvar does not define the variable, nor declares it as local.
Quite the opposite, it basically declares it as global (or rather as
dynamically-scoped, which ends up being fairly close).
You want to use
(let ((count-cmd (format "wc %s" (if (stringp opts) opts "-w"))))
instead.
> (if mark-active
> (shell-command-on-region (region-beginning) (region-end) count-cmd)
> (shell-command-on-region (point-min) (point-max) count-cmd) ))
Don't use shell-command-on-region from Elisp. Use call-process-region instead.
Stefan
next prev parent reply other threads:[~2013-05-27 18:59 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-27 16:03 M-x call with optional arg; call from Elisp Emanuel Berg
2013-05-27 16:13 ` Emanuel Berg
2013-05-28 19:24 ` Emanuel Berg
2013-05-27 18:59 ` Stefan Monnier [this message]
[not found] ` <mailman.476.1369681518.22516.help-gnu-emacs@gnu.org>
2013-05-28 19:52 ` Emanuel Berg
2013-05-30 5:44 ` Kevin Rodgers
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvbo7wdzfh.fsf-monnier+gmane.emacs.help@gnu.org \
--to=monnier@iro.umontreal.ca \
--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.
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).