Erlang Development Environment

Peter Andersson <>
Fri Mar 9 16:12:59 CET 2001

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: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".


1> utils:manfind(ets, "*new*").
89:      new(Name, Type)
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.


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


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

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

man(Module) when atom(Module) ->

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

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
	_ ->
	    search(Ls, Lines, String, N+1)

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

new_search(1, _, _) ->

new_search(Cur, N, Lines) ->
    case io:get_line('[N/s/p/q]>') of
	"s\n" ->
	"q\n" ->
	"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)

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) ->
      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_lines(Pos, Len, Lines) ->
    Ls = get_line(Pos, Lines),
    print_lines1(Len, Pos, Ls).

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

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

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

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

print([]) ->

More information about the erlang-questions mailing list