[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: |
Fri, 6 Nov 2015 07:49:11 -0900 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
* Tim Johnson <tim@akwebsoft.com> [151106 07:30]:
> * Joost Kremers <joost.m.kremers@gmail.com> [151106 00:57]:
> > Tim Johnson wrote:
> > > Here is an example of what could be a working function 'interning'
> > > a string :
> > > (defun tj-toggle-funcs ()
> > > "Toggle functions"
> > > (interactive)
> > > (let ((menu
> > > '("" ("" ("Transient Mark Mode" . "transient-mark-mode"))
> > > ("Truncate Lines" . "toggle-truncate-lines")
> > > ("Show Tabs" . "toggle-tabs-font-lock"))))
> > > (choice ))
> > > (setq choice (tmm-prompt menu))
> > > (if choice
> > > (call-interactively (intern choice)))))
> > >
> > > My preference *would* be that a command object be read from the
> > > 'menu structure, but wasn't able to make it work.
> > > So my next step is to figure out how to place a command object as a
> > > value instead of a string... and then evaluate it properly.
> Thanks for the reply :
>
> > Check out the Elisp manual on pop-up menus, which use the function
> > x-popup-menu, which takes the same kind of menu structure as tmm-prompt.
>
> 1)I'm a bit "mouse averse" - I.E. I prefer tmm-prompt for
> numerous reasons.
>
> 2)The Elisp manual (as far as I have found it) does not give any
> working examples which have edified me.
>
> What has eluded me so far is how to use commands as values in the
> alist - this is why I introduced the topic of evaluating a string
> as a command.
>
> > C-h i Elisp RET Pop-up menus RET
> >
> > An alternative to what you're trying to do would be to use the hydra
> > package:
> >
> > https://github.com/abo-abo/hydra
> >
> > Here is my toggle hydra, for example:
> >
> > ```
> > (defhydra jk-hydra-toggle (:color blue)
> > "Change"
> > ("d" toggle-debug-on-error "Debug")
> > ("w" writeroom-mode "Writeroom")
> > ("i" ispell-change-dictionary "Change Ispell Dictionary")
> > ("f" toggle-fill-unfill "Fill")
> > ("F" follow-mode "Follow mode")
> > ("t" orgtbl-mode "OrgTbl mode")
> > ("y" typo-mode "Typo mode")
> > ("q" nil "Cancel"))
> > (bind-key "s-r" #'jk-hydra-toggle/body)
> > ```
> The formatting of this structure above makes total sense, but can
> it be used for tmm-prompt.
>
> > Yeah, ok, so `ispell-change-dictionary` is not a toggle... But you get the
> > idea. ;-)
Oh! I've read further on hydra. Doesn't even need tmm-prompt. It
looks pretty awesome. I will try it.
BTW: After a night's sleep and some coffee, I think I have a
working tmm-prompt solution with command objects:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(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-tabs-font-lock))
("4)Cursor Color" . (tj-cursor-color)))))
(choice))
(setq choice (tmm-prompt menu))
(if choice
(eval choice))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
cheers
--
Tim
http://www.akwebsoft.com, http://www.tj49.com
- Re: Execute a string as a command, (continued)
Re: Execute a string as a command, Random832, 2015/11/05
Re: Execute a string as a command, Barry Margolin, 2015/11/05