nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Nano-devel] The undo feature


From: Benno Schulenberg
Subject: Re: [Nano-devel] The undo feature
Date: Tue, 21 Oct 2014 20:47:01 +0200

On Tue, Oct 21, 2014, at 19:36, Erik Lundin wrote:
> I've been thinking about the whole undo feature in nano. Isn't it too
> complex for the task at hand?

Possibly.  Mark has become the expert in this area, so you'd better
ask him.  (Mark is on a digest, so if you want a timely answer from
him, you have to keep him in the CC or the To.)

> This is what it looks like right now:
> 
> typedef struct undo {
>     ssize_t lineno;
>     undo_type type;
>         /* What type of undo this was. */
>     size_t begin;
>         /* Where did this action begin or end. */
>     char *strdata;
>         /* String type data we will use for copying the affected line
> back. */
>     int xflags;
>         /* Some flag data we need. */
> 
>     /* Cut-specific stuff we need. */
>     filestruct *cutbuffer;
>         /* Copy of the cutbuffer. */
>     filestruct *cutbottom;
>         /* Copy of cutbottom. */
>     bool mark_set;
>         /* Was the marker set when we cut? */
>     ssize_t mark_begin_lineno;
>         /* copy copy copy */
>     size_t mark_begin_x;
>         /* Another shadow variable. */
>     struct undo *next;
> } undo;
> 
> 
> First off. Lots of the variables here are tailored for the cut feature?
> It all boils down to the fact that you can undo one or more actions in a
> single undo. These actions can be added, changed or removed lines or a
> mix of these (macros?). So why not simplify it?
> 
> typedef enum {
>    ADD, DEL, CHANGE
> } subundo_type;
> 
> typedef struct subundo {
>    subundo_type type;
>    filestruct *line;
>    size_t mark_begin_x;
>    struct subundo *next;
> } subundo;
> 
> typedef struct undo {
>     undo_type type;
>     struct subundo *actions;
>     struct undo *next;
> } undo;
> 
> I might have missed some important variable connected to the marking or
> such. This is just an example :)
> 
> Then when adding a new undo first add it with:
> add_undo(INDENT);
> 
> Then before changing a line:
> add_subundo(CHANGE, filestruct);
> 
> Where filestruct points to the line that needs to be saved. When adding
> new lines we only need to save the line number in the filestruct.
> 
> This way you can add an unlimited amount of sequenced changes to a
> single undo. This can be used with cut, added text, indenting,
> whitespace to tabs, macros etc.
> 
> What do you think?
> 
> -- 
> Erik Lundin <address@hidden>

-- 
http://www.fastmail.fm - Or how I learned to stop worrying and
                          love email again




reply via email to

[Prev in Thread] Current Thread [Next in Thread]