newLISP Fan Club

Forum => Anything else we might add? => Topic started by: HPW on October 23, 2003, 10:01:38 AM

Title: command without paranthesis?
Post by: HPW on October 23, 2003, 10:01:38 AM
In autolisp you can define a lisp-command without paranthesis by make an defun with an "C:" before the lisp-function name.


(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.
Title:
Post by: HPW on October 23, 2003, 01:22:16 PM
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.
Title:
Post by: Lutz on October 23, 2003, 05:39:45 PM
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
Title:
Post by: HPW on October 23, 2003, 10:16:47 PM
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!
Title:
Post by: HPW on October 25, 2003, 12:16:36 AM
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



# 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.
Title:
Post by: HPW on October 25, 2003, 12:56:40 AM
Another little improvment:


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.
Title:
Post by: HPW on November 02, 2003, 08:40:51 AM
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.