[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: |
Sat, 7 Nov 2015 10:36:18 -0900 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
* Barry Margolin <barmar@alum.mit.edu> [151107 09:44]:
> In article <mailman.1860.1446859974.7904.help-gnu-emacs@gnu.org>,
> Tim Johnson <tim@akwebsoft.com> wrote:
>
> > * Emanuel Berg <embe8573@student.uu.se> [151106 12:47]:
> > > Tim Johnson <tim@akwebsoft.com> writes:
> > >
> > > > I can't get to that phase for another day or two..
> > > > thanks, Emanuel.
> > >
> > > No, there are much better things for you to do than to
> > > digest that code. For example, ask yourself why you
> > > want to execute strings as commands, and if there is
> > > a better way still.
> > >
> > > That code of mine is more like a demo to show of
> > > skills and attract ohs and ahs. It is not really
> > > helpful (tho sometimes I use it so it *does* work).
> >
> > By this time, you've probably read from the continuation of this
> > thread that I had problems with setting up the menu structure so
> > that command objects could be read from it. Thus I used a string
> > representation to see if that could be evaluated.
>
> The usual way to implement things like this is with an association list.
> The key is the string that's displayed in the menu, and the value is a
> symbol that names a function or a lambda expression.
Absolutely. This is what I was finally able to make work:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun tj-toggle-funcs ()
"Toggle functions"
(interactive)
(let ((menu
'("" ("" ("1)Transient Mark Mode" . (transient-mark-mode))
("2)Truncate Lines" . (toggle-truncate-lines))
("3)Show Tabs" . (toggle-show-tabs-show-ws)))
(choice))
(setq choice (tmm-prompt menu))
(if choice
(eval choice))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Any creative or instructive comments are more than welcome.
--
Tim
http://www.akwebsoft.com, http://www.tj49.com
Re: Execute a string as a command, Random832, 2015/11/05