Page 1 of 1

command without paranthesis?

Posted: Thu Oct 23, 2003 5:01 pm
by HPW
In autolisp you can define a lisp-command without paranthesis by make an defun with an "C:" before the lisp-function name.

Code: Select all

(defun C:Testfunc () (setq banana 1))
At the console-prompt you can type "Testfunc" and it's starts.

Would it be possible to add such or similar option to newlisp.
When we make then an application with a console window
a direct command-typing would be possible without paranthesis.
The command would then ask interactivly about input data.

Posted: Thu Oct 23, 2003 8:22 pm
by HPW
After some thoughts about the problem, it should be possible just by modifying the TCL-code of the console. Just compare the input against a command-list and when the input-string is in the command-list, make a proper lisp-call out of it and send it to newlisp. So the define could stay as it is and we have only to set up the command-list.

Posted: Fri Oct 24, 2003 12:39 am
by Lutz
The function to modify in newlisp-tk.tcl would be 'ProcessConsoleInput()' before the second to last line which says: 'puts $nlio $lastCommand' , you could check the contents of last command and than replace it with a newLISP command with parenthesis etc.:

----------------- before -------------------
update

puts $nlio $lastCommand
flush $nlio
----------------- after ---------------------
update

if { $lastCommand == "dir" } { set lastCommand "(directory)" }
if { $lastCommand == "syms" } { set lastCommand "(symbols)" }

puts $nlio $lastCommand
flush $nlio
----------------------------------------------

I tried it out and it works fine for me.

Lutz

Posted: Fri Oct 24, 2003 5:16 am
by HPW
Thanks again Lutz,

Exactly what I wanted to do, but I was not so fast as you.
(You know your code best)

That is what I like very much on newlisp:

Powerfull flexibility!!
First class response-quality and time!

Posted: Sat Oct 25, 2003 7:16 am
by HPW
For a more general solution I do this:

#In the global var-section

set Ide(DirectConsoleCmd) {dir syms}
set Ide(DirectLispCmd) {directory symbols}

#in proc ProcessConsoleInput

Code: Select all

#	if { $lastCommand == "dir" } { set lastCommand "(directory)" }
#	if { $lastCommand == "syms" } { set lastCommand "(symbols)" }


	if { [llength $Ide(DirectConsoleCmd)] > 0 } {
		set cmdpos [lsearch $Ide(DirectConsoleCmd) $lastCommand]
		if { $cmdpos > -1 } {
		 set lastCommand "("
		 append lastCommand [lindex $Ide(DirectLispCmd) $cmdpos] ")"
		}
	}
Now I want to set it dynamicly from lisp. See the different thread on problems with accessing TK-variables. Then no re-wrap is needed.

Posted: Sat Oct 25, 2003 7:56 am
by HPW
Another little improvment:

Code: Select all

	if { [llength $Ide(DirectConsoleCmd)] > 0 } {
		set cmdpos [lsearch $Ide(DirectConsoleCmd) [string tolower $lastCommand]]
		if { $cmdpos > -1 } {
		 set lastCommand "("
		 append lastCommand [lindex $Ide(DirectLispCmd) $cmdpos] ")"
		}
	}
With this the commands are case-insensitive.

Posted: Sun Nov 02, 2003 4:40 pm
by HPW

Code: Select all

if { [llength $Ide(DirectConsoleCmd)] > 0 } { 
      set cmdpos [lsearch -exact $Ide(DirectConsoleCmd) [string tolower $lastCommand]] 
      if { $cmdpos > -1 } { 
       set lastCommand "(" 
       append lastCommand [lindex $Ide(DirectLispCmd) $cmdpos] ")" 
      } 
   } 
Adding the '-exact' option will prevent to activate the first command through input of '*'. Or something like 'd*'. Only the exact command will trigger.