all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Emanuel Berg <embe8573@student.uu.se>
To: help-gnu-emacs@gnu.org
Subject: M-x call with optional arg; call from Elisp
Date: Mon, 27 May 2013 18:03:55 +0200	[thread overview]
Message-ID: <87hahobeac.fsf@VLAN-3434.student.uu.se> (raw)

Take a look at the below code, and you'll understand immediately what
I ask.

1. How can I call a function with M-x and provide an optional string
arg?

2. Why do I get 0 when I call from Elisp? (Is it the return code - $?
- and not the output?) I tried with eval and funcall as well:
same. How do I call from Elisp?

;;; word count
(defun words (&optional opts)
  "Count buffer words with wc OPTS, or wc -w if not OPTS is given."
  (interactive)
  (defvar count-cmd)
  (setq count-cmd (format "wc %s" (if (stringp opts) opts "-w")))
  (if mark-active
    (shell-command-on-region (region-beginning) (region-end) count-cmd)
    (shell-command-on-region (point-min) (point-max) count-cmd) ))
(words "-l") ; doesn't work (0) - can I call this with M-x and an arg?
(words)      ; same, but `M-x words' works

(defun count-buffer-wc-option (option)
  (interactive "s wc options: ")
  "Count buffer according to wc OPTION."
  (shell-command-on-region (point-min) (point-max)
                           (format "wc %s" option)) )
(count-buffer-wc-option "-l") ; same, but
                              ; `M-x count-... RET -l' works

-- 
Emanuel Berg - programmer (hire me! CV below)
computer projects: http://user.it.uu.se/~embe8573
internet activity: http://home.student.uu.se/embe8573


             reply	other threads:[~2013-05-27 16:03 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-27 16:03 Emanuel Berg [this message]
2013-05-27 16:13 ` M-x call with optional arg; call from Elisp Emanuel Berg
2013-05-28 19:24   ` Emanuel Berg
2013-05-27 18:59 ` Stefan Monnier
     [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

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

  git send-email \
    --in-reply-to=87hahobeac.fsf@VLAN-3434.student.uu.se \
    --to=embe8573@student.uu.se \
    --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.