command without paranthesis?

For the Compleat Fan
Locked
HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

command without paranthesis?

Post 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.
Hans-Peter

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post 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.
Hans-Peter

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post 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

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post 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!
Hans-Peter

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post 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.
Hans-Peter

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post 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.
Hans-Peter

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post 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.
Hans-Peter

Locked