poke-devel
[Top][All Lists]
Advanced

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

[COMMITTED] poke: turn `pager' into a Poke setting


From: Jose E. Marchesi
Subject: [COMMITTED] poke: turn `pager' into a Poke setting
Date: Sat, 29 Jan 2022 16:59:52 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

2022-01-29  Jose E. Marchesi  <jemarch@gnu.org>

        * poke/pk-settings.pk: Add setting for `pager'.
        * poke/poke.h: Remove poke_pager_p.
        * poke/poke.c: Likewise.
        * poke/pk-cmd-set.c (pk_cmd_set_pager): Delete.
        (pk_cmd_set_init): Remove pager setting.
---
 ChangeLog           |  8 ++++++++
 poke/pk-cmd-set.c   | 52 +---------------------------------------------------
 poke/pk-repl.c      |  2 +-
 poke/pk-settings.pk | 35 ++++++++++++++++++++---------------
 poke/poke.c         |  5 -----
 poke/poke.h         |  1 -
 poke/poke.pk        |  3 +++
 7 files changed, 33 insertions(+), 73 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 3e0c3c18..c871572e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2022-01-29  Jose E. Marchesi  <jemarch@gnu.org>
 
+       * poke/pk-settings.pk: Add setting for `pager'.
+       * poke/poke.h: Remove poke_pager_p.
+       * poke/poke.c: Likewise.
+       * poke/pk-cmd-set.c (pk_cmd_set_pager): Delete.
+       (pk_cmd_set_init): Remove pager setting.
+
+2022-01-29  Jose E. Marchesi  <jemarch@gnu.org>
+
        * configure.ac (HAVE_HSERVER): Search for `tgetnum' first in
        libtermcap and then in libncurses.
 
diff --git a/poke/pk-cmd-set.c b/poke/pk-cmd-set.c
index 4b10eb7d..0eae5b21 100644
--- a/poke/pk-cmd-set.c
+++ b/poke/pk-cmd-set.c
@@ -183,55 +183,8 @@ pk_cmd_set_error_on_warning (int argc, struct pk_cmd_arg 
argv[],
   return 1;
 }
 
-static int
-pk_cmd_set_pager (int argc, struct pk_cmd_arg argv[], uint64_t uflags)
-{
-  /* set error-on-warning {yes,no} */
-
-  const char *arg;
-
-  /* Note that it is not possible to distinguish between no argument
-     and an empty unique string argument.  Therefore, argc should be
-     always 1 here, and we determine when no value was specified by
-     checking whether the passed string is empty or not.  */
-
-  if (argc != 2)
-    assert (0);
-
-  arg = PK_CMD_ARG_STR (argv[1]);
-
-  if (*arg == '\0')
-    {
-      if (poke_pager_p)
-        pk_puts ("yes\n");
-      else
-        pk_puts ("no\n");
-    }
-  else
-    {
-      if (STREQ (arg, "yes"))
-        poke_pager_p = 1;
-      else if (STREQ (arg, "no"))
-        poke_pager_p = 0;
-      else
-        {
-          pk_term_class ("error");
-          pk_puts (_("error: "));
-          pk_term_end_class ("error");
-          pk_puts (_("pager should be one of `yes' or `no'\n"));
-          return 0;
-        }
-    }
-
-  return 1;
-}
-
 extern struct pk_cmd null_cmd; /* pk-cmd.c  */
 
-const struct pk_cmd set_pager_cmd =
-  {"pager", "s?", "", 0, NULL, NULL, pk_cmd_set_pager,
-   "set pager (yes|no)", NULL};
-
 const struct pk_cmd set_error_on_warning_cmd =
   {"error-on-warning", "s?", "", 0, NULL, NULL, pk_cmd_set_error_on_warning,
    "set error-on-warning (yes|no)", NULL};
