From c310c7d875c8aa871180de130e820ed19a2489f5 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Fri, 12 Dec 2014 16:39:46 +0100 Subject: implemented automatic EOL translation support * activated via bit 4 of the ED flag (enabled by default) * automatic EOL guessing on file loading and translation to LFs. * works with files that have inconsistent EOL sequences. * automatic translation to original EOL sequences on file saving * works with inconsistent EOL sequences in the buffer. This should usually not happen if the file was read in with automatic EOL translation enabled. * also works with the EC and EG commands * performance is OK, depending on the file being translated. When reading files with UNIX EOLs, the overhead is minimal typically-sized files. For DOS EOLs the overhead is larger but still acceptable. * Return (line feed) is now an immediate editing command. This centralizes EOL sequence insertion. Later, other features like auto-indent could be added to the editing command. * get_eol() has been moved to main.cpp (now called get_eol_seq() * Warn if file ownership could not be preserved when saving files. * IOView has been almost completely rewritten based on GIOChannels. The EOL translation code is also in IOView. --- src/qregisters.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'src/qregisters.cpp') diff --git a/src/qregisters.cpp b/src/qregisters.cpp index acb12cf..e792fc0 100644 --- a/src/qregisters.cpp +++ b/src/qregisters.cpp @@ -251,6 +251,40 @@ QRegister::execute(bool locals) g_free(str); } +void +QRegister::undo_set_eol_mode(void) +{ + if (!must_undo) + return; + + /* + * Necessary, so that upon rubout the + * string's parameters are restored. + */ + string.update(QRegisters::view); + + if (QRegisters::current && QRegisters::current->must_undo) + QRegisters::current->string.undo_edit(QRegisters::view); + + QRegisters::view.undo_ssm(SCI_SETEOLMODE, + QRegisters::view.ssm(SCI_GETEOLMODE)); + + string.undo_edit(QRegisters::view); +} + +void +QRegister::set_eol_mode(gint mode) +{ + if (QRegisters::current) + QRegisters::current->string.update(QRegisters::view); + + string.edit(QRegisters::view); + QRegisters::view.ssm(SCI_SETEOLMODE, mode); + + if (QRegisters::current) + QRegisters::current->string.edit(QRegisters::view); +} + void QRegister::load(const gchar *filename) { @@ -262,6 +296,11 @@ QRegister::load(const gchar *filename) string.edit(QRegisters::view); string.reset(); + /* + * IOView::load() might change the EOL style. + */ + undo_set_eol_mode(); + /* * undo_set_string() pushes undo tokens that restore * the previous document in the view. -- cgit v1.2.3