Execute highlighted code

General discussions on potential enhancements to the APL+Win system.

Execute highlighted code

Postby Ajay Askoolum » September 19th, 2014, 3:05 pm

I've been working primarily with SQL Server Management Studio in recent weeks. One of the features of the query window is that you can highlight any complete code snippet, press F5 and SSMS returns the results in the results window.

For example, with

select * from myTable where exists (select key from myTable1);

I could highlight

select key from myTable1

Press F5 and get the result.

In the last couple of days, I've been highlighting code in the APL+Win interactive session and pressing F5 to no avail.

Can you implement a similar feature? It would be a big bonus when debugging code. And if it execute in situ (i.e. without echoing the snippet to the bottom of the session as in SSMS), it will avoid clutter in the session.
Ajay Askoolum
 
Posts: 632
Joined: February 22nd, 2007, 2:16 am
Location: United Kingdom

Re: Execute highlighted code

Postby Tech Support » September 22nd, 2014, 2:43 pm

Thank you for your suggestion.
Tech Support
 
Posts: 1125
Joined: February 10th, 2007, 7:33 am
Location: Rockville, MD

Re: Execute highlighted code

Postby Chizever » September 22nd, 2014, 3:43 pm

Create a tool with a keyboard shortcut of F5.

The entire command is a single del character.

Now whenever you highlight anything, press F5 and it will execute it in your session.

You may want to write a user command, SafeExecute, so that it can trap errors and/or pop up a screen with the result
Code: Select all
    ∇ CMDSAFEEXECUTE ∆∆a;∆∆result;⎕wself
[1]    :try
[2]       ⍎'∆∆result←',∆∆a
[3]       ∆∆result←⍕∆∆result
[4]       ∆∆result←∊∆∆result,⎕tcnl
[5]    :catchif 'VALUE ERROR'≡⎕EM
[6]       ∆∆result←'no result from executed expression'
[7]    :catchall
[8]       ∆∆result←'error executing expression:',⎕tcnl,⎕tcnl,⎕dm
[9]    :endtry
[10]
[11]   ⎕wself←'∆∆SafeExecute' ⎕wi 'Create' 'Form' 'Close'
[12]     ⎕wi 'caption' 'Safe Execute'
[13]     ⎕wi 'border' 2 16 64
[14]     ⎕wi 'icon' '>ICO 116 aplw.exe'
[15]     ⎕wi 'font' 'APLHELP'
[16]     ⎕wi 'onResize' '⎕wi ":ed.where" (0 0,2↑⎕warg)'
[17]
[18]   ⎕wself←⎕wi ':ed.New' 'Edit'
[19]     ⎕wi 'style' 4 8 16 64 2048 16384
[20]     ⎕wi 'text' (∆∆a,⎕tcnl,⎕tcnl,⎕tcnl,∆∆result)
[21]
[22]   0 0⍴⎕wi ':Show'
    ∇


Make the command in tools to be:
Code: Select all
⎕ucmd 'SafeExecute ∇'


Now, you'll execute the hilighted code and display the results in a pop up window.
Chizever
 
Posts: 63
Joined: March 1st, 2007, 12:12 pm

Re: Execute highlighted code

Postby Ajay Askoolum » September 22nd, 2014, 4:06 pm

Thank you very much. That (just defining the tool) worked for me. And, it will be very handy albeit the highlighting is lost upon execution.

May be a future version will support this out of the box & keep the highlighting too: highlight code, press key (F5 or other) and the results display as a tooltip - any interaction loses the tooltip.
Ajay Askoolum
 
Posts: 632
Joined: February 22nd, 2007, 2:16 am
Location: United Kingdom

Re: Execute highlighted code

Postby brent hildebrand » September 25th, 2014, 9:23 pm

May I suggest a slight tweak - so that the []IO of the SafeExecute reflect the []IO of the current session?
Code: Select all
    ∇ CMDSAFEEXECUTE ∆∆a;∆∆result;⎕wself;⎕io
[1]   ⎕io←0 ⎕vget '⎕io'
[2]    :try
[3]       ⍎'∆∆result←',∆∆a
[4]       ∆∆result←⍕∆∆result
[5]       ∆∆result←∊∆∆result,⎕tcnl
[6]    :catchif 'VALUE ERROR'≡⎕EM
[7]       ∆∆result←'no result from executed expression'
[8]    :catchall
[9]       ∆∆result←'error executing expression:',⎕tcnl,⎕tcnl,⎕dm
[10]   :endtry
[11] 
[12]   ⎕wself←'∆∆SafeExecute' ⎕wi 'Create' 'Form' 'Close'
[13]     ⎕wi 'caption' 'Safe Execute'
[14]     ⎕wi 'border' 2 16 64
[15]     ⎕wi 'style' 2 16
[16]     ⎕wi 'icon' ('>ICO 116 ',∊↑/⎕wcall 'GetModuleFileName' (↑⎕wcall 'W_Init') (512⍴' ') 512)
[17]     ⎕wi 'font' 'APLHELP'
[18]     ⎕wi 'onResize' '⎕wi ":ed.where" (0 0,2↑⎕warg)'
[19] 
[20]   ⎕wself←⎕wi ':ed.New' 'Edit'
[21]     ⎕wi 'style' 4 8 16 64 2048 16384
[22]     ⎕wi 'text' (∆∆a,⎕tcnl,⎕tcnl,⎕tcnl,∆∆result)
[23] 
[24]   0 0⍴⎕wi ':Show'
    ∇
brent hildebrand
 
Posts: 476
Joined: February 12th, 2007, 5:53 pm
Location: Loma Linda, CA


Return to APL+Win Wish-List

Who is online

Users browsing this forum: No registered users and 1 guest

cron