[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Execute a string as a command
From: |
Tim Johnson |
Subject: |
Re: Execute a string as a command |
Date: |
Thu, 5 Nov 2015 19:06:13 -0900 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
* Emanuel Berg <embe8573@student.uu.se> [151105 18:51]:
> Tim Johnson <tim@akwebsoft.com> 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
Re: Execute a string as a command, Random832, 2015/11/05