diff options
author | Felix Lange <fjl@twurst.com> | 2011-10-14 05:45:42 +0200 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2011-10-14 05:45:42 +0200 |
commit | bd5145368593e09460d4461256ee4f934b2ebf26 (patch) | |
tree | 471852782d61d64bede27d67552eb79af0a598aa | |
parent | 90640c1aed302fd83a500bb9ccdfb6cf7b481112 (diff) | |
download | ermacs-fork-bd5145368593e09460d4461256ee4f934b2ebf26.tar.gz |
remove cruft
cruft includes:
- module header comments (yikes..)
- author attributes (sorry luke)
- old guard tests
37 files changed, 155 insertions, 615 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..17278c0 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.beam diff --git a/ChangeLog b/ChangeLog.old index 1985f9c..1985f9c 100644 --- a/ChangeLog +++ b/ChangeLog.old diff --git a/Emakefile b/Emakefile new file mode 100644 index 0000000..873d24c --- /dev/null +++ b/Emakefile @@ -0,0 +1,2 @@ +{'src/edit_transform',[{outdir, "ebin"}, {i, "include"}]}. +{'src/*',[{outdir, "ebin"}, {i, "include"}]}. @@ -1,4 +1,17 @@ -SUBDIRS = src mods/src +ERL = erl +SRC_DIR = $(CURDIR)/src +EBIN_DIR = $(CURDIR)/ebin -include ../../support/subdir.mk +.PHONY: all clean shell +all: + $(ERL) -noinput -eval "case make:all() of up_to_date -> halt(0); error -> halt(1) end." + +clean: + rm -f $(EBIN_DIR)/*.beam + +run: all + ./bin/ermacs + +shell: all + $(ERL) -pa $(EBIN_DIR) diff --git a/bin/ermacs b/bin/ermacs new file mode 100755 index 0000000..8ade916 --- /dev/null +++ b/bin/ermacs @@ -0,0 +1,26 @@ +#!/bin/sh + +START_CWD=`pwd -P` + +SCRIPT=$0 +cd `dirname $SCRIPT` +SCRIPT=`basename $SCRIPT` +# Iterate down a (possible) chain of symlinks +while [ -L "$SCRIPT" ]; do + SCRIPT=`readlink $SCRIPT` + cd `dirname $SCRIPT` + SCRIPT=`basename $SCRIPT` +done + +PHYS_DIR=`pwd -P` +EBIN="$PHYS_DIR/../ebin" +MODS_EBIN="$PHYS_DIR/../mods/ebin" + +cd $START_CWD + +${ERL-erl} erl -pa ${EBIN}/ebin -pa ${MODS_EBIN} -noinput -noshell -nouser \ + -run edit start $* \ + 2>/tmp/ermacs-misc.log + +# How do I get sh to run this in response to SIGINT? +stty sane diff --git a/include/edit.hrl b/include/edit.hrl index 2d7bcd5..9781b00 100644 --- a/include/edit.hrl +++ b/include/edit.hrl @@ -1,15 +1,6 @@ -%% -*- comment-column: 33 -*- +-define(debug(F, A), io:format("[~s:~p] " ++ F, [?MODULE, ?LINE | A])). --ifndef(_EDIT_HRL). --define(_EDIT_HRL, true). - --define(debug(F, A), - io:format("[~s:~p] " ++ F, [?MODULE, ?LINE | A]) - ). - -%% To use the GTK terminal, use the following definition. -%% Requires that you have erlgtk and gterm in your path. -%%-define(EDIT_TERMINAL, edit_terminal_gterm). +%% TODO: remove -define(EDIT_TERMINAL, edit_terminal). -record(state, @@ -44,5 +35,3 @@ keymaps}). -define(EOL_CHAR, $$). % Character to indicate the line is chopped - --endif. diff --git a/src/Makefile b/src/Makefile deleted file mode 100644 index 087f2a9..0000000 --- a/src/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -include ../../../support/include.mk - -ERLC_FLAGS += -I ../.. -pa ../ebin/ - -SCRIPT=../bin/ermacs -SED_EXPR = s:%BASEDIR%:`pwd`/..: - -all: $(ERL_OBJECTS) $(SCRIPT) - -# edit_transform has to be built first. This rule is actually -# circular, but that seems okay with GNU make. -$(ERL_OBJECTS): ../ebin/edit_transform.beam - -$(SCRIPT): ermacs.in - sed ${SED_EXPR} < $< > $@ - chmod +x $@ - -clean: - -rm -f $(ERL_OBJECTS) - -rm -f ../bin/ermacs - -$(ERL_OBJECTS): $(ERL_HEADERS) - diff --git a/src/cord.erl b/src/cord.erl index 980248d..3e131f0 100644 --- a/src/cord.erl +++ b/src/cord.erl @@ -1,10 +1,3 @@ -%%%---------------------------------------------------------------------- -%%% File : cord.erl -%%% Author : Luke Gorrie <luke@bluetail.com> -%%% Purpose : Data structure for large strings of text -%%% Created : 21 Oct 2000 by Luke Gorrie <luke@bluetail.com> -%%%---------------------------------------------------------------------- -%% %% Cords - a scalable data structure for strings of text. %% %% Cords are binary trees with erlang binaries as leaves. The trees @@ -40,7 +33,6 @@ %% {result, R}. -module(cord). --author('luke@bluetail.com'). -compile(export_all). @@ -75,8 +67,8 @@ new() -> <<>>. -new(B) when binary(B) -> fix_cord(B); -new(L) when list(L) -> new(list_to_binary(L)). +new(B) when is_binary(B) -> fix_cord(B); +new(L) when is_list(L) -> new(list_to_binary(L)). %% More efficient way to create a cord from a file. This %% implementation is not terribly clever (read small chunks, balance @@ -112,18 +104,18 @@ make_cord(Left, Right) -> right=Right, dirty=true}. -cord_size(Cord) when binary(Cord) -> +cord_size(Cord) when is_binary(Cord) -> size(Cord); -cord_size(Cord) when record(Cord, cord) -> +cord_size(Cord = #cord{}) -> Cord#cord.size. -max_depth(Cord) when binary(Cord) -> +max_depth(Cord) when is_binary(Cord) -> 1; max_depth(Cord) -> 1 + max(max_depth(Cord#cord.left), max_depth(Cord#cord.right)). -nr_nodes(Cord) when binary(Cord) -> +nr_nodes(Cord) when is_binary(Cord) -> 1; nr_nodes(Cord) -> 1 + nr_nodes(Cord#cord.left) + nr_nodes(Cord#cord.right). @@ -135,14 +127,11 @@ mean_leaf_size(Cord) -> Sizes), round(Sum / length(Sizes)). -leaf_sizes(Cord) when binary(Cord) -> +leaf_sizes(Cord) when is_binary(Cord) -> [size(Cord)]; leaf_sizes(Cord) -> leaf_sizes(Cord#cord.left) ++ leaf_sizes(Cord#cord.right). -max(X, Y) when X > Y -> X; -max(X, Y) -> Y. - insert(Cord, New, Point) -> replace(Cord, New, Point, 0). @@ -151,7 +140,7 @@ delete(Cord, Point, Length) -> %% replace/4: Replace a region of the cord. `New' is the text to %% replace the region with, and can be either a list, binary, or cord. -replace(Cord, New, Start, Length) when list(New) -> +replace(Cord, New, Start, Length) when is_list(New) -> replace(Cord, list_to_binary(New), Start, Length); replace(Cord, New, Start, Length) -> %% Replace is done by copying the areas on the left and right of @@ -161,14 +150,14 @@ replace(Cord, New, Start, Length) -> {C, D} = split(B, Length), fix_cord(make_cord(make_cord(A, New), D)). -split(Cord, 0) when binary(Cord) -> +split(Cord, 0) when is_binary(Cord) -> {<<>>, Cord}; -split(Cord, Pos) when binary(Cord) -> +split(Cord, Pos) when is_binary(Cord) -> ?assert(Pos =< cord_size(Cord)), <<Left:Pos/binary, Right/binary>> = Cord, {Left, Right}; -split(Cord, Pos) when record(Cord, cord) -> +split(Cord = #cord{}, Pos) -> ?assert(Pos =< cord_size(Cord)), LeftSz = cord_size(Cord#cord.left), RightSz = cord_size(Cord#cord.right), @@ -184,7 +173,7 @@ split(Cord, Pos) when record(Cord, cord) -> end. %% join two cords together and rebalance. -join(Left, Right) when binary(Left) -> +join(Left, Right) when is_binary(Left) -> fix_cord(make_cord(Left, Right)). %% fix_cord/1 @@ -193,7 +182,7 @@ join(Left, Right) when binary(Left) -> %% reasonable sizes. %% Leaf (binary) - break it up if it's too big -fix_cord(Bin) when binary(Bin) -> +fix_cord(Bin) when is_binary(Bin) -> if size(Bin) > ?MAX_SIZE -> {Left, Right} = split(Bin, round(size(Bin) / 2)), fix_cord(make_cord(Left, Right)); @@ -204,7 +193,7 @@ fix_cord(Cord) when Cord#cord.dirty == false -> Cord; %% Branch (cord) - merge its children if they're too small, balance it %% if it's too unbalanced. -fix_cord(Cord) when record(Cord, cord) -> +fix_cord(Cord = #cord{}) -> Sz = cord_size(Cord), Left = Cord#cord.left, Right = Cord#cord.right, @@ -217,13 +206,13 @@ fix_cord(Cord) when record(Cord, cord) -> SzDiff > (Sz/3) -> %% needs rebalancing if LeftSz > RightSz -> - if binary(Left) -> + if is_binary(Left) -> fix_cord(to_binary(Cord)); true -> balance_from_left(Cord) end; LeftSz =< RightSz -> - if binary(Right) -> + if is_binary(Right) -> fix_cord(to_binary(Cord)); true -> balance_from_right(Cord) @@ -238,7 +227,7 @@ fix_cord(Cord) when record(Cord, cord) -> %% Balance by taking from the left side. %% Left must be a #cord, right can be a binary. -balance_from_left(#cord{left=Left, right=Right}) when record(Left, cord) -> +balance_from_left(#cord{left = Left, right = Right}) when is_record(Left, cord) -> LLSz = cord_size(Left#cord.left), LRSz = cord_size(Left#cord.right), if @@ -247,7 +236,7 @@ balance_from_left(#cord{left=Left, right=Right}) when record(Left, cord) -> fix_cord(make_cord(Left#cord.left, make_cord(Left#cord.right, Right))); - record(Left#cord.right, cord) -> + is_record(Left#cord.right, cord) -> %% double rotate LeftRight = Left#cord.right, fix_cord(make_cord(make_cord(Left#cord.left, @@ -260,7 +249,7 @@ balance_from_left(#cord{left=Left, right=Right}) when record(Left, cord) -> %% oh, pain, duplication. never have been good at taking redundancy %% out of symmetric functions. -luke -balance_from_right(#cord{left=Left, right=Right}) when record(Right, cord) -> +balance_from_right(#cord{left = Left, right = Right}) when is_record(Right, cord) -> RLSz = cord_size(Right#cord.left), RRSz = cord_size(Right#cord.right), if @@ -269,7 +258,7 @@ balance_from_right(#cord{left=Left, right=Right}) when record(Right, cord) -> fix_cord(make_cord(make_cord(Left, Right#cord.left), Right#cord.right)); - record(Right#cord.left, cord) -> + is_record(Right#cord.left, cord) -> %% double rotate RightLeft = Right#cord.left, fix_cord(make_cord(make_cord(Left, @@ -294,20 +283,20 @@ region_binary(Cord, Start, Length) -> region_list(Cord, Start, Length) -> binary_to_list(region_binary(Cord, Start, Length)). -to_binary(Cord) when binary(Cord) -> +to_binary(Cord) when is_binary(Cord) -> Cord; to_binary(Cord) -> - list_to_binary(to_binary1(Cord)). + to_binary1(Cord). -to_binary1(Cord) when binary(Cord) -> +to_binary1(Cord) when is_binary(Cord) -> Cord; -to_binary1(Cord) when record(Cord, cord) -> - [to_binary1(Cord#cord.left),to_binary1(Cord#cord.right)]. +to_binary1(Cord = #cord{left = Left, right = Right}) -> + <<(to_binary1(Left))/binary, (to_binary1(Right))/binary>>. to_list(Cord) -> binary_to_list(to_binary(Cord)). -to_iolist(Cord) when binary(Cord) -> +to_iolist(Cord) when is_binary(Cord) -> [Cord]; to_iolist(Cord) -> [to_iolist(Cord#cord.left) | to_iolist(Cord#cord.right)]. @@ -335,7 +324,7 @@ walk(Cord, Pos, Direction, F) -> walk1(<<>>, Direction, F) -> {more, F}; -walk1(Bin, Direction, F) when binary(Bin) -> +walk1(Bin, Direction, F) when is_binary(Bin) -> {Chunk, Char} = case Direction of backward -> Sz = size(Bin) - 1, @@ -351,7 +340,7 @@ walk1(Bin, Direction, F) when binary(Bin) -> {result, R} -> {result, R} end; -walk1(Cord, Direction, F) when record(Cord, cord) -> +walk1(Cord, Direction, F) when is_record(Cord, cord) -> {First, Second} = case Direction of backward -> {Cord#cord.right, Cord#cord.left}; @@ -371,7 +360,7 @@ walker(Cord) -> walker(Cord, Direction) -> walker(Cord, Direction, <<>>). -walker(Cord, Direction, More) when binary(Cord) -> +walker(Cord, Direction, More) when is_binary(Cord) -> {Cord, Direction, More}; walker(Cord, forward, More) -> walker(Cord#cord.left, forward, make_cord(Cord#cord.right, More)); @@ -500,5 +489,3 @@ split_with_each(Cord, [H|T], L, N) -> split_with_each(Cord, T, L, N); split_with_each(Cord, [], L, N) -> split_with_each(Cord, L, L, N-1). - - diff --git a/src/cord_regexp.erl b/src/cord_regexp.erl index 1d6bb4d..9927af2 100644 --- a/src/cord_regexp.erl +++ b/src/cord_regexp.erl @@ -1,12 +1,4 @@ -%%%---------------------------------------------------------------------- -%%% File : cord_regexp.erl -%%% Author : Luke Gorrie <luke@bluetail.com> -%%% Purpose : Regexp ops on cords -%%% Created : 10 Mar 2001 by Luke Gorrie <luke@bluetail.com> -%%%---------------------------------------------------------------------- - -module(cord_regexp). --author('luke@bluetail.com'). -compile(export_all). %%-export([Function/Arity, ...]). @@ -59,7 +51,7 @@ continue_match(RE, {W, N}) -> X end. -first_match1(RE, W, Pos) when list(RE) -> +first_match1(RE, W, Pos) when is_list(RE) -> case regexp:parse(RE) of {ok, REP} -> first_match1(optimise(REP), W, Pos); @@ -111,20 +103,11 @@ re_apply(eos, More, done, P, C) -> end; re_apply(eos, More, $\n, P, C) -> re_apply_more(More, P, push($\n, C)); % \n isn't consumed -re_apply(eos, More, done, P, C) -> - case cord:walker_direction(C) of - forward -> re_apply_more(More, P, C); - backward -> nomatch - end; re_apply(bos, More, done, P, C) -> case cord:walker_direction(C) of forward -> nomatch; backward -> re_apply_more(More, P, C) end; -re_apply(eos, _, done, _, _) -> - true; -re_apply(eos, _, done, _, _) -> - true; re_apply({'or', RE1, RE2}, More, Ch, P, C) -> re_apply_or({apply, RE1, More, Ch, P, C}, {apply, RE2, More, Ch, P, C}); @@ -155,7 +138,7 @@ re_apply({comp_class, Cc}, More, Ch, P, C) -> true -> nomatch; false -> re_apply_more(More, advance(P, C), C) end; -re_apply(Ch, More, Ch, P, C) when integer(Ch) -> +re_apply(Ch, More, Ch, P, C) when is_integer(Ch) -> re_apply_more(More, advance(P, C), C); re_apply(_, _, _, _, _) -> nomatch. diff --git a/src/edit.erl b/src/edit.erl index 17e4f7a..c0b4761 100644 --- a/src/edit.erl +++ b/src/edit.erl @@ -1,16 +1,7 @@ -%%%---------------------------------------------------------------------- -%%% File : edit.erl -%%% Author : Luke Gorrie <luke@bluetail.com> -%%% Purpose : Main editor process. -%%% -%%% Grown out of Tobbe's 'edit' program, and slowly rewritten. -%%%---------------------------------------------------------------------- -module(edit). --author('luke@bluetail.com'). -export([start/0]). --include_lib("ermacs/include/edit.hrl"). - +-include("edit.hrl"). -compile(export_all). %% Command-line entry function. Starts the editor. @@ -23,12 +14,7 @@ start(Args) -> %% Easy/hacky way - asynchronously ask that all the files be %% loaded. When this process is initialised it'll see the %% messages. - Filenames = lists:map(fun(X) -> atom_to_list(X) end, - Args), - lists:foreach(fun(Filename) -> - self() ! {invoke, {edit_file, find_file, [Filename]}} - end, - Filenames), + lists:foreach(fun(Filename) -> self() ! {invoke, {edit_file, find_file, [Filename]}} end, Args), start(). %% Another command-line entry function. Starts the editor with some @@ -164,7 +150,7 @@ dispatch(State) -> receive {invoke, {M, F, A}} -> dispatch_proc(State, fun() -> apply(M, F, [State | A]) end); - {invoke, Fun} when function(Fun) -> + {invoke, Fun} when is_function(Fun) -> dispatch_proc(State, fun() -> Fun(State) end); {invoke_extended, {Mod, Func, Args}} -> dispatch_extended(State, Mod, Func, Args); @@ -260,5 +246,3 @@ analyse_loop(Procs) -> eprof:total_analyse() end, analyse_loop(Procs). - - diff --git a/src/edit_bench.erl b/src/edit_bench.erl index 1c40925..d667862 100644 --- a/src/edit_bench.erl +++ b/src/edit_bench.erl @@ -1,10 +1,3 @@ -%%%------------------------------------------------------------------- -%%% File : edit_bench.erl -%%% Author : Luke Gorrie <luke@bluetail.com> -%%% Purpose : Random benchmarking -%%% -%%% Created : 29 Sep 2001 by Luke Gorrie <luke@bluetail.com> -%%%------------------------------------------------------------------- -module(edit_bench). -compile(export_all). @@ -27,6 +20,3 @@ cord_bench_loop(Cord, Pid, N) when N > 0 -> cord_receiver() -> receive {cord, Who, Cord} -> Who ! ack end, cord_receiver(). - - - diff --git a/src/edit_buf.erl b/src/edit_buf.erl index 7d89741..af3044a 100644 --- a/src/edit_buf.erl +++ b/src/edit_buf.erl @@ -1,12 +1,4 @@ -%%%---------------------------------------------------------------------- -%%% File : edit_buf.erl -%%% Author : Luke Gorrie <luke@bluetail.com> -%%% Purpose : Buffer process -%%% Created : 14 Sep 2000 by Luke Gorrie <luke@bluetail.com> -%%%---------------------------------------------------------------------- - -module(edit_buf). --author('luke@bluetail.com'). -compile(export_all). %%-export([Function/Arity, ...]). @@ -32,7 +24,7 @@ new(Name) -> Err end. -start_link(Name) when atom(Name) -> +start_link(Name) when is_atom(Name) -> case whereis(Name) of undefined -> Pid = proc_lib:spawn_link(?MODULE, init, [Name]), diff --git a/src/edit_complete.erl b/src/edit_complete.erl index b955574..bd24b9d 100644 --- a/src/edit_complete.erl +++ b/src/edit_complete.erl @@ -1,18 +1,9 @@ -%%%---------------------------------------------------------------------- -%%% File : edit_complete.erl -%%% Author : Luke Gorrie <luke@bluetail.com> -%%% Purpose : Minibuffer completion. -%%% Created : 26 Mar 2001 by Luke Gorrie <luke@bluetail.com> -%%%---------------------------------------------------------------------- - -module(edit_complete). --author('luke@bluetail.com'). --include_lib("ermacs/include/edit.hrl"). +-include("edit.hrl"). -include_lib("kernel/include/file.hrl"). -compile(export_all). -%%-export([Function/Arity, ...]). -import(edit_lib, [buffer/1]). diff --git a/src/edit_display.erl b/src/edit_display.erl index e732c62..d62d681 100644 --- a/src/edit_display.erl +++ b/src/edit_display.erl @@ -1,14 +1,5 @@ -%%%---------------------------------------------------------------------- -%%% File : edit_display.erl -%%% Author : Luke Gorrie <luke@bluetail.com> -%%% Purpose : Editor display process: talks to curses -%%% Created : 16 Sep 2000 by Luke Gorrie <luke@bluetail.com> -%%%---------------------------------------------------------------------- - -module(edit_display). --author('luke@bluetail.com'). - --include_lib("ermacs/include/edit.hrl"). +-include("edit.hrl"). -compile(export_all). %%-export([Function/Arity, ...]). @@ -38,7 +29,7 @@ try_update(Window) -> {X, Y} -> %% draw mode line draw_modeline(Window), - TrimX = edit_lib:min(X, Window#window.width - 1), + TrimX = min(X, Window#window.width - 1), ?EDIT_TERMINAL:move_to(TrimX, Y + Window#window.y), Window; undefined -> @@ -146,9 +137,6 @@ back_lines(_, N, Pos) -> dotimes(Fun, 0) -> true; -dotimes(Fun, N) when integer(N), N > 0 -> +dotimes(Fun, N) when is_integer(N), N > 0 -> Fun(), dotimes(Fun, N-1). - -min(X, Y) when X < Y -> X; -min(X, Y) -> Y. diff --git a/src/edit_display.erl.slow b/src/edit_display.erl.slow deleted file mode 100644 index 54a1d01..0000000 --- a/src/edit_display.erl.slow +++ /dev/null @@ -1,160 +0,0 @@ -%%%---------------------------------------------------------------------- -%%% File : edit_display.erl -%%% Author : Luke Gorrie <luke@bluetail.com> -%%% Purpose : Editor display process: talks to curses -%%% Created : 16 Sep 2000 by Luke Gorrie <luke@bluetail.com> -%%%---------------------------------------------------------------------- - --module(edit_display). --author('luke@bluetail.com'). - --include_lib("ermacs/include/edit.hrl"). - --compile(export_all). -%%-export([Function/Arity, ...]). - -draw_window(Window) when Window#window.minibuffer == true, - Window#window.status_text /= undefined -> - ?EDIT_TERMINAL:move_to(0, Window#window.y), - draw_line(Window#window.status_text), - Window#window{status_text=undefined}; -draw_window(Window) -> - try_update(Window). - -try_update(Window) -> - Buf = Window#window.buffer, - PointMax = edit_buf:point_max(Buf), - DStart = edit_buf:mark_pos(Buf, Window#window.start_mark), - Scan = edit_lib:beginning_of_line_pos(Buf, DStart), - Point = edit_buf:mark_pos(Buf, point), - Cord = edit_buf:get_cord(Buf), - {_, CordInFront} = cord:split(Cord, Scan-1), - Walker = cord:walker(CordInFront, forward), - ?EDIT_TERMINAL:move_to(0, Window#window.y), - Rows = edit_window:text_lines(Window), - Prefix = Window#window.prefix, - PLen = length(Prefix), - PAcc = lists:reverse(Prefix), - case try_update_loop(Walker,Rows,Scan,PLen,0,Point,undefined,PAcc) of - {X, Y} -> - %% draw mode line - draw_modeline(Window), - TrimX = edit_lib:min(X, Window#window.width - 1), - ?EDIT_TERMINAL:move_to(TrimX, Y + Window#window.y), - Window; - undefined -> - %% The point wasn't inside the area we drew, so we - %% recenter the display with the point in the middle and - %% then draw again. - try_update(recenter_window(Window)) - end. - -%% Returns the location of the point in a tuple {X, Y}, or undefined -%% if it wasn't in the area drawn. - -try_update_loop(W0, NRows, Scan, Col, Row, Point, PointXY, Acc) - when Scan == Point, PointXY == undefined -> - try_update_loop(W0, NRows, Scan, Col, Row, Point, {Col,Row}, Acc); -try_update_loop(W0, NRows, Scan, Col, Row, Point, PointXY, Acc) -> - {Ch, W1} = cord:walker_next(W0), - case Ch of - done -> - draw_line(lists:reverse(Acc)), - RemainingRows = NRows - Row, - %% draw empty lines until the end - dotimes(fun() -> draw_line([]), - ?EDIT_TERMINAL:newline() - end, - RemainingRows), - PointXY; - $\n -> - draw_line(lists:reverse(Acc)), - ?EDIT_TERMINAL:newline(), - NextRow = Row+1, - if NextRow == NRows -> - PointXY; - true -> - try_update_loop(W1,NRows,Scan+1,0,Row+1,Point,PointXY,[]) - end; - $\t -> - Size = 8 - (Col rem 8), - Tab = lists:duplicate(Size, $ ), - Acc1 = Tab++Acc, - try_update_loop(W1,NRows,Scan+1,Col+Size,Row,Point,PointXY,Acc1); - Ch -> - Acc1 = [Ch|Acc], - try_update_loop(W1,NRows,Scan+1,Col+1,Row,Point,PointXY,Acc1) - end. - -draw_line(L) -> - Wth = ?EDIT_TERMINAL:width(), - Str = trunc_line(L, Wth), - ?EDIT_TERMINAL:put_string(L), - ?EDIT_TERMINAL:erase_to_eol(). - -trunc_line([H], 1) -> [H]; -trunc_line(_, 1) -> [$$]; -trunc_line([H|T], N) -> [H|trunc_line(T, N-1)]; -trunc_line([], _) -> []. - -draw_modeline(Window) when Window#window.minibuffer == true -> - ok; -draw_modeline(Window) -> - Buffer = Window#window.buffer, - Where = modeline_where(Window, Buffer), - Text = lists:flatten( - io_lib:format("--:?? ~s (~s) ~s", - [atom_to_list(Buffer), - (edit_buf:get_mode(Buffer))#mode.name, - Where])), - ?EDIT_TERMINAL:font_reverse(), - ?EDIT_TERMINAL:move_to(0, Window#window.y + - edit_window:physical_lines(Window) - 1), - draw_line(Text), - ?EDIT_TERMINAL:font_normal(). - -modeline_where(Window, Buffer) -> - case edit_buf:get_size(Buffer) of - 0 -> - "ALL"; - BSize -> - Start = edit_buf:mark_pos(Buffer, Window#window.start_mark), - Percentage = trunc(Start * 100 / BSize), - io_lib:format("~p%", [Percentage]) - end. - -%% Update the display_start of a window so that it presents the point -%% in the middle of the screen. -recenter_window(Window) -> - Buf = Window#window.buffer, - Height = edit_window:text_lines(Window), - Pos = backward_lines(Buf, trunc(Height / 2)), - edit_buf:move_mark(Buf, Window#window.start_mark, Pos), - Window. - -backward_lines(Buf, N) -> - StartPos = edit_lib:beginning_of_line_pos(Buf), - edit_buf:walk_backward(Buf, - fun(X) -> back_lines(X, N, StartPos) end, - StartPos). - -back_lines(finish, N, Pos) -> - {result, 1}; -back_lines($\n, N, Pos) -> - if - N == 1 -> - {result, Pos}; - true -> - {more, fun(New) -> back_lines(New, N-1, Pos-1) end} - end; -back_lines(_, N, Pos) -> - {more, fun(New) -> back_lines(New, N, Pos-1) end}. - -dotimes(Fun, 0) -> - true; -dotimes(Fun, N) when integer(N), N > 0 -> - Fun(), - dotimes(Fun, N-1). - -min(X, Y) when X < Y -> X; -min(X, Y) -> Y. diff --git a/src/edit_eval.erl b/src/edit_eval.erl index 24a102e..a8e749c 100644 --- a/src/edit_eval.erl +++ b/src/edit_eval.erl @@ -1,14 +1,5 @@ -%%%---------------------------------------------------------------------- -%%% File : edit_eval.erl -%%% Author : Luke Gorrie <luke@bluetail.com> -%%% Purpose : Erlang code evaluation -%%% Created : 21 Jan 2001 by Luke Gorrie <luke@bluetail.com> -%%%---------------------------------------------------------------------- - -module(edit_eval). --author('luke@bluetail.com'). - --include_lib("ermacs/include/edit.hrl"). +-include("edit.hrl"). -compile({parse_transform, edit_transform}). @@ -178,13 +169,16 @@ find_start(Buf) -> not_found -> 1; X -> - edit_lib:min(X + length(?PROMPT), edit_buf:point_max(Buf)) + min(X + length(?PROMPT), edit_buf:point_max(Buf)) end. %% local_func(Function, Args, Bindings, Shell) -> %% {value,Val,Bs} %% Evaluate local functions, including shell commands. +local_func(F, As0, Bs0, Buf) when is_function(F) -> + {As,Bs} = erl_eval:expr_list(As0, Bs0, {eval,{?MODULE,local_func},[Buf]}), + {value, apply(F, As),Bs}; local_func(F, As0, Bs0, Buf) -> {As,Bs} = erl_eval:expr_list(As0, Bs0, {eval,{?MODULE,local_func},[Buf]}), case erlang:function_exported(user_default, F, length(As)) of @@ -192,11 +186,7 @@ local_func(F, As0, Bs0, Buf) -> {value,apply(user_default, F, As),Bs}; false -> {value,apply(shell_default, F, As),Bs} - end; -local_func(F, As0, Bs0, Buf) -> - {As,Bs} = erl_eval:expr_list(As0, Bs0, {eval,{?MODULE,local_func},[Buf]}), - {value,apply(F, As),Bs}. - + end. %% ---------------------------------------------------------------------- %% Evaluation server API diff --git a/src/edit_extended.erl b/src/edit_extended.erl index 31920ca..3849155 100644 --- a/src/edit_extended.erl +++ b/src/edit_extended.erl @@ -1,14 +1,6 @@ -%%%---------------------------------------------------------------------- -%%% File : edit_extended.erl -%%% Author : Luke Gorrie <luke@bluetail.com> -%%% Purpose : execute-extended-command (emacs lingo) -%%% Created : 14 Jan 2001 by Luke Gorrie <luke@bluetail.com> -%%%---------------------------------------------------------------------- - -module(edit_extended). --author('luke@bluetail.com'). --include_lib("ermacs/include/edit.hrl"). +-include("edit.hrl"). -compile(export_all). -compile({parse_transform, edit_transform}). @@ -20,7 +12,7 @@ extended_command(State, Mod, Func, Args) -> execute(State, Mod, Func, Args, []) -> case catch apply(Mod, Func, [State | Args]) of - S when record(S, state) -> + S when is_record(S, state) -> S; {'EXIT', Rsn} -> io:format("** Crash: ~p~n", [Rsn]), @@ -90,7 +82,7 @@ find_cmd_info(Mod, Func) -> case catch Mod:command_info() of {'EXIT', _} -> {[], ""}; - L when list(L) -> + L when is_list(L) -> case lists:keysearch(Func, 1, L) of {value, {_, Params, Doc}} -> {Params, Doc}; diff --git a/src/edit_file.erl b/src/edit_file.erl index 5c26de6..11a7661 100644 --- a/src/edit_file.erl +++ b/src/edit_file.erl @@ -1,14 +1,6 @@ -%%%---------------------------------------------------------------------- -%%% File : edit_file.erl -%%% Author : Luke Gorrie <luke@bluetail.com> -%%% Purpose : file-related editor commands -%%% Created : 14 Jan 2001 by Luke Gorrie <luke@bluetail.com> -%%%---------------------------------------------------------------------- - -module(edit_file). --author('luke@bluetail.com'). --include_lib("ermacs/include/edit.hrl"). +-include("edit.hrl"). -compile(export_all). -compile({parse_transform, edit_transform}). @@ -85,11 +77,9 @@ auto_set_mode(State) -> auto_set_mode(State, Filename, []) -> State; auto_set_mode(State, Filename, [{RE, {Mod, Fun}}|T]) -> - case regexp:match(Filename, RE) of + case re:run(Filename, RE, [{capture,none}]) of nomatch -> auto_set_mode(State, Filename, T); - {match, _, _} -> + match -> Mod:Fun(State) end. - - diff --git a/src/edit_genserv.erl b/src/edit_genserv.erl index 0ec5557..6c2aab0 100644 --- a/src/edit_genserv.erl +++ b/src/edit_genserv.erl @@ -1,16 +1,8 @@ -%%%---------------------------------------------------------------------- -%%% File : edit_genserv.erl -%%% Author : Luke Gorrie <luke@bluetail.com> -%%% Purpose : Generic utility functions for servers. -%%% Created : 28 Apr 2001 by Luke Gorrie <luke@bluetail.com> -%%%---------------------------------------------------------------------- - %% This is a library for writing servers. The idea is to have a less %% abstract gen_server, in which the protocols are exposed and the %% servers still use 'receive' to get requests with pattern matching. -module(edit_genserv). --author('luke@bluetail.com'). -export([start_link/4, call/2, call/3, reply/2, cast/2]). @@ -19,7 +11,7 @@ %% Returns: {ok, Pid} | {error, Reason} start_link(Name, M, F, A) -> case whereis(Name) of - Pid when pid(Pid) -> + Pid when is_pid(Pid) -> {error, {already_started, Pid}}; undefined -> Pid = spawn_link(M, F, A), diff --git a/src/edit_globalmap.erl b/src/edit_globalmap.erl index 8751f95..eafd335 100644 --- a/src/edit_globalmap.erl +++ b/src/edit_globalmap.erl @@ -1,12 +1,4 @@ -%%%---------------------------------------------------------------------- -%%% File : edit_globalmap.erl -%%% Author : Luke Gorrie <luke@bluetail.com> -%%% Purpose : Global keymap -%%% Created : 23 Sep 2000 by Luke Gorrie <luke@bluetail.com> -%%%---------------------------------------------------------------------- - -module(edit_globalmap). --author('luke@bluetail.com'). -export([init/0]). diff --git a/src/edit_help.erl b/src/edit_help.erl index dc904cf..3f93467 100644 --- a/src/edit_help.erl +++ b/src/edit_help.erl @@ -1,13 +1,5 @@ -%%%---------------------------------------------------------------------- -%%% File : edit_help.erl -%%% Author : Luke Gorrie <luke@bluetail.com> -%%% Purpose : Help-related functions -%%% Created : 2 Feb 2002 by Luke Gorrie <luke@bluetail.com> -%%%---------------------------------------------------------------------- - -module(edit_help). - --include_lib("ermacs/include/edit.hrl"). +-include("edit.hrl"). -import(edit_lib, [buffer/1]). @@ -37,7 +29,7 @@ find_source(S) -> {Mod, Fun, Args} -> find_source(S, Mod, Fun); _ -> - edit_lib:status_msg(S, "Not bound to a function") + edit_util:status_msg(S, "Not bound to a function") end. find_source(S0, Mod, Fun) -> @@ -51,9 +43,9 @@ find_source(S0, Mod, Fun) -> end. guess_source_file(S0) -> - case regexp:sub(S0, "ebin", "src") of + case re:replace(S0, "ebin", "src", [{return, list}]) of {ok, S1, _} -> - case regexp:sub(S1, "beam", "erl") of + case re:replace(S1, "beam", "erl", [{return, list}]) of {ok, S2, _} -> case file:read_file_info(S2) of {ok, _} -> diff --git a/src/edit_history.erl b/src/edit_history.erl index 750ac35..eaf8935 100644 --- a/src/edit_history.erl +++ b/src/edit_history.erl @@ -1,14 +1,6 @@ -%%%---------------------------------------------------------------------- -%%% File : edit_history.erl -%%% Author : Luke Gorrie <luke@bluetail.com> -%%% Purpose : Command history -%%% Created : 24 Mar 2001 by Luke Gorrie <luke@bluetail.com> -%%%---------------------------------------------------------------------- - -module(edit_history). --author('luke@bluetail.com'). --include_lib("ermacs/include/edit.hrl"). +-include("edit.hrl"). -compile({parse_transform, edit_transform}). -import(edit_lib, [buffer/1]). @@ -80,8 +72,8 @@ search(State, BaseVar, RegionFn, Regexp) -> kill_old(Buf, RegionFn), edit_buf:insert(Buf, Cmd, edit_buf:mark_pos(Buf, point)), State; - {error, Err} -> - edit_util:status_msg(State, "Error: " ++ regexp:format_error(Err)); + {error, {ErrString, Position}} -> + edit_util:status_msg(State, "Regex Error at " ++ integer_to_list(Position) ++ ": " ++ ErrString); nomatch -> edit_util:status_msg(State, "Not found") end. @@ -109,16 +101,22 @@ trim_history(Hist) when length(Hist) > ?HISTORY_MAX_LENGTH -> trim_history(Hist) -> Hist. -find_match([], Regexp) -> +find_match(Strings, Regexp) -> + case re:compile(Regexp) of + {ok, MP} -> + find_match1(Strings, MP); + {error, Error} -> + {error, Error} + end. + +find_match1([], _Regexp) -> nomatch; -find_match([H|T], Regexp) -> - case regexp:match(H, Regexp) of - nomatch -> - find_match(T, Regexp); - {match, _Start, _Length} -> - {match, H}; - {error, Err} -> - {error, Err} +find_match1([H|T], Regexp) -> + case re:run(H, Regexp) of + nomatch -> + find_match(T, Regexp); + match -> + {match, H} end. list_var(Base) -> Base. diff --git a/src/edit_input.erl b/src/edit_input.erl index 2f0990a..e1b4b06 100644 --- a/src/edit_input.erl +++ b/src/edit_input.erl @@ -1,14 +1,6 @@ -%%%---------------------------------------------------------------------- -%%% File : edit_input.erl -%%% Author : Luke Gorrie <luke@bluetail.com> -%%% Purpose : Keyboard input server -%%% Created : 22 Jan 2001 by Luke Gorrie <luke@bluetail.com> -%%%---------------------------------------------------------------------- - -module(edit_input). --author('luke@bluetail.com'). --include_lib("ermacs/include/edit.hrl"). +-include("edit.hrl"). -export([start_link/1, loop/1]). diff --git a/src/edit_keymap.erl b/src/edit_keymap.erl index 9ed0ce6..c69c37d 100644 --- a/src/edit_keymap.erl +++ b/src/edit_keymap.erl @@ -1,12 +1,4 @@ -%%%---------------------------------------------------------------------- -%%% File : edit_keymap.erl -%%% Author : Luke Gorrie <luke@bluetail.com> -%%% Purpose : Keymap implemented as an ETS table -%%% Created : 23 Sep 2000 by Luke Gorrie <luke@bluetail.com> -%%%---------------------------------------------------------------------- - -module(edit_keymap). --author('luke@bluetail.com'). -export([start_link_server/0, new/1, keymap_exists/1, global_set_key/2, set_key/3, @@ -16,7 +8,7 @@ start_link_server() -> case whereis(?MODULE) of - Pid when pid(Pid) -> + Pid when is_pid(Pid) -> {error, {already_started, Pid}}; undefined -> Pid = spawn_link(?MODULE, server, []), diff --git a/src/edit_lex.erl b/src/edit_lex.erl deleted file mode 100644 index 4d6e6ef..0000000 --- a/src/edit_lex.erl +++ /dev/null @@ -1,14 +0,0 @@ -%%%---------------------------------------------------------------------- -%%% File : edit_lex.erl -%%% Author : Luke Gorrie <luke@bluetail.com> -%%% Purpose : Lexer -%%% Created : 8 Apr 2001 by Luke Gorrie <luke@bluetail.com> -%%%---------------------------------------------------------------------- - --module(edit_lex). --author('luke@bluetail.com'). - -%%-compile(export_all). -%%-export([Function/Arity, ...]). - - diff --git a/src/edit_lib.erl b/src/edit_lib.erl index 08fd0aa..412de2c 100644 --- a/src/edit_lib.erl +++ b/src/edit_lib.erl @@ -1,17 +1,11 @@ -module(edit_lib). --author('tobbe@serc.rmit.edu.au'). -%%---------------------------------------------------------------------- -%% Created : 15 Jun 1998 by tobbe@serc.rmit.edu.au -%% Function: Core library routines for the Edit editor. -%%---------------------------------------------------------------------- --vc('$Id$ '). --include_lib("ermacs/include/edit.hrl"). +-include("edit.hrl"). -compile(export_all). -compile({parse_transform, edit_transform}). -self_insert_command(S,Ch) when record(S,state) -> +self_insert_command(S,Ch) when is_record(S,state) -> insert_char(S,Ch). delete_char_backward(S) -> @@ -67,7 +61,7 @@ abort(S) -> %% ----------------------------------- %% Move cursor vertically down 1 line. -next_line(S) when record(S,state) -> +next_line(S) when is_record(S,state) -> Buf = buffer(S), NewWindow = update_goal(S, Buf), Goal = NewWindow#window.goal_column, @@ -82,7 +76,7 @@ next_line(S) when record(S,state) -> S#state{curwin=NewWindow} end. -previous_line(S) when record(S,state) -> +previous_line(S) when is_record(S,state) -> Buf = buffer(S), NewWindow = update_goal(S, Buf), Goal = NewWindow#window.goal_column, @@ -141,7 +135,7 @@ point(Buf) -> %% ---------------------------- %% Move point left 1 character. -backward_char(S) when record(S,state) -> +backward_char(S) when is_record(S,state) -> Buf = buffer(S), Pos = edit_buf:mark_pos(Buf, point) - 1, case Pos < 1 of @@ -155,7 +149,7 @@ backward_char(S) when record(S,state) -> %% Move point right 1 character. %% -forward_char(S) when record(S,state) -> +forward_char(S) when is_record(S,state) -> Buf = buffer(S), Pos = edit_buf:mark_pos(Buf, point) + 1, Max = edit_buf:point_max(Buf), @@ -202,7 +196,7 @@ beginning_of_line_pos(Buf, Pos) -> %% We start before the point, incase we're on a newline case find_char_backward(Buf, const_P($\n), Pos - 1) of not_found -> 1; % point_min - N when integer(N) -> N + 1 % we want to be just after the newline + N when is_integer(N) -> N + 1 % we want to be just after the newline end. move_to_char_backward(Buf, Pred) -> @@ -220,7 +214,7 @@ find_char_backward(Buf, Pred, Pos, Default) -> Pos) of not_found -> Default; - P when integer(P) -> + P when is_integer(P) -> P end. @@ -257,7 +251,7 @@ end_of_line_pos(Buf, Pos) -> P = case find_char_forward(Buf, fun(C) -> C == $\n end, Pos) of not_found -> edit_buf:point_max(Buf); - N when integer(N) -> + N when is_integer(N) -> N end. @@ -276,7 +270,7 @@ find_char_forward(Buf, Pred, Pos, Default) -> Pos) of not_found -> Default; - P when integer(P) -> + P when is_integer(P) -> P end. @@ -316,7 +310,7 @@ scroll_up(State) -> case find_nth(Buf, backward, DStart, $\n, Height - 1) of not_found -> 1; - X when integer(X) -> + X when is_integer(X) -> X + 1 end, DEnd = case find_nth(Buf, forward, NewDStart, $\n, Height) of @@ -340,7 +334,7 @@ scroll_down(State) -> DStart = edit_buf:mark_pos(Buf, Win#window.start_mark), PMax = edit_buf:point_max(Buf), case find_nth(Buf, forward, DStart, $\n, edit_window:text_lines(Win)-2) of - X when integer(X), + X when is_integer(X), X < PMax -> %% We want to be just after the newline - i.e. start of next line Pos = X + 1, @@ -365,7 +359,7 @@ scroll_down_wrap(Win) -> PMax = edit_buf:point_max(Buf), Lines = edit_window:text_lines(Win), Pos = case find_nth(Buf, forward, DStart, $\n, Lines) of - X when integer(X), + X when is_integer(X), X < PMax -> %% We want to be just after the newline - i.e. start %% of next line @@ -633,7 +627,7 @@ kill_buffer(State, Name) -> State; Buffers -> case whereis(BufferName) of - Pid when pid(Pid) -> + Pid when is_pid(Pid) -> edit_buf:kill(BufferName), NewBuffers = Buffers -- [BufferName], F = fun(Win) -> @@ -653,12 +647,6 @@ kill_buffer(State, Name) -> end end. -min(X,Y) when X<Y -> X; -min(_,Y) -> Y. - -max(X,Y) when X>Y -> X; -max(_,Y) -> Y. - %% Get the buffer from state - blocks if it's being borrowed by someone else. buffer(State) -> Buf = (State#state.curwin)#window.buffer, diff --git a/src/edit_make.erl b/src/edit_make.erl deleted file mode 100644 index 20f6cc2..0000000 --- a/src/edit_make.erl +++ /dev/null @@ -1,14 +0,0 @@ --module(edit_make). --export([start/0]). - -start() -> - spawn(fun() -> doit() end). - -doit() -> - sleep(1), - ig:gen(edit_ig), - c:c(edit_ig), - halt(). - -sleep(Sec) -> - receive after Sec*1000 -> true end. diff --git a/src/edit_mod.erl b/src/edit_mod.erl index ae5be54..bc78532 100644 --- a/src/edit_mod.erl +++ b/src/edit_mod.erl @@ -1,12 +1,4 @@ -%%%---------------------------------------------------------------------- -%%% File : edit_mod.erl -%%% Author : Luke Gorrie <luke@bluetail.com> -%%% Purpose : Module loader -%%% Created : 28 Apr 2001 by Luke Gorrie <luke@bluetail.com> -%%%---------------------------------------------------------------------- - -module(edit_mod). --author('luke@bluetail.com'). -export([init/0, require/1, load/1]). diff --git a/src/edit_terminal.erl b/src/edit_terminal.erl index b18cafb..d6841c7 100644 --- a/src/edit_terminal.erl +++ b/src/edit_terminal.erl @@ -1,12 +1,4 @@ -%%%---------------------------------------------------------------------- -%%% File : edit_terminal.erl -%%% Author : Luke Gorrie <luke@bluetail.com> -%%% Purpose : ncurses terminal implementation -%%% Created : 16 Sep 2000 by Luke Gorrie <luke@bluetail.com> -%%%---------------------------------------------------------------------- - -module(edit_terminal). --author('luke@bluetail.com'). -include_lib("slang/include/slang.hrl"). diff --git a/src/edit_terminal_gterm.erl b/src/edit_terminal_gterm.erl deleted file mode 100644 index 0d6b678..0000000 --- a/src/edit_terminal_gterm.erl +++ /dev/null @@ -1,42 +0,0 @@ -%%%---------------------------------------------------------------------- -%%% File : edit_terminal_gterm.erl -%%% Author : Luke Gorrie <luke@bluetail.com> -%%% Purpose : edit_terminal implementation for gterm (Tony's GTK terminal -%%% emulator) -%%% Created : 14 Mar 2001 by Luke Gorrie <luke@bluetail.com> -%%%---------------------------------------------------------------------- - --module(edit_terminal_gterm). --author('luke@bluetail.com'). - --compile(export_all). -%%-export([Function/Arity, ...]). - -%% name of terminal process --define(TERM, ?MODULE). - -setup() -> - Term = gterm:run(), - register(?TERM, Term), -% gterm_api:set_local_echo(Term, false), -% gterm_api:set_auto_scroll(Term, false), - Term. - -teardown() -> - gterm_api:quit(). - -newline() -> gterm_api:newline(?TERM). -put_char(C) -> gterm_api:put_char(?TERM, C). -put_string(S) -> gterm_api:put_string(?TERM, S). -format(Fmt, Args) -> gterm_api:format(?TERM, Fmt, Args). -erase_to_eol() -> gterm_api:erase_to_eol(?TERM). -move_to(X, Y) -> gterm_api:move_to(?TERM, X, Y). -refresh() -> gterm_api:refresh(?TERM). -invalidate() -> gterm_api:refresh(?TERM). -width() -> gterm_api:width(?TERM). -height() -> gterm_api:height(?TERM). -read() -> gterm_api:read(?TERM). -font_reverse() -> gterm_api:font_reverse(?TERM). -font_normal() -> gterm_api:font_normal(?TERM). - - diff --git a/src/edit_text.erl b/src/edit_text.erl index 3bcc7d9..2c83594 100644 --- a/src/edit_text.erl +++ b/src/edit_text.erl @@ -1,12 +1,4 @@ -%%%---------------------------------------------------------------------- -%%% File : edit_text.erl -%%% Author : Luke Gorrie <luke@bluetail.com> -%%% Purpose : Text data structure with markers and undo -%%% Created : 2 Oct 2001 by Luke Gorrie <luke@bluetail.com> -%%%---------------------------------------------------------------------- - -module(edit_text). --author('luke@bluetail.com'). -export([new/0, new/1, replace/4, add_mark/4, move_mark/3, mark_pos/2, undo/2, cord/1, walk_backward/3, walk_forward/3]). @@ -21,7 +13,7 @@ new() -> new(<<>>). -new(BCS) when list(BCS) -> +new(BCS) when is_list(BCS) -> new(cord:new(BCS)); new(Cord) -> #text{cord=Cord}. @@ -38,9 +30,9 @@ replace(Text0 = #text{cord=Cord0,marks=Marks0,undo=Undo0}, CBS, Start, Len) -> %% ...) - if that plays nicely with "running undo" Text0#text{cord=Cord1, marks=Marks1, undo=Undo1, running_undo=[]}. -cbs_length(L) when list(L) -> length(L); -cbs_length(B) when binary(B) -> size(B); -cbs_length(C) -> cord:cord_size(C). +cbs_length(L) when is_list(L) -> length(L); +cbs_length(B) when is_binary(B) -> size(B); +cbs_length(C) -> cord:cord_size(C). update_marks(Marks, Start, End, Len) -> [update_mark(Mark,Start,End,Len) || Mark <- Marks]. @@ -88,7 +80,7 @@ mark_pos(#text{marks=Marks}, Name) -> {found, Mark} = find(fun(M) -> M#mark.name == Name end, Marks), Mark#mark.pos. -find(Pred, []) -> +find(_Pred, []) -> not_found; find(Pred, [H|T]) -> case Pred(H) of diff --git a/src/edit_transform.erl b/src/edit_transform.erl index 52bd294..34c3043 100644 --- a/src/edit_transform.erl +++ b/src/edit_transform.erl @@ -1,16 +1,9 @@ -%%%---------------------------------------------------------------------- -%%% File : edit_transform.erl -%%% Author : Luke Gorrie <luke@bluetail.com> -%%% Purpose : Parse transform module for editor command modules -%%% Created : 25 Oct 2000 by Luke Gorrie <luke@bluetail.com> -%%%---------------------------------------------------------------------- - +%% Parse transform module for editor command modules +% % -command({cmd1, [{name1, prompt1}], doc1}). % -command({cmd2, []}). -module(edit_transform). --author('luke@bluetail.com'). - -export([parse_transform/2]). %% Collect "command" attributes to generate a command_info function. These @@ -22,7 +15,7 @@ %% %% command_info() returns [{Fun, [Arg], DocString}] %% -parse_transform(Form, Opts) -> +parse_transform(Form, _Opts) -> {Head, Rest} = split(Form), {Body, EOF} = splitlast(Rest), Line = element(2, hd(Body)), @@ -56,7 +49,7 @@ scan_and_parse(Source, Line) -> %% 'module' attribute, Body is the rest. split(Form) -> split(Form, []). -split([X = {attribute, Line, module, Module}|T], Acc) -> +split([X = {attribute, _Line, module, _Module}|T], Acc) -> {lists:reverse([X|Acc]), T}; split([H|T], Acc) -> split(T, [H|Acc]). diff --git a/src/edit_util.erl b/src/edit_util.erl index c539277..2a08e28 100644 --- a/src/edit_util.erl +++ b/src/edit_util.erl @@ -1,14 +1,6 @@ -%%%---------------------------------------------------------------------- -%%% File : edit_util.erl -%%% Author : Luke Gorrie <luke@bluetail.com> -%%% Purpose : Utility functions -%%% Created : 15 Oct 2000 by Luke Gorrie <luke@bluetail.com> -%%%---------------------------------------------------------------------- - -module(edit_util). --author('luke@bluetail.com'). --include_lib("ermacs/include/edit.hrl"). +-include("edit.hrl"). -export([keyname/1, status_msg/2, status_msg/3, update_minibuffer_window/2, select_window/2, update/3]). @@ -209,11 +201,11 @@ spawn_with_init(Pid, Ref, Buffers, What) -> Pid ! {ready, Ref}, spawn_with_apply(What), %% we miss this redraw if the command crashes. oops. - edit:invoke_later(?MODULE, redraw, []). + edit:invoke_async(?MODULE, redraw, []). spawn_with_apply({M, F, A}) -> apply(M, F, A); -spawn_with_apply(Fun) when function(Fun) -> +spawn_with_apply(Fun) when is_function(Fun) -> Fun(). @@ -223,9 +215,9 @@ redraw(State) -> State. %% Get the current working directory for the state or buffer. -pwd(State) when record(State, state) -> +pwd(State) when is_record(State, state) -> pwd((State#state.curwin)#window.buffer); -pwd(Buf) when atom(Buf) -> +pwd(Buf) when is_atom(Buf) -> case edit_buf:get_filename(Buf) of undefined -> case file:get_cwd() of @@ -242,4 +234,3 @@ pwd(Buf) when atom(Buf) -> Filename -> filename:dirname(Filename)++"/" end. - diff --git a/src/edit_var.erl b/src/edit_var.erl index 0af74b4..0e264b6 100644 --- a/src/edit_var.erl +++ b/src/edit_var.erl @@ -1,20 +1,9 @@ -%%%---------------------------------------------------------------------- -%%% File : edit_var.erl -%%% Author : Luke Gorrie <luke@bluetail.com> -%%% Purpose : Variable management server - transient and persistent -%%% Created : 21 Jan 2001 by Luke Gorrie <luke@bluetail.com> -%%%---------------------------------------------------------------------- - %%% This module implements "setq"-like variables. But, this seems a bit %%% distasteful because of concurrent updates and so on. Maybe there is %%% better way to do variables in general (or just program-internal %%% variables). -module(edit_var). --author('luke@bluetail.com'). - -%%-compile(export_all). -%%-export([Function/Arity, ...]). -behaviour(gen_server). @@ -70,12 +59,10 @@ include([H|T], Value) -> [H|include(T, Value)]. init([]) -> Filename = filename:join(os:getenv("HOME"), "edit_var.dets"), Ets = ets:new(edit_mem_var, [set, public, named_table]), - {ok, Dets} = dets:open_file(edit_disk_var, - [{type, set}, - {file, Filename}]), + {ok, Dets} = dets:open_file(edit_disk_var, [{type, set}, {file, Filename}]), load_file(Dets, Ets), - State = #state{ets=Ets, - dets=Dets}, + State = #state{ets = Ets, dets = Dets}, + {ok, State}. %%---------------------------------------------------------------------- diff --git a/src/edit_window.erl b/src/edit_window.erl index a14c047..1ef1b06 100644 --- a/src/edit_window.erl +++ b/src/edit_window.erl @@ -1,14 +1,6 @@ -%%%---------------------------------------------------------------------- -%%% File : edit_window.erl -%%% Author : Luke Gorrie <luke@bluetail.com> -%%% Purpose : Window handling functions -%%% Created : 14 Oct 2000 by Luke Gorrie <luke@bluetail.com> -%%%---------------------------------------------------------------------- - -module(edit_window). --author('luke@bluetail.com'). --include_lib("ermacs/include/edit.hrl"). +-include("edit.hrl"). -compile(export_all). %%-export([Function/Arity, ...]). @@ -39,7 +31,7 @@ width(W) -> %% the window knows where it's up to. attach(Window, Buffer) -> attach(Window, Buffer, 1). -attach(Window, Buffer, Start) -> +attach(Window, Buffer, _Start) -> edit_buf:add_mark(Buffer, Window#window.start_mark, 1, backward), Window#window{buffer=Buffer}. diff --git a/src/ermacs.in b/src/ermacs.in deleted file mode 100644 index accb10f..0000000 --- a/src/ermacs.in +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh - -BASEDIR=%BASEDIR% - -erl -pa ${BASEDIR}/ebin -pa ${BASEDIR}/mods/ebin \ - -noshell -nouser -s edit start $* 2>/tmp/ermacs-misc.log - -# How do I get sh to run this in response to SIGINT? -stty sane - |