@@ -272,7 +225,7 @@ pk_cmd_set_init ()
   nsettings = pk_array_nelem (registry_settings);
 
   set_cmds = xmalloc (sizeof (struct pk_cmd *)
-                      * (pk_int_value (nsettings) + 3));
+                      * (pk_int_value (nsettings) + 2));
 
   for (i = 0; i < pk_int_value (nsettings); ++i)
     {
@@ -313,9 +266,6 @@ pk_cmd_set_init ()
   /* Add error-on-warning. */
   set_cmds[i++] = &set_error_on_warning_cmd;
 
-  /* Add set-pager.  */
-  set_cmds[i++] = &set_pager_cmd;
-
   /* NOTE: if you add more C-handled commands here like
      `error-on-warning' and `set-pager', please do not forget to
      update the xmalloc count above.  */
diff --git a/poke/pk-repl.c b/poke/pk-repl.c
index 76c9df6f..50c06095 100644
--- a/poke/pk-repl.c
+++ b/poke/pk-repl.c
@@ -383,7 +383,7 @@ pk_repl (void)
           add_history (line);
 #endif
 
-          if (poke_pager_p)
+          if (pk_var_int ("pk_pager_p"))
             pk_term_start_pager ();
           pk_cmd_exec (line);
           pk_term_stop_pager ();
diff --git a/poke/pk-settings.pk b/poke/pk-settings.pk
index 63d8ee75..4453ee42 100644
--- a/poke/pk-settings.pk
+++ b/poke/pk-settings.pk
@@ -507,6 +507,26 @@ See also \".help .doc\".",
       }
     };
 
+pk_settings.add_setting
+  :entry Poke_Setting {
+      name = "pager",
+      kind = POKE_SETTING_BOOL,
+      summary = "whether to use the terminal pager",
+      usage = ".set pager {yes,no}",
+      description = "\
+This setting determines whether the output of poke commands will
+be paged or not.  Each page will have the height of the terminal.
+
+This setting is `no' by default.",
+    getter = lambda any: { return pk_pager_p; },
+    setter = lambda (any val) int:
+      {
+        pk_pager_p = val as int<32>;
+        return 1;
+      }
+   };
+
+
 /* Create help topics for the global settings defined above.  */
 
 for (setting in pk_settings.entries)
@@ -535,21 +555,6 @@ turn warnings into errors.
 This setting is `no' by default.",
     };
 
-/* Likewise for `pager'.  */
-
-pk_help_add_topic
-  :entry Poke_HelpEntry {
-           category = "settings",
-           topic = "pager",
-           summary = "whether to use the terminal pager",
-           synopsis = ".set pager {yes,no}",
-           description = "\
-This setting determines whether the output of poke commands will
-be paged or not.  Each page will have the height of the terminal.
-
-This setting is `no' by default.",
-   };
-
 /* Dump current settings.  */
 
 fun pk_settings_dump = void:
diff --git a/poke/poke.c b/poke/poke.c
index b589729d..76ff9a69 100644
--- a/poke/poke.c
+++ b/poke/poke.c
@@ -128,11 +128,6 @@ pk_compiler poke_compiler;
 
 int poke_load_init_file = 1;
 
-/* The following global indicates whether to use the terminal
-   pager.  It defaults to 0.  */
-
-int poke_pager_p;
-
 /* Command line options management.  */
 
 enum
diff --git a/poke/poke.h b/poke/poke.h
index 8508dd68..c09bf005 100644
--- a/poke/poke.h
+++ b/poke/poke.h
@@ -31,7 +31,6 @@
 extern int poke_interactive_p;
 extern int poke_quiet_p;
 extern int poke_exit_p;
-extern int poke_pager_p;
 #if HAVE_HSERVER
 extern int poke_hserver_p;
 #endif
diff --git a/poke/poke.pk b/poke/poke.pk
index b1dc4b0d..287bba29 100644
--- a/poke/poke.pk
+++ b/poke/poke.pk
@@ -46,6 +46,9 @@ var pk_doc_viewer = "info";
 /* Whether poke was built with support for libNBD.  */
 var pk_have_libnbd_p = 0;
 
+/* Whether to user the terminal pager.  */
+var pk_pager_p = 0;
+
 /* Default exception handler.  Do not do anything here that could
    raise an exception, because it will be silently ignored :P */
 
-- 
2.11.0





reply via email to

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