From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Emanuel Berg Newsgroups: gmane.emacs.help Subject: Re: M-x call with optional arg; call from Elisp Date: Tue, 28 May 2013 21:52:04 +0200 Organization: Aioe.org NNTP Server Message-ID: <87fvx6ubkr.fsf@VLAN-3434.student.uu.se> References: <87hahobeac.fsf@VLAN-3434.student.uu.se> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1369771332 31378 80.91.229.3 (28 May 2013 20:02:12 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 28 May 2013 20:02:12 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue May 28 22:02:13 2013 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UhQ60-0003cb-W1 for geh-help-gnu-emacs@m.gmane.org; Tue, 28 May 2013 22:02:13 +0200 Original-Received: from localhost ([::1]:46918 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UhQ60-0007fx-LD for geh-help-gnu-emacs@m.gmane.org; Tue, 28 May 2013 16:02:12 -0400 X-Received: by 10.180.206.107 with SMTP id ln11mr5312962wic.7.1369770761868; Tue, 28 May 2013 12:52:41 -0700 (PDT) X-FeedAbuse: http://nntpfeed.proxad.net/abuse.pl feeded by 88.191.116.97 Original-Path: usenet.stanford.edu!h2no14959194wiw.1!news-out.google.com!hv6ni21309wib.1!nntp.google.com!proxad.net!feeder1-2.proxad.net!nntpfeed.proxad.net!dedibox.gegeweb.org!gegeweb.eu!gegeweb.org!aioe.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 38 Original-NNTP-Posting-Host: SWN/nubmpQxYKwY7hPy4YA.user.speranza.aioe.org Original-X-Complaints-To: abuse@aioe.org User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) X-Notice: Filtered by postfilter v. 0.8.2 Cancel-Lock: sha1:nsIy7VHFKRQGFokVmYgPt7xTBCA= Original-Xref: usenet.stanford.edu gnu.emacs.help:198845 X-Mailman-Approved-At: Tue, 28 May 2013 16:02:00 -0400 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:91111 Archived-At: Stefan Monnier writes: >> 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. Yes, that did it: this works from M-x: (defun words (&optional opts) "Count buffer words with wc OPTS, or wc -w if not OPTS is given." (interactive "s (RET for -w) options to wc: ") (let*((options (if (not (string= "" opts)) opts "-w")) (count-cmd (format "wc %s" options)) ) (if mark-active (shell-command-on-region (region-beginning) (region-end) count-cmd) (shell-command-on-region (point-min) (point-max) count-cmd) ))) > 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. Aha, when I started with Elisp, I always used let, but then I found defvar and started using it, because the syntax is much easier to use. I thought defvar gave a local variable if in a defun. > Don't use shell-command-on-region from Elisp. Use > call-process-region instead. The above function seems to work. shell-command-on-region and call-process-region are not syntactically interchangeable, but I'll do it if you care to tell me the advantage. -- Emanuel Berg - programmer (hire me! CV below) computer projects: http://user.it.uu.se/~embe8573 internet activity: http://home.student.uu.se/embe8573