Erlang Development Environment

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Erlang Development Environment

Sean Hinde-2
Peter,

> An improvement
> would perhaps be the possibility to save the retrieved data
> (from an update) to
> file so that you don't have to collect the info from scratch
> every time you
> start the program. I suppose using e.g. dets, it would be
> quite a quick thing to
> implement?

I agree - it is on the TODO list in the source. The easiest way would be to
just save the list of functions as a term to a file.
 
> While we're on the subject of easy access to documentation...
> I've sometimes
> found it useful to be able to view Erlang man pages from the
> Erlang shell. I
> wrote a very simple program the other day that either prints
> a page to stdout or
> lets you perform some string searching within a page. If
> anyone's interested
> I'll post it.

That sounds useful. It would also be easy to add a button to get the man
page for the currently selected module in the code_finder (maybe even to
jump to the right function - Hm, that'd be neat).

- Sean



NOTICE AND DISCLAIMER:
This email (including attachments) is confidential.  If you have received
this email in error please notify the sender immediately and delete this
email from your system without copying or disseminating it or placing any
reliance upon its contents.  We cannot accept liability for any breaches of
confidence arising through use of email.  Any opinions expressed in this
email (including attachments) are those of the author and do not necessarily
reflect our opinions.  We will not accept responsibility for any commitments
made by our employees outside the scope of our business.  We do not warrant
the accuracy or completeness of such information.




Reply | Threaded
Open this post in threaded view
|

Erlang Development Environment

Peter Andersson
Sean Hinde wrote:
>
> That sounds useful. It would also be easy to add a button to get the man
> page for the currently selected module in the code_finder (maybe even to
> jump to the right function - Hm, that'd be neat).
>

Hi Sean,

I like that idea. Then I think the text should be extracted from the man page
source files to be searched through and displayed. My little hack "cheats" in
the sense that it presents text already processed by "erl -man". I was going to
change it to process marked up source instead, but I didn't get to it yet. I
also thought I'd change it to actually resemble unix man, but now I feel it'd be
more useful to make it into something that could be integrated with your
code_finder. It (my hack that is) needs a rewrite rather than an update for
this, though. I'll have a look at it next week if you like.

Anyway, I'll post the simple man page viewer. Here's the interface:

        utils:man(Module)
        utils:manfind(Module, ShRegExp)
       
manfind prompts you with "[N/s/p/q]>", where N means "print N lines following
the match", s means "search next" and p means "print previous line".

Example:

1> utils:manfind(ets, "*new*").
89:      new(Name, Type)
[N/s/p/q]>10
90:
91:           Creates a new table  and  returns  a  table  identifier
92:           which  can be used in subsequent operations. This table
93:           ID can also be sent to other processes so that a  table
94:           can be shared between processes. It is completely loca-
95:           tion transparent and can be sent to processes at  other
96:           nodes. Accordingly, the table identifier can be used as
97:           a location transparent store. Large amounts of data can
98:           be distributed to locations where it can be stored.

Regards

  /Peter
-------------- next part --------------
%%%----------------------------------------------------------------------
%%% File    : utils.erl
%%% Author  : Peter Andersson
%%% Purpose : Print or search through Erlang man page from shell.
%%% Created : 9 Mar 2001
%%%----------------------------------------------------------------------

-module(utils).
-author('eeipan').

-export([man/1, manfind/2]).

-define(MANCMD(Mod), os:cmd("erl -man " ++ Mod)).


man(Module) when atom(Module) ->
    man(atom_to_list(Module));

man(Module) when list(Module) ->
    Page = ?MANCMD(Module),
    Lines = format(Page, [[]]),
    print(Lines).

manfind(Module, String) when atom(Module) ->
    manfind(atom_to_list(Module), String);
   
manfind(Module, String) when list(Module) ->
    Page = ?MANCMD(Module),
    Lines = format(Page, [[]]),
    search(Lines, Lines, String, 1).

search([L | Ls], Lines, String, N) ->
    case regexp:match(L, regexp:sh_to_awk(String)) of
        {match,_,_} ->
            print_line(N, Lines),
            case new_search(N, N, Lines) of
                true -> search(Ls, Lines, String, N+1);
                false -> ok
            end;
        _ ->
            search(Ls, Lines, String, N+1)
    end;

search([], _, _, _) -> ok.

new_search(1, _, _) ->
    false;  

new_search(Cur, N, Lines) ->
    case io:get_line('[N/s/p/q]>') of
        "s\n" ->
            true;
        "q\n" ->
            false;
        "N\n" ->
            io:format("!!! Specify number of lines !!!~n", []),
            new_search(Cur, N, Lines);
        "p\n" ->
            print_line(Cur-1, Lines),
            new_search(Cur-1, N, Lines);
        Len ->
            Len1 = list_to_integer(string:strip(Len, right, $\n)),
            print_lines(Cur+1, Len1, Lines),
            new_search(Cur+Len1, N, Lines)
    end.

format([$_,$\b | Cs], Lines) ->
    format(Cs, Lines);

format([$\n | Cs], [L | Ls]) ->
    format(Cs, [[] | [L | Ls]]);

format([C | Cs], [L | Ls]) ->
    format(Cs, [[C | L] | Ls]);

format([], Lines) ->
    lists:foldl(
      fun(L, Ls) ->
              LR = lists:reverse(L),
              [LR | Ls]
      end, [], Lines).

print_line(N, Lines) ->
    [L | _] = get_line(N, Lines),
    io:format("~w: ", [N]),
    print([L]).

print_lines(Pos, Len, Lines) ->
    Ls = get_line(Pos, Lines),
    print_lines1(Len, Pos, Ls).

print_lines1(0, M, [L | _]) ->
    ok;
print_lines1(N, M, [L | Ls]) ->
    io:format("~w: ", [M]),
    print([L]),
    print_lines1(N-1, M+1, Ls);
print_lines1(_, _, []) ->
    ok.

get_line(1, Ls) ->
    Ls;
get_line(N, [L | Ls]) ->
    get_line(N-1, Ls);
get_line(_, []) ->
    "\n!!! EOF !!!\n".

print([[] | Ls]) ->
    io:format("~n", []),
    print(Ls);

print([L | Ls]) ->
    io:format("~s~n", [L]),
    print(Ls);

print([]) ->
    ok.