changeset 31009:a0c8c28c38cb

maint: Merge stable to default.
author Markus Mützel <markus.muetzel@gmx.de>
date Sun, 22 May 2022 19:36:01 +0200
parents 497de29f6946 (current diff) 4d74446020ad (diff)
children 77968df298fd
files libgui/src/m-editor/file-editor-tab.cc libgui/src/main-window.cc libinterp/corefcn/pr-output.cc
diffstat 2 files changed, 33 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc	Sat May 21 09:03:10 2022 +0200
+++ b/libgui/src/m-editor/file-editor-tab.cc	Sun May 22 19:36:01 2022 +0200
@@ -2201,8 +2201,24 @@
     if (trackedFiles.contains (file_to_save))
       m_file_system_watcher.removePath (file_to_save);
 
-    // open the file for writing
-    if (! file.open (QIODevice::WriteOnly))
+    // Remove trailing white spaces if desired
+    resource_manager& rmgr = m_octave_qobj.get_resource_manager ();
+    gui_settings *settings = rmgr.get_settings ();
+
+    if (settings->value (ed_rm_trailing_spaces).toBool ())
+      {
+        // Replace trailing spaces, make sure edit area is writable,
+        // which is not the case when saving at exit or when closing
+        // the modified file.
+        bool ro = m_edit_area->isReadOnly ();
+        m_edit_area->setReadOnly (false); // allow writing for replace_all
+        m_edit_area->replace_all ("[ \\t]+$", "", true, false, false);
+        m_edit_area->setReadOnly (ro);    // recover read only state
+      }
+
+    // open the file for writing (use QIODevice::ReadWrite for avoiding
+    // truncating the previous file contents)
+    if (! file.open (QIODevice::ReadWrite))
       {
         // Unsuccessful, begin watching file again if it was being
         // watched previously.
@@ -2231,13 +2247,6 @@
     if (! codec)
       return;   // No valid codec
 
-    // Remove trailing white spaces if desired
-    resource_manager& rmgr = m_octave_qobj.get_resource_manager ();
-    gui_settings *settings = rmgr.get_settings ();
-
-    if (settings->value (ed_rm_trailing_spaces).toBool ())
-      m_edit_area->replace_all ("[ \\t]+$", "", true, false, false);
-
     // Save the file
     out.setCodec (codec);
 
--- a/libinterp/corefcn/pr-output.cc	Sat May 21 09:03:10 2022 +0200
+++ b/libinterp/corefcn/pr-output.cc	Sun May 22 19:36:01 2022 +0200
@@ -3845,18 +3845,19 @@
 As with the @samp{short} format, Octave will switch to an exponential @samp{e}
 format if it is unable to format a matrix properly using the current format.
 
-@item  short e
-@itemx long e
+@item  shorte
+@itemx longe
 Exponential format.  The number to be represented is split between a mantissa
 and an exponent (power of 10).  The mantissa has 5 significant digits in the
 short format.  In the long format, double values are displayed with 16
 significant digits and single values are displayed with 8.  For example,
-with the @samp{short e} format, @code{pi} is displayed as @code{3.1416e+00}.
-
-@item  short g
-@itemx long g
+with the @samp{shorte} format, @code{pi} is displayed as @code{3.1416e+00}.
+Optionally, the trailing @samp{e} can be split into a second argument.
+
+@item  shortg
+@itemx longg
 Optimally choose between fixed point and exponential format based on the
-magnitude of the number.  For example, with the @samp{short g} format,
+magnitude of the number.  For example, with the @samp{shortg} format,
 @code{pi .^ [2; 4; 8; 16; 32]} is displayed as
 
 @example
@@ -3870,12 +3871,14 @@
   8.1058e+15
 @end group
 @end example
-
-@item  short eng
-@itemx long eng
-Identical to @samp{short e} or @samp{long e} but displays the value using an
+Optionally, the trailing @samp{g} can be split into a second argument.
+
+@item  shorteng
+@itemx longeng
+Identical to @samp{shorte} or @samp{longe} but displays the value using an
 engineering format, where the exponent is divisible by 3.  For example, with
-the @samp{short eng} format, @code{10 * pi} is displayed as @code{31.416e+00}.
+the @samp{shorteng} format, @code{10 * pi} is displayed as @code{31.416e+00}.
+Optionally, the trailing @samp{eng} can be split into a second argument.
 
 @item  free
 @itemx none