Open function in editor on specific line.

General APL language issues
nikll
Posts: 13
Joined: Sat Oct 17, 2015 1:35 pm

Open function in editor on specific line.

Post by nikll »

Is there any way to open programmatically a function on a cirtain line of code?
I tried following but it doesn't work. :(

Code: Select all

)ED foo[3]
DanB|Dyalog

Re: Open function in editor on specific line.

Post by DanB|Dyalog »

Not sure what you mean by "open programmatically" but if you meant to open the editor on a specific line number you can double click or shift-Enter on the name followed by [line#] to do that.

As an aside, note that if you are searching the workspace using ]locate to find where code is found you can add a modifier to ask ]locate to include the name of the programs found next to the line number where a match is found.

For example if you are looking for 'abc' in the workspace you would do

      ]locate abc

∇ #.myprog (1 found)
[55] abc

If you now double click on #.myprog you will open the editor on line 1 and you will need to scroll to the line where the match was found. Not bad here but if you have 100s of lines you may lose a few seconds to find it. OTOH if you do (notice the -name)
      ]locate abc  -name

∇ #.myprog (1 found)
#.myprog[55] abc

]locate will pad the program name to the line number and you can double click on #.myprog[55] and the editor will "jump" immediately to line 55.
nikll
Posts: 13
Joined: Sat Oct 17, 2015 1:35 pm

Re: Open function in editor on specific line.

Post by nikll »

Sorry, my explanation wasn't clear enough.
I meant "programmatically" - from a function, instead of manual ways: shift+Enter or double click. Let's say we have a function and I need to open it from another function on certain line

Code: Select all

      ∇foo
[0]   foo
[1]   1
[2]   2
[3]   3
[4]  ∇

      ∇OpenFooOnLine
[0]   OpenFooOnLine lineNumber;cmd
[1]   :If 0=lineNumber
[2]      cmd←'⎕ED ''foo'''
[3]   :Else
[4]      cmd←'⎕ED ''foo[',(⍕lineNumber),']'''
[5]   :EndIf
[6]   ⎕←cmd
[7]
[8]   ⍎cmd
[9]  ∇

      OpenFooOnLine 0      - works fine
⎕ED 'foo'
      OpenFooOnLine 1      - doesn't :(
⎕ED 'foo[1]'
nikll
Posts: 13
Joined: Sat Oct 17, 2015 1:35 pm

Re: Open function in editor on specific line.

Post by nikll »

I see not too much ideas (might my that is idea is unclear :) )
Ok, then I would ask another question.
We can to simulate a keystroke for "a" with coommand like this:

Code: Select all

⎕NQ '⎕SE' 'KeyPress' 'a'


How can I to do the same for Alt+"a" , if it possible?
Thanks
:)
gil
Posts: 72
Joined: Mon Feb 15, 2010 12:42 am

Re: Open function in editor on specific line.

Post by gil »

The question is perfectly clear and I would also like to see if it is possible, but I don't know the answer.

Is there no way to open a function in the editor and go to a specific line programmatically, i.e. accomplish the same thing as when double-clicking on a name followed by line number in square brackets:

      foo[25]


It would be a useful feature to have.
Vince|Dyalog
Posts: 439
Joined: Wed Oct 01, 2008 9:39 am

Re: Open function in editor on specific line.

Post by Vince|Dyalog »

Hi Nikll,

I don't think that there is any way to do what you want.

It's a good idea though, and I've logged this as RFE 13581.

Regards,

Vince
nikll
Posts: 13
Joined: Sat Oct 17, 2015 1:35 pm

Re: Open function in editor on specific line.

Post by nikll »

Great! Then I would prefer to have a possibility of specifying not only a row but also a cursor position in the line and even selecting of some part of the line.
Thanks Vince :)
gil
Posts: 72
Joined: Mon Feb 15, 2010 12:42 am

Re: Open function in editor on specific line.

Post by gil »

nikll wrote:How can I to do the same for Alt+"a" , if it possible?
Thanks
:)

Have you tried:
      ⎕NQ'⎕SE' 'KeyPress' '' 0 65 4
nikll
Posts: 13
Joined: Sat Oct 17, 2015 1:35 pm

Re: Open function in editor on specific line.

Post by nikll »

I have got this hieroglyph (Unicode Edition)

Code: Select all

      ⎕NQ'⎕SE' 'KeyPress' '' 0 65 4
      翿

But I expect to invoke the Action menu like if I press "Alt+a" on keyboard.


By the way there is an error message for a unrecognizable key code but for the empty string I get some strange sign. Looks inconsistent.

Code: Select all

      ⎕NQ'⎕SE' 'KeyPress' 'UD' 
KEY CODE UNRECOGNISED
      ⎕NQ'⎕SE' 'KeyPress' ''
      翿


/N
User avatar
AndyS|Dyalog
Posts: 263
Joined: Tue May 12, 2009 6:06 pm

Re: Open function in editor on specific line.

Post by AndyS|Dyalog »

There is one way of achieving your goal of opening the editor on a specific line and column in the editor. I'm not entirely sure I'd recommend using it, and it won't work with RIDE. But you could try something like the following:

Suppose I have a function foo, and I want to open the editor with the cursor immediately after the 9 on foo[2]:

      ⎕fx'foo' '1 1 1 1' '2 2 9 2' '3 3 3 3' ⍝ Create a function to work on
0 0 ⍴(1 2 5/'ED' 'DC' 'RC' )⎕pfkey 33 ⍝ 2 Down Cursors, 5 Right Cursors
{⎕nq '⎕se' 'KeyPress' ⍵}¨'foo',⊂'F33'

Good innit ? :-)

You might have to increase the PFKey buffer size if you're going to cope with huge functions etc. (Options->Configure->Log or set PFKEY_SIZE).

I'll log the generation of the Unicode character (Unicode code point 32767) as a bug. When I get odd things like this in the session I generally move to the beginning of the line and type ⎕UCS', hit RL (end of line) and then close the quotes and hit ER (Enter). That displays the Unicode code point values. Very useful if you manage to introduce characters that look like a space, but aren't !

What are you trying to achieve as the end result of issuing Alt-a ? If for example it it to open the editor (<Alt-a><Shift-Enter>), then you might be better off enqueuing the 'ED' command. When it comes to commands, Dyalog treats them differently from normal characters; it's worth looking at the section on Keyboard shortcuts in the Dyalog APL User Guide, and also at the Dyalog for UNIX User Guide (which you can find at http://docs.dyalog.com)
Post Reply