ratpoison-devel
[Top][All Lists]
Advanced

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

[RP] [patch] listhooks


From: Rupert Levene
Subject: [RP] [patch] listhooks
Date: Sun Jul 20 02:07:25 2003
User-agent: Mutt/1.5.3i

By overwhelming popular demand, this patch implements a command to
list the commands on a particular hook.

Index: actions.c
===================================================================
RCS file: /cvsroot/ratpoison/ratpoison/src/actions.c,v
retrieving revision 1.177
diff -u -r1.177 actions.c
--- actions.c   17 Jul 2003 05:41:41 -0000      1.177
+++ actions.c   18 Jul 2003 22:40:32 -0000
@@ -108,6 +108,7 @@
     {"gmerge",         cmd_gmerge,             arg_VOID},
     {"addhook",         cmd_addhook,            arg_STRING},
     {"remhook",         cmd_remhook,            arg_STRING},
+    {"listhooks",       cmd_listhooks,          arg_STRING},
 
     /* Commands to set default behavior. */
     {"defbargravity",          cmd_defbargravity,      arg_STRING},
@@ -3698,6 +3699,87 @@
   return NULL;
 }
 
+struct list_head *
+hook_completions (char* str)
+{
+  struct list_head *list;
+  struct rp_hook_db_entry *entry;
+
+  /* Initialize our list. */
+  list = xmalloc (sizeof (struct list_head));
+  INIT_LIST_HEAD (list);
+ 
+  for (entry = rp_hook_db; entry->name; entry++)
+    {
+      struct sbuf *hookname;
+
+      hookname = sbuf_new(0);
+      sbuf_copy (hookname, entry->name);
+      list_add_tail (&hookname->node, list);
+    }
+  
+  return list;
+}
+
+char *
+cmd_listhooks (int interactive, char *data)
+{
+  struct sbuf *buffer;
+  struct list_head *hook;
+  struct sbuf *cur;
+  char *str;
+  
+  if (data == NULL)
+    str = get_input (" Hook: ", hook_completions);
+  else
+    str = xstrdup (data);
+
+  if (str == NULL)
+    {
+      message(" listhooks: one argument required ");
+      return NULL;
+    }
+  
+  hook = hook_lookup (str);
+  if (hook == NULL)
+    {
+      marked_message_printf (0, 0, " listhooks: unknown hook \"%s\"", str);
+      return NULL;
+    }
+
+  buffer = sbuf_new(0);
+
+  if (list_empty(hook))
+    {
+      sbuf_printf(buffer, "Nothing defined for %s", str);
+    }
+  else
+    {
+      list_for_each_entry (cur, hook, node)
+       {
+         sbuf_printf_concat(buffer, "%s", sbuf_get (cur));
+         if (cur->node.next != hook)
+           sbuf_printf_concat(buffer, "\n");
+       }
+    }
+
+  /* Display it or return it. */
+  if (interactive)
+    {
+      marked_message (sbuf_get (buffer), 0, 0);
+      sbuf_free (buffer);
+      return NULL;
+    }
+  else
+    {
+      char* tmp = sbuf_get(buffer);
+      free(buffer);
+      return tmp;
+    }
+
+
+}
+
 char *
 cmd_remhook (int interactive, char *data)
 {
@@ -3718,7 +3800,7 @@
   hook = hook_lookup (token);
   if (hook == NULL)
     {
-      marked_message_printf (0, 0, " addhook: unknown hook \"%s\"", token);
+      marked_message_printf (0, 0, " remhook: unknown hook \"%s\"", token);
       free (dup);
       return NULL;
     }
@@ -3727,7 +3809,7 @@
   
   if (token == NULL)
     {
-      message (" addhook: two arguments required ");
+      message (" remhook: two arguments required ");
       free (dup);
       return NULL;
     }
Index: actions.h
===================================================================
RCS file: /cvsroot/ratpoison/ratpoison/src/actions.h,v
retrieving revision 1.63
diff -u -r1.63 actions.h
--- actions.h   17 Jul 2003 05:41:41 -0000      1.63
+++ actions.h   18 Jul 2003 22:40:32 -0000
@@ -134,6 +134,7 @@
 char *cmd_windows (int interactive, char *data);
 char *cmd_addhook (int interactive, char *data);
 char *cmd_remhook (int interactive, char *data);
+char *cmd_listhooks (int interactive, char *data);
 
 void initialize_default_keybindings (void);
 void free_keybindings ();




reply via email to

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