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: Execute a string as a command Date: Fri, 06 Nov 2015 04:53:22 +0100 Message-ID: <87r3k3yea5.fsf@debian.uxu> References: <20151106032357.GF3301@mail.akwebsoft.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1446781452 26535 80.91.229.3 (6 Nov 2015 03:44:12 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 6 Nov 2015 03:44: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 Fri Nov 06 04:44:02 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 1ZuXwY-0003uA-27 for geh-help-gnu-emacs@m.gmane.org; Fri, 06 Nov 2015 04:44:02 +0100 Original-Received: from localhost ([::1]:36476 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZuXwX-0006Ja-Bm for geh-help-gnu-emacs@m.gmane.org; Thu, 05 Nov 2015 22:44:01 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47072) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZuXwN-0006JJ-1z for help-gnu-emacs@gnu.org; Thu, 05 Nov 2015 22:43:52 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZuXwJ-0001ym-1f for help-gnu-emacs@gnu.org; Thu, 05 Nov 2015 22:43:51 -0500 Original-Received: from plane.gmane.org ([80.91.229.3]:46469) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZuXwI-0001yh-Qz for help-gnu-emacs@gnu.org; Thu, 05 Nov 2015 22:43:46 -0500 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1ZuXwF-0003ai-Vq for help-gnu-emacs@gnu.org; Fri, 06 Nov 2015 04:43:44 +0100 Original-Received: from nl106-137-244.student.uu.se ([130.243.137.244]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 06 Nov 2015 04:43:43 +0100 Original-Received: from embe8573 by nl106-137-244.student.uu.se with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 06 Nov 2015 04:43:43 +0100 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: help-gnu-emacs@gnu.org Original-Lines: 69 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: nl106-137-244.student.uu.se Mail-Copies-To: never User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) Cancel-Lock: sha1:/O4NRMbnq8oEjWvjplx5cr7tklk= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 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:107962 Archived-At: 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?) 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