Since this thread was originally about KWORDs, I got to thinking, there's got to be a better way.
A long time ago I got a hold of this little routine:
(Works best if Dynamic Input is turned on, then it's just a click and go thing)
;;;------------------------------------------------------------------------------------------------
;;;Tony Tanzillo - Gets the default return string for user input
(defun xgetstring
(msg StringInput
/ s
) (cond (StringInput
(strcat " <" StringInput
">: ")) (t ": ")))))
(cond ((eq s
"") StringInput
) (t s
)) )
And I made some modifications and came up with this:
;;;------------------------------------------------------------------------------------------------
;;;Written by Jamie Myers
;;;Loose extrapilation from Tony Tanzillo's XGETSTRING sub-routine
(defun xgetkword
(msg StringInput
/ s
) (cond (StringInput
(strcat " <" StringInput
">: ")) (t ": ")))))
(cond ((eq s
nil) StringInput
) (t s
)) )
It requires a default variable bet set and an initget call before the routine is run.
(setq rpt
(xgetkword
"\nContinue? [Yes/No]" rpt
))
And that has worked well for me for a long time. But, then again, I'm somewhat lazy. I wanted to create a better getkword function. So I came up with this:
;;;------------------------------------------------------------------------------------------------
;;;Written by Jamie Myers 01-09-2013
;;;Inspiration fromTony Tanzillo's XGETSTRING sub-routine,
;;;and help from irneb, CAB and Lee Mac
;;;Use: (setq <Variable> (GetKwordSub <message> <list of strings> <Variable>))
;;;Example: (setq ReturnString (GetKwordSub "Selection" (list "Yes" "No" "Maybe" "A bc" "A-bc" "X_Y-z") ReturnString))
(defun GetKwordSub
(Msg StringList Default
/ Msg Default Answer StringList ModList Cnt Setinitget Setmessage
) (if (not Default
) (setq Answer
(nth 0 StringList
)) (setq Answer Default
));set default if there is none (while (> Cnt
-1);iterate through the list to create 2 strings, one for the initget call and one for the message );while
(strcat "\n" Msg
"[" Setmessage
"]" (t ": ")))))
(cond ((eq Answer
nil) Answer
) (t Answer
)) );defun
It has issues. Using the example call, it gets confused between "A bc" and "A-bc". My thinking is that there more than likely will never be an issue.
I've added a few comments to get and idea of what's going on.
Anyways, what do the experts say. And of course, I want to see if it will even work for someone else.
Rabbit