lynx-dev
[Top][All Lists]
Advanced

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

lynx-dev [PATCH 2.8.3.dev10] Key binding in lynx


From: Ilya Zakharevich
Subject: lynx-dev [PATCH 2.8.3.dev10] Key binding in lynx
Date: Wed, 10 Nov 1999 01:31:23 -0500 (EST)

The following patch allows arbitrary key bindings in lynx.  The next
step is (of course!) how to merge different ways to bind keys into one
command.

I have this

setkey "\200s" LAC:LEFT_LINK/BACKW     # C-left
setkey "\200t" LAC:RIGHT_LINK/FORWW    # C-right

in my .lynx-keymaps file, and C-left/C-right move by word in editing
modes, and move to left/right link in "principal" mode.

[Patch is agains dev10, but I do not remember any obviously conflicting patch.]

Enjoy,
Ilya

--- ./LYKeymap.h-pre    Wed Jul 14 11:25:26 1999
+++ ./LYKeymap.h        Wed Nov 10 01:06:44 1999
@@ -10,6 +10,7 @@ extern char *key_for_func PARAMS((int fu
 extern int LYReverseKeymap PARAMS((int key_name));
 extern int lookup_keymap PARAMS((int code));
 extern int lacname_to_lac PARAMS((CONST char *func));
+extern int lecname_to_lec PARAMS((CONST char *func));
 extern int lkcstring_to_lkc PARAMS((CONST char *src));
 extern int remap PARAMS((char *key, char *func));
 extern void print_keymap PARAMS((char **newfile));
@@ -42,10 +43,13 @@ extern LYKeymap_t key_override[];
 #endif
 
 /* * *  LynxKeyCodes  * * */
+#define LKC_ISLAC2     0x8000  /* flag: contains 2 lynxactioncodes */
 #define LKC_MOD1       0x4000  /* a modifier bit - currently for ^x-map */
 #define LKC_MOD2       0x2000  /* another one - currently for esc-map */
 #define LKC_MOD3       0x1000  /* another one - currently for double-map */
 #define LKC_ISLAC      0x0800  /* flag: lynxkeycode already lynxactioncode */
+
+/* Used to distinguish internal Lynx keycodes of (say) extended ncurses once. 
*/
 #define LKC_ISLKC      0x0400  /* flag: already lynxkeycode (not native) */
                     /* 0x0400  is MOUSE_KEYSYM for slang in LYStrings.c */
 #define LKC_MASK       0x07FF  /* mask for lynxkeycode proper */
@@ -53,10 +57,18 @@ extern LYKeymap_t key_override[];
 #define LKC_DONE       0x07FE  /* special value - operation done, not-a-key */
 
 /* * *  LynxActionCodes  * * */
-#define LAC_MASK       0x00FF  /* mask for lynxactioncode - must cover all
+#define LAC_SHIFT      8       /* shift for lynxactioncode - must not
+                                  overwrite any assigned LYK_* values */
+#define LAC_MASK       ((1<<LAC_SHIFT)-1)
+                               /* mask for lynxactioncode - must cover all
                                   assigned LYK_* values */
 
 
+/*  Substitute a single actioncode given a double one */
+#define LKC2_TO_LKC(c,n)   (((c) == -1 || !((c) & LKC_ISLAC2)) ? (c) : \
+                           ((n) == 1) ? (((c) & LAC_MASK) | LKC_ISLAC) : \
+                           (((((c)&~LKC_ISLAC2)>>LAC_SHIFT) & LAC_MASK) | 
LKC_ISLAC2))
+
 /*  Convert lynxkeycode to lynxactioncode.  Modifiers are dropped.  */
 #define LKC_TO_LAC(ktab,c) (((c) == -1) ? ktab[0] : \
                            ((c) & LKC_ISLAC) ? ((c) & LAC_MASK) : \
@@ -65,6 +77,9 @@ extern LYKeymap_t key_override[];
 
 /*  Mask lynxactioncode as a lynxkeycode.  */
 #define LAC_TO_LKC0(a) ((a)|LKC_ISLAC)
+
+/*  Mask 2 lynxactioncode as a lynxkeycode.  */
+#define LAC2_TO_LKC0(a,b) ((a)|((b)<<LAC_SHIFT)|LKC_ISLAC2)
 
 /*  Convert lynxactioncode to a lynxkeycode, attempting reverse mapping.  */
 #define LAC_TO_LKC(a) 
((LYReverseKeymap(a)>=0)?LYReverseKeymap(a):LAC_TO_LKC0(a))
--- ./LYEditmap.c-pre   Thu Aug 26 06:31:18 1999
+++ ./LYEditmap.c       Wed Nov 10 01:06:34 1999
@@ -981,7 +981,9 @@ PUBLIC int EditBinding ARGS1(
      *  If we have more than one modifier bits, the first currently
      *  wins. - kw
      */
-    if (xlkc & LKC_MOD1) {
+    if (xlkc & LKC_ISLAC2) {
+       return c;
+    } else if (xlkc & LKC_MOD1) {
        xleac = LKC_TO_LEC_M1(c);
     } else if (xlkc & LKC_MOD2) {
        xleac = LKC_TO_LEC_M2(c);
--- ./LYStrings.c-pre   Wed Oct 20 03:20:52 1999
+++ ./LYStrings.c       Wed Nov 10 00:58:02 1999
@@ -910,6 +910,22 @@ PUBLIC int map_string_to_keysym ARGS2(CO
     *keysym = -1;
 
     if (strncasecomp(str, "LAC:", 4) == 0) {
+       char *other = strchr(str+4, '/');
+
+       if (other) {
+          int othersym = lecname_to_lec(other + 1);
+          char buf[BUFSIZ];
+
+          if (othersym > 0 && other - str - 4 < BUFSIZ ) {
+               strncpy(buf, str + 4, other - str - 4);
+               buf[other - str - 4] = '\0';
+               *keysym = lacname_to_lac(buf);
+               if (*keysym >= 0) {
+                   *keysym = LAC2_TO_LKC0(*keysym, othersym);
+                   return (*keysym);
+               }
+          }
+       }
        *keysym = lacname_to_lac(str + 4);
        if (*keysym >= 0) {
            *keysym = LAC_TO_LKC0(*keysym);
@@ -1420,6 +1436,13 @@ re_read:
        }
     }
 #endif /* !USE_SLANG || VMS */
+
+    /* Extract a single code if two are merged: */
+    if (c & LKC_ISLAC2)
+       if (code == FOR_INPUT || code == FOR_PROMPT)
+           return LKC2_TO_LKC(c, 2);
+       else
+           c = LKC2_TO_LKC(c, 1);
 
 #ifdef USE_GETCHAR
     if (c == EOF && errno == EINTR)    /* Ctrl-Z causes EINTR in getchar() */
--- ./LYKeymap.c-pre    Mon Sep 13 21:07:16 1999
+++ ./LYKeymap.c        Wed Nov 10 00:26:40 1999
@@ -777,6 +777,66 @@ PRIVATE CONST char *funckey[] = {
   "mouse pseudo key",          /* normally not mapped to keymap[] action */
 };
 
+
+struct emap {
+       CONST char *name;
+       CONST int   code;
+       CONST char *descr;
+};
+
+PRIVATE struct emap ekmap[] = {
+  {"NOP",      LYE_NOP,        "Do Nothing"},
+  {"CHAR",     LYE_CHAR,       "Insert printable char"},
+  {"ENTER",    LYE_ENTER,      "Input complete, return char/lynxkeycode"},
+  {"TAB",      LYE_TAB,        "Input complete, return TAB"},
+  {"ABORT",    LYE_ABORT,      "Input cancelled"},
+
+  {"FORM_PASS",        LYE_FORM_PASS,  "In fields: input complete, or Do 
Nothing"},
+
+  {"DELN",     LYE_DELN,       "Delete next/curr char"},
+  {"DELC",     LYE_DELC,       "Obsolete (DELC case was equiv to DELN)"},
+  {"DELP",     LYE_DELP,       "Delete prev      char"},
+  {"DELNW",    LYE_DELNW,      "Delete next word"},
+  {"DELPW",    LYE_DELPW,      "Delete prev word"},
+
+  {"ERASE",    LYE_ERASE,      "Erase the line"},
+
+  {"BOL",      LYE_BOL,        "Go to begin of line"},
+  {"EOL",      LYE_EOL,        "Go to end   of line"},
+  {"FORW",     LYE_FORW,       "Cursor forwards"},
+  {"BACK",     LYE_BACK,       "Cursor backwards"},
+  {"FORWW",    LYE_FORWW,      "Word forward"},
+  {"BACKW",    LYE_BACKW,      "Word back"},
+
+  {"LOWER",    LYE_LOWER,      "Lower case the line"},
+  {"UPPER",    LYE_UPPER,      "Upper case the line"},
+
+  {"LKCMD",    LYE_LKCMD,      "Invoke command prompt"},
+
+  {"AIX",      LYE_AIX,        "Hex 97"},
+
+  {"DELBL",    LYE_DELBL,      "Delete back to BOL"},
+  {"DELEL",    LYE_DELEL,      "Delete thru EOL"},
+
+  {"SWMAP",    LYE_SWMAP,      "Switch input keymap"},
+
+  {"TPOS",     LYE_TPOS,       "Transpose characters"},
+
+  {"SETM1",    LYE_SETM1,      "Set modifier 1 flag"},
+  {"SETM2",    LYE_SETM2,      "Set modifier 2 flag"},
+  {"UNMOD",    LYE_UNMOD,      "Fall back to no-modifier command"},
+
+  {"C1CHAR",   LYE_C1CHAR,     "Insert C1 char if printable"},
+
+  {"SETMARK",  LYE_SETMARK,    "emacs-like set-mark-command"},
+  {"XPMARK",   LYE_XPMARK,     "emacs-like exchange-point-and-mark"},
+  {"KILLREG",  LYE_KILLREG,    "emacs-like kill-region"},
+  {"YANK",     LYE_YANK,       "emacs-like yank"}
+#if defined(WIN_EX)
+, {"PASTE",    LYE_PASTE,      "ClipBoard to Lynx"}
+#endif
+};
+
 PRIVATE char *pretty ARGS1 (int, c)
 {
        static char buf[30];
@@ -861,6 +921,27 @@ PUBLIC int lacname_to_lac ARGS1(
        for (i = 0, mp = revmap; (*mp).name != NULL; mp++, i++) {
                if (strcmp((*mp).name, func) == 0) {
                        return i;
+               }
+       }
+       return (-1);
+}
+
+/*
+ *  Return editactioncode whose name is the string func.
+ *  func must be present in the ekmap table.
+ *  returns -1 if not found. - kw
+ */
+PUBLIC int lecname_to_lec ARGS1(
+       CONST char *,   func)
+{
+       int i;
+       struct emap *mp;
+
+       if (func == NULL || *func == '\0')
+              return (-1);
+       for (i = 0, mp = ekmap; (*mp).name != NULL; mp++, i++) {
+               if (strcmp((*mp).name, func) == 0) {
+                       return (*mp).code;
                }
        }
        return (-1);

reply via email to

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