I recently finished an edit for J8. Ran into an interesting problem when
positioning the edit window on the name. It seems that (wd 'sm get edit')
counts characters, not bytes. Things get a little messy when the script to
edit contains U8. The script which gave me trouble was qt.ijs with the line
drawing symbols. I just modified my edit to allow for that, but it seems to
work. There has to be a better way than I did here to identify U8
characters, but it works.
_________________________________________________________

NB.*whereis v Where is a name defined?
whereis=:3 : 0
if. '_'={:y
  do.  'locales z'=.<"0}:&.>({:,<@;@}:)<;.2 y
  else. locales=.,conl ''[z=.<,y
end.
foundlocales=.''
for_l. locales do.
  n=.nl__l ''
  if.z e. n do. foundlocales=.foundlocales,l end.
end.
foundlocales
NB. '>(4!:4 <y){4!:3'''''
)

NB.*edit v Edit a name in a script
NB. Argument:
NB.   y - The name to edit in some loaded script
NB. Return:
NB.   None. The script file defining the name is opened for edit
NB.   with the name near the top of the edit window (hopefully).
NB.   If the name is defined from more than one script file then
NB.   the lines are written to the execution window for the user
NB.   to pick the one to edit. If the name was not defined by a
NB.   script then nothing happens.
NB. It would have been nice to open a form with the selection
NB. list but no message box would work and creating one with all
NB. events would be involved and not worth the trouble.
edit=:3 : 0
if. '_'={:,y=.;;:y
  do.   y=.}:;}:<;.2 y[l=.<y
  else. l=.(<y),&.>'_'([,],[)&.>whereis y
end.
f=.(3 : '>(4!:4 <y){4!:3''''') &.>l
if. 0=#f   do. echo '"',y,'" not found.' return. end.
if. 1<#~.f do.
  echo '"',y,'" is found in several places.'
  echo '   edit ''',"1(>l),.'''  NB. ',"1>f
  echo 'Pick from the above the one to edit.'
  return.
end.
open f
NB. Position at name in window.
get=.]{~[:<1,~([:{."1])i.[:<[
m=.(128#1),(64#0),(64#1)
marku8=.m{~a.i.]
t=.<;.2 tt=.LF,~>'text' get wd 'sm get edit'
if. 0=#i=.I.(<y;'=:')(+./@E.;:)&>t do.
  i=.I.(<l,<'=:')(+./@E.;:)&>t
end.
i=.{.|.i NB. Get last definition.
'l sel'=.+/\(+/@}:,{:)i{.(+/@marku8)&>t
NB. 'l sel'=.+/\(+/@}:,{:)i{.#&>t
wd 'sm set edit select ',":2##>tt
wd 'sm set edit select ',":2#l
wd 'sm set edit select ',":(0,#y)+sel+{.I.y E.>t{~<:i
)
___________________________________________________________

On Thu, Sep 10, 2015 at 12:37 PM, Raul Miller <[email protected]> wrote:

> Speaking of things we miss from j602, I really liked the (edit) verb,
> for inspecting definitions in context.
>
> Here's the best I can currently approximate it in j804:
>
> edit=:3 :0
>    open (4!:3''){~4!:4<y
> )
>
> Example use:
>
>    edit 'tsrep'
>
> This example gives me system/main/stdlib.ijs in an editor window. What
> it doesn't do is find anything that looks like the definition of tsrep
> in that file.
>
> And there's some justice for that - sometimes what looks like the
> definition isn't really the definition. But I'd like to try. Maybe put
> a user interface in front of it, if it seems ambiguous?
>
> But I don't know how to move to a position within the opened file.
>
> Looking at the definition of open:
>
> 3 : 'wd ''openj *'' , > {. getscripts_j_ y'
>
> So it's a wd command. But google is useless, and I don't specifically
> know where to go to find any relevant reference.
>
> Looking through:
>
> http://www.jsoftware.com/jwiki/Guides/Window%20Driver/ChildClasses
> http://www.jsoftware.com/jwiki/Guides/Window%20Driver/Command%20Reference
> http://www.jsoftware.com/jwiki/Guides/Window%20Driver/Parent
> http://www.jsoftware.com/jwiki/Guides/Window%20Driver/Window%20Controls
>
> http://www.jsoftware.com/jwiki/Guides/Window%20Driver/Window%20Driver%20Overview
>
> finds me nothing on 'openj'.
>
> I might be able to find something under http://jsoftware.com/websvn/
> but that's a fairly hostile environment for searching. Still, spending
> a few minutes there suggests that the c++ sources are no longer
> visible to me.
>
> At a guess, though, the code is currently not designed to support J
> driving the behavior of the edit windows.
>
> --
> Raul
>
>
> On Thu, Sep 10, 2015 at 2:16 PM, Dan Bron <[email protected]> wrote:
> > Ian wrote:
> > "Normal use" for me invariably means referring to sample code.
> >> Especially when using addons, i.e. all the time.
> >
> >
> > Funny what constitutes “normal use” for different people!
> >
> > I may have opened the Labs in my first few weeks of using J (was that
> 2001? wow.), but I haven’t since.
> >
> > I don’t find the interactive/pagination workflow of Labs conducive for
> reference material. It’s tutorial material. I believe the intended use case
> for Labs is you go through any given Lab once or twice, but once you
> internalize the lesson, you put it on the shelf.
> >
> > For reference material, i.e. “normal use” for me, I use the Dictionary,
> Wiki, and Forum search tool, supplemented by  open’scriptname’  where
> needed (though sadly we’re missing  edit’functioname’ from the good old
> days).
> >
> > -Dan
> >
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to