buffer modified flag

3 views
Skip to first unread message

Joe

unread,
Feb 11, 2010, 1:58:46 PM2/11/10
to Ymacs - AJAX code editor
I want to add a "*" to the modeline if the buffer is modified, so I
added to ymacs-buffer.js:

P.isModified = function() {
if(this.__undoQueue.length > 0){ return "*";}
return "-";
}

P.renderModelineContent = function(rc) {
var ml = String.buffer("--", this.isModified(), "- <b>",
this.name.htmlEscape(), "</b> (", rc.row + \
1, ",", rc.col, ") ");

The only problem is that the undoQueue has length if you do a
navigation keystroke. I would think that it would only have size if
an edit action occurred. One interesting thing to do is to change the
code to:

P.isModified = function() {
return this.__undoQueue.length; }

the length of the undoQueue jumps around quite a bit and is not always
what I would expect.

Also, is there a way to get the number of lines in a buffer, and what
the current "mode" is (i.e. javascript, css etc). I'd like to add
those to the modeline.

thanks,
-joe


Mihai Călin Bazon

unread,
Feb 11, 2010, 11:15:18 PM2/11/10
to ym...@googlegroups.com
Indeed, having an isModified flag would be nice. I kept postponing
working on it :-)

The problem with the undoQueue is that everything that has been undoed
will be pushed back to the undoQueue as soon as a command which is not
"undo" is executed (so that you can undo the undo, like in Emacs). So
when you undo, changes get pushed to the __redoQueue; as soon as
undoQueue becomes empty, your isModified function will return false,
but redoQueue has data which will be pushed back to the undoQueue as
soon as you move the cursor, for instance. So I'm not sure that this
is the right solution...

I gotta run and will be offline for a few days.. Please post if you
figure out something. Patches welcome :-)

Cheers,
-Mihai

> --
> www.ymacs.com - AJAX code editor

--
Mihai Bazon,
http://mihai.bazon.net/blog

Joseph McDonald

unread,
Feb 11, 2010, 11:25:46 PM2/11/10
to ymacs
2010/2/11 Mihai Călin Bazon <mihai...@gmail.com>:

> Indeed, having an isModified flag would be nice.  I kept postponing
> working on it :-)
>
> The problem with the undoQueue is that everything that has been undoed
> will be pushed back to the undoQueue as soon as a command which is not
> "undo" is executed (so that you can undo the undo, like in Emacs).  So
> when you undo, changes get pushed to the __redoQueue; as soon as
> undoQueue becomes empty, your isModified function will return false,
> but redoQueue has data which will be pushed back to the undoQueue as
> soon as you move the cursor, for instance.  So I'm not sure that this
> is the right solution...

Ok, I'll dig into it a bit.


>
> I gotta run and will be offline for a few days..  Please post if you
> figure out something.  Patches welcome :-)

Vacation I hope. If so, have a good one!
Oh, your sig says ymacs.COM which should prob be ymacs.ORG.

-joe

Joseph McDonald

unread,
Feb 12, 2010, 12:42:53 AM2/12/10
to ymacs
2010/2/11 Mihai Călin Bazon <mihai...@gmail.com>:
> Indeed, having an isModified flag would be nice.  I kept postponing
> working on it :-)

I know of a cheat, but it's pretty ugly... upon keystroke (and
perhaps throw out navigation keys) do a crc32 calc on the buffer and
see if it matches the original. using this:
http://noteslog.com/post/crc32-for-javascript/# my pc does 100 crc32
answers per second on 10K byte strings on google chrome.

maybe it's too hackish.

-joe

Joseph McDonald

unread,
Feb 12, 2010, 1:10:14 AM2/12/10
to ymacs
actually straight string comparisons are wicked fast, so I went with this:

P.isModified = function() {
if (this.__code === this.__origCode) { return "-"; }
return "*";
}
and in P.setCode() I added:
this.__origCode = code;

The nice thing about this approach is if you modify the buffer and
then modify it in such a way that it gets back to its original state
(not necessarily using undo), the buffer will show as unmodified.
This is a better state of affairs then regular emacs which will still
show the buffer modified even if you modified it back to its original
state (something that has always mildly annoyed me).

also, now we have a string for "revert buffer"...

what do you think?

thanks,
-joe

Reply all
Reply to author
Forward
0 new messages