From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tim Johnson Newsgroups: gmane.emacs.help Subject: Re: Execute a string as a command Date: Thu, 5 Nov 2015 19:06:13 -0900 Organization: AkWebsoft Message-ID: <20151106040613.GH3301@mail.akwebsoft.com> References: <20151106032357.GF3301@mail.akwebsoft.com> <87r3k3yea5.fsf@debian.uxu> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1446782797 12097 80.91.229.3 (6 Nov 2015 04:06:37 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 6 Nov 2015 04:06:37 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Nov 06 05:06:28 2015 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 1ZuYIF-0000xU-UD for geh-help-gnu-emacs@m.gmane.org; Fri, 06 Nov 2015 05:06:28 +0100 Original-Received: from localhost ([::1]:36527 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZuYIF-0001iu-AL for geh-help-gnu-emacs@m.gmane.org; Thu, 05 Nov 2015 23:06:27 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50063) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZuYI5-0001ih-2i for help-gnu-emacs@gnu.org; Thu, 05 Nov 2015 23:06:18 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZuYI1-00088r-QC for help-gnu-emacs@gnu.org; Thu, 05 Nov 2015 23:06:17 -0500 Original-Received: from tjohnson.mtaonline.net ([64.4.232.191]:33897) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZuYI1-00088G-Hu for help-gnu-emacs@gnu.org; Thu, 05 Nov 2015 23:06:13 -0500 Original-Received: by tj49.com (Postfix, from userid 1000) id F288A200122; Thu, 5 Nov 2015 19:06:13 -0900 (AKST) Mail-Followup-To: help-gnu-emacs@gnu.org Content-Disposition: inline In-Reply-To: <87r3k3yea5.fsf@debian.uxu> User-Agent: Mutt/1.5.21 (2010-09-15) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 64.4.232.191 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:107965 Archived-At: * Emanuel Berg [151105 18:51]: > Tim Johnson writes: > > > Example : A string has the value of : > > "toggle-truncate-lines" > > > > (setq string-wants-to-be-a-command > > "toggle-truncate-lines") > > > > How may I convert 'string-wants-to-be-a-command to > > a command: I.E. => (toggle-truncate-lines) to be > > used programmatically? > > (Why do you want this? Is there a better way to > do it?) Probably. Bearing in mind that I am just beginning to code in elisp. I'm going to save your code and digest it tomorrow. I have a larger need, and that is, a series of popup(or tmm-prompt)-driven commands. However, I believe it would be better for future searches, if I posted any question I might have on that issue in a morely suitably titled subject. I can't get to that phase for another day or two.. thanks, Emanuel. > Do you mean you want to parenthesize the string? - in > what case this is an editing issue, at least for > uncomplicated commands. > > Or do you want to store commands in strings and have > a function execute the commands that the string > contain? - if so, take a look at something I wrote > several years ago: > > ;; This file: http://user.it.uu.se/~embe8573/conf/emacs-init/shell-cli.el > > (defun string-to-cmd (str) > (interactive (list (read-string " $> "))) > (let*((cmd (read (car (split-string str " ")))) > (args (cdr (make-arg-list (string-to-list str)))) ) > (dolist (arg (nreverse args)) > (push 13 unread-command-events) ; 13 is RET > (dolist (n (reverse (string-to-list arg))) > (push n unread-command-events) )) > (call-interactively cmd) )) > > ;; test: (string-to-cmd "goto-char 0") > > (defun make-arg-list (chars) > (interactive) > (if chars > (let ((WS 39) ; whitespace ( ) > (SQM 32) ; quote (') > (c (car chars)) > (cs (cdr chars)) ) > (if (eq c WS) (make-word cs '() WS) > (if (eq c SQM) (make-arg-list cs) > (make-word chars '() SQM)) )) > '() )) > > (defun make-word (chars wd sep) > (interactive) > (if chars > (let ((c (car chars)) > (cs (cdr chars))) > (if (eq c sep) (cons wd (make-arg-list cs)) > (make-word cs (append wd (list c)) sep))) > (list wd) )) > > (defun zow (string symbol number) > "Test: shell-cli.el" > (interactive "sstring: \nSsymbol: \nnnumber: ") > (message "got: %S" (list string symbol number)) ) > > (provide 'shell-cli) > > -- > underground experts united > http://user.it.uu.se/~embe8573 > > -- Tim http://www.akwebsoft.com, http://www.tj49.com