[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
M-x call with optional arg; call from Elisp
From: |
Emanuel Berg |
Subject: |
M-x call with optional arg; call from Elisp |
Date: |
Mon, 27 May 2013 18:03:55 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) |
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
- M-x call with optional arg; call from Elisp,
Emanuel Berg <=