changeset 32075:9583d971e603

mfile_encoding: Add to officially documented functions. * libinterp/corefcn/input.cc (Fmfile_encoding): Rename from "F__mfile_encoding__". Add documentation. Add alias with the former name. * doc/interpreter/func.txi: Add documentation for function to manual. * doc/interpreter/basics.txi, libgui/src/main-window.cc (main_window::update_default_encoding), scripts/pkg/private/install.m (extract_pkg), scripts/testfun/__run_test_suite__.m, test/file-encoding/file-encoding.tst: Adapt for changed function name.
author Markus Mützel <markus.muetzel@gmx.de>
date Thu, 04 May 2023 18:06:08 +0200
parents 03fe0b635d2e
children 7ce8302036c1
files doc/interpreter/basics.txi doc/interpreter/func.txi libgui/src/main-window.cc libinterp/corefcn/input.cc scripts/pkg/private/install.m scripts/testfun/__run_test_suite__.m test/file-encoding/file-encoding.tst
diffstat 7 files changed, 42 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/doc/interpreter/basics.txi	Wed May 03 22:52:33 2023 -0400
+++ b/doc/interpreter/basics.txi	Thu May 04 18:06:08 2023 +0200
@@ -391,11 +391,11 @@
 properties).  In other words, the system's locale charset is in effect until a
 user manually sets the m-file encoding (e.g., in one of the startup files) and
 triggers re-parsing of any relevant m-files.  Octave can be forced to use a
-new encoding with the undocumented function @code{__mfile_encoding__}:
+new encoding with the function @code{mfile_encoding}:
 
 @example
 @group
-__mfile_encoding__ ("utf-8");  # set new encoding
+mfile_encoding ("utf-8");  # set new encoding
 clear ("functions");  # re-parse all .m files in the new encoding
 @end group
 @end example
--- a/doc/interpreter/func.txi	Wed May 03 22:52:33 2023 -0400
+++ b/doc/interpreter/func.txi	Thu May 04 18:06:08 2023 +0200
@@ -926,6 +926,8 @@
 
 @DOCSTRING(dir_in_loadpath)
 
+@DOCSTRING(mfile_encoding)
+
 @DOCSTRING(dir_encoding)
 
 @node Subfunctions
--- a/libgui/src/main-window.cc	Wed May 03 22:52:33 2023 -0400
+++ b/libgui/src/main-window.cc	Thu May 04 18:06:08 2023 +0200
@@ -2751,7 +2751,7 @@
      {
        // INTERPRETER THREAD
 
-       F__mfile_encoding__ (interp, ovl (mfile_encoding));
+       Fmfile_encoding (interp, ovl (mfile_encoding));
      });
 }
 
--- a/libinterp/corefcn/input.cc	Wed May 03 22:52:33 2023 -0400
+++ b/libinterp/corefcn/input.cc	Thu May 04 18:06:08 2023 +0200
@@ -488,7 +488,7 @@
 
   octave_value retval
     = set_internal_variable (m_mfile_encoding, args, nargout,
-                             "__mfile_encoding__");
+                             "mfile_encoding");
 
   // Additional validation if the encoding has changed.
 
@@ -515,10 +515,10 @@
             {
               m_mfile_encoding = saved_encoding;
               if (errno == EINVAL)
-                error ("__mfile_encoding__: conversion from encoding '%s' "
+                error ("mfile_encoding: conversion from encoding '%s' "
                        "not supported", encoding.c_str ());
               else
-                error ("__mfile_encoding__: error %d opening encoding '%s'",
+                error ("mfile_encoding: error %d opening encoding '%s'",
                        errno, encoding.c_str ());
             }
           else
@@ -1570,14 +1570,31 @@
   return input_sys.gud_mode (args, nargout);
 }
 
-DEFMETHOD (__mfile_encoding__, interp, args, nargout,
+DEFMETHOD (mfile_encoding, interp, args, nargout,
            doc: /* -*- texinfo -*-
-@deftypefn  {} {@var{current_encoding} =} __mfile_encoding__ ()
-@deftypefnx {} {} __mfile_encoding__ (@var{new_encoding})
-@deftypefnx {} {@var{old_encoding} =} __mfile_encoding__ (@var{new_encoding})
-Query or set the codepage that is used for reading m-files.
+@deftypefn  {} {@var{current_encoding} =} mfile_encoding ()
+@deftypefnx {} {} mfile_encoding (@var{new_encoding})
+@deftypefnx {} {@var{old_encoding} =} mfile_encoding (@var{new_encoding})
+Query or set the encoding that is used for reading m-files.
+
+The input and output are strings naming an encoding, e.g., "utf-8".
+
+This encoding is used by Octave's parser when reading m-files unless a
+different encoding was set for a specific directory containing m-files using
+the function @code{dir_encoding} or in a file @file{.oct-config} in that
+directory.
 
-The input and output are strings naming a particular codepage, e.g., "utf-8".
+The special value @qcode{"system"} selects the encoding that matches the system
+locale.
+
+If the m-file encoding is changed after the m-files have already been parsed,
+the files have to be parsed again for that change to take effect.  That can be
+triggered with the command @code{clear all}.
+
+Additionally, this encoding is used to load and save files with the built-in
+editor in Octave's GUI.
+
+@seealso{dir_encoding}
 @end deftypefn */)
 {
   input_system& input_sys = interp.get_input_system ();
@@ -1585,6 +1602,8 @@
   return input_sys.mfile_encoding (args, nargout);
 }
 
+DEFALIAS (__mfile_encoding__, mfile_encoding);
+
 DEFMETHOD (dir_encoding, interp, args, nargout,
            doc: /* -*- texinfo -*-
 @deftypefn  {} {@var{current_encoding} =} dir_encoding (@var{dir})
@@ -1593,7 +1612,8 @@
 @deftypefnx {} {@var{old_encoding} =} dir_encoding (@var{dir}, @var{new_encoding})
 Query or set the @var{encoding} that is used for reading m-files in @var{dir}.
 
-The per-directory encoding overrides the (globally set) m-file encoding.
+The per-directory encoding overrides the (globally set) m-file encoding,
+@pxref{XREFmfile_encoding,,@code{mfile_encoding}}.
 
 The string @var{DIR} must match how the directory would appear in the load
 path.
@@ -1622,7 +1642,7 @@
 files have to be parsed again for that change to take effect.  That can be done
 with the command @code{clear all}.
 
-@seealso{addpath, path}
+@seealso{addpath, path, mfile_encoding}
 @end deftypefn */)
 {
   int nargin = args.length ();
--- a/scripts/pkg/private/install.m	Wed May 03 22:52:33 2023 -0400
+++ b/scripts/pkg/private/install.m	Thu May 04 18:06:08 2023 +0200
@@ -329,11 +329,7 @@
 
 function pkg = extract_pkg (nm, pat)
 
-  mfile_encoding = __mfile_encoding__ ();
-  if (strcmp (mfile_encoding, "system"))
-    mfile_encoding = __locale_charset__ ();
-  endif
-  fid = fopen (nm, "rt", "n", mfile_encoding);
+  fid = fopen (nm, "rt", "n", mfile_encoding ());
   pkg = "";
   if (fid >= 0)
     while (! feof (fid))
--- a/scripts/testfun/__run_test_suite__.m	Wed May 03 22:52:33 2023 -0400
+++ b/scripts/testfun/__run_test_suite__.m	Thu May 04 18:06:08 2023 +0200
@@ -55,7 +55,7 @@
   pso = page_screen_output ();
   orig_wquiet = warning ("query", "quiet");
   orig_wstate = warning ();
-  orig_mfile_encoding = __mfile_encoding__ ("utf-8");
+  orig_mfile_encoding = mfile_encoding ("utf-8");
   logfile = make_absolute_filename ("fntests.log");
   unwind_protect
     page_screen_output (false);
@@ -156,7 +156,7 @@
     warning ("off", "all");
     warning (orig_wstate);
     warning (orig_wquiet.state, "quiet");
-    __mfile_encoding__ (orig_mfile_encoding);
+    mfile_encoding (orig_mfile_encoding);
     page_screen_output (pso);
   end_unwind_protect
 
--- a/test/file-encoding/file-encoding.tst	Wed May 03 22:52:33 2023 -0400
+++ b/test/file-encoding/file-encoding.tst	Thu May 04 18:06:08 2023 +0200
@@ -123,14 +123,14 @@
 %! end_unwind_protect
 
 ## oruntests with file in different folder (not in load path) with
-## "__mfile_encoding__"
+## "mfile_encoding"
 %!test <*62780>
-%! old_mfile_encoding = __mfile_encoding__ ("windows-1251");
+%! old_mfile_encoding = mfile_encoding ("windows-1251");
 %! unwind_protect
 %!   ## use "evalc" to suppress output to the log
 %!   evalc ('oruntests ("CP1251");');
 %! unwind_protect_cleanup
-%!   __mfile_encoding__ (old_mfile_encoding);
+%!   mfile_encoding (old_mfile_encoding);
 %! end_unwind_protect
 
 ## oruntests with file in different folder with .oct-config file (in load path)