Split up <enter> (ctrl+j) and <return> (ctrl+m) into different bindings so
people can map them differently.  The default behavior is unchanged as we
map them both to the same function.

URL: http://dev.mutt.org/trac/ticket/3494
---
 doc/gen-map-doc |  3 ++-
 enter.c         |  6 ------
 functions.h     | 21 ++++++++++++---------
 keymap.c        | 11 +++++++----
 main.c          |  1 +
 mutt_curses.h   | 10 ----------
 6 files changed, 22 insertions(+), 30 deletions(-)

diff --git a/doc/gen-map-doc b/doc/gen-map-doc
index e2fadac..416ae9e 100644
--- a/doc/gen-map-doc
+++ b/doc/gen-map-doc
@@ -34,7 +34,8 @@ while (<STDIN>) {
     $binding =~ s/^\\(0\d+)$/'^'.chr(64+oct($1))/e;
     $binding =~ s/^\\(0\d+)(.)/'^'.chr(64+oct($1)) ." $2"/e;
     $binding =~ s/\\t/&lt;Tab&gt;/;
-    $binding =~ s/M_ENTER_S/&lt;Return&gt;/;
+    $binding =~ s/\\r/&lt;Return&gt;/;
+    $binding =~ s/\\n/&lt;Enter&gt;/;
     $binding =~ s/NULL//;
     die "unknown key $binding" if $binding =~ /\\[^\\]|<|>/;
     die "unknown OP $op" unless $OPS{$op};
diff --git a/enter.c b/enter.c
index 377e7a1..246ba57 100644
--- a/enter.c
+++ b/enter.c
@@ -669,12 +669,6 @@ self_insert:
       /* use the raw keypress */
       ch = LastKey;
 
-#ifdef KEY_ENTER
-      /* treat ENTER the same as RETURN */
-      if (ch == KEY_ENTER)
-       ch = '\r';
-#endif
-
       /* quietly ignore all other function keys */
       if (ch & ~0xff)
        continue;
diff --git a/functions.h b/functions.h
index 7a1c5a9..23bc18a 100644
--- a/functions.h
+++ b/functions.h
@@ -22,9 +22,6 @@
  *
  * Notes:
  *
- * - If you want to bind \n or \r, use M_ENTER_S so that it will work
- * correctly under both ncurses and S-Lang
- *
  * - If you need to bind a control char, use the octal value because the \cX
  * construct does not work at this level.
  *
@@ -70,7 +67,8 @@ const struct binding_t OpGeneric[] = { /* map: generic */
   { "tag-prefix-cond", OP_TAG_PREFIX_COND,     NULL },
   { "end-cond",                OP_END_COND,            NULL },
   { "shell-escape",    OP_SHELL_ESCAPE,        "!" },
-  { "select-entry",    OP_GENERIC_SELECT_ENTRY,M_ENTER_S },
+  { "select-entry",    OP_GENERIC_SELECT_ENTRY,"\n" },
+  { "select-entry",    OP_GENERIC_SELECT_ENTRY,"\r" },
   { "search",          OP_SEARCH,              "/" },
   { "search-reverse",  OP_SEARCH_REVERSE,      "\033/" },
   { "search-opposite", OP_SEARCH_OPPOSITE,     NULL },
@@ -147,7 +145,8 @@ const struct binding_t OpMain[] = { /* map: index */
   { "show-version",            OP_VERSION,                     "V" },
   { "set-flag",                        OP_MAIN_SET_FLAG,               "w" },
   { "clear-flag",              OP_MAIN_CLEAR_FLAG,             "W" },
-  { "display-message",         OP_DISPLAY_MESSAGE,             M_ENTER_S },
+  { "display-message",         OP_DISPLAY_MESSAGE,             "\n" },
+  { "display-message",         OP_DISPLAY_MESSAGE,             "\r" },
   { "buffy-list",              OP_BUFFY_LIST,                  "." },
   { "sync-mailbox",            OP_MAIN_SYNC_FOLDER,            "$" },
   { "display-address",         OP_DISPLAY_ADDRESS,             "@" },
@@ -247,7 +246,8 @@ const struct binding_t OpPager[] = { /* map: pager */
   { "search",          OP_SEARCH,                      "/" },
   { "search-reverse",  OP_SEARCH_REVERSE,              "\033/" },
   { "search-opposite", OP_SEARCH_OPPOSITE,             NULL },
-  { "next-line",       OP_NEXT_LINE,                   M_ENTER_S },
+  { "next-line",       OP_NEXT_LINE,                   "\n" },
+  { "next-line",       OP_NEXT_LINE,                   "\r" },
   { "jump",            OP_JUMP,                        NULL },
   { "next-unread",     OP_MAIN_NEXT_UNREAD,            NULL },
   { "previous-new",    OP_MAIN_PREV_NEW,               NULL },
@@ -289,7 +289,8 @@ const struct binding_t OpAttach[] = { /* map: attachment */
   { "list-reply",      OP_LIST_REPLY,                  "L" },
   { "forward-message", OP_FORWARD_MESSAGE,             "f" },
   { "view-text",       OP_ATTACH_VIEW_TEXT,            "T" },
-  { "view-attach",     OP_VIEW_ATTACH,                 M_ENTER_S },
+  { "view-attach",     OP_VIEW_ATTACH,                 "\n" },
+  { "view-attach",     OP_VIEW_ATTACH,                 "\r" },
   { "delete-entry",    OP_DELETE,                      "d" },
   { "undelete-entry",  OP_UNDELETE,                    "u" },
   { "collapse-parts",  OP_ATTACH_COLLAPSE,             "v" },
@@ -333,7 +334,8 @@ const struct binding_t OpCompose[] = { /* map: compose */
   { "toggle-unlink",   OP_COMPOSE_TOGGLE_UNLINK,       "u" },
   { "toggle-recode",    OP_COMPOSE_TOGGLE_RECODE,      NULL },
   { "update-encoding", OP_COMPOSE_UPDATE_ENCODING,     "U" },
-  { "view-attach",     OP_VIEW_ATTACH,                 M_ENTER_S },
+  { "view-attach",     OP_VIEW_ATTACH,                 "\n" },
+  { "view-attach",     OP_VIEW_ATTACH,                 "\r" },
   { "send-message",    OP_COMPOSE_SEND_MESSAGE,        "y" },
   { "pipe-entry",      OP_PIPE,                        "|" },
 
@@ -446,7 +448,8 @@ const struct binding_t OpSmime[] = { /* map: smime */
 
 #ifdef MIXMASTER
 const struct binding_t OpMix[] = { /* map: mixmaster */
-  { "accept",          OP_MIX_USE,     M_ENTER_S },
+  { "accept",          OP_MIX_USE,     "\n" },
+  { "accept",          OP_MIX_USE,     "\r" },
   { "append",          OP_MIX_APPEND,  "a"       },
   { "insert",          OP_MIX_INSERT,  "i"       },
   { "delete",          OP_MIX_DELETE,  "d"       },
diff --git a/keymap.c b/keymap.c
index 40ea745..702304b 100644
--- a/keymap.c
+++ b/keymap.c
@@ -76,10 +76,8 @@ static struct mapping_t KeyNames[] = {
   { "<Insert>",        KEY_IC },
   { "<Home>",  KEY_HOME },
   { "<End>",   KEY_END },
-#ifdef KEY_ENTER
-  { "<Enter>", KEY_ENTER },
-#endif
-  { "<Return>",        M_ENTER_C },
+  { "<Enter>", '\n' },
+  { "<Return>",        '\r' },
   { "<Esc>",   '\033' },
   { "<Tab>",   '\t' },
   { "<Space>", ' ' },
@@ -781,6 +779,7 @@ void km_init (void)
   km_bindkey ("8", MENU_GENERIC, OP_JUMP);
   km_bindkey ("9", MENU_GENERIC, OP_JUMP);
 
+  km_bindkey ("<return>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
   km_bindkey ("<enter>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
 
   /* Miscellaneous extra bindings */
@@ -792,6 +791,7 @@ void km_init (void)
   km_bindkey ("K", MENU_MAIN, OP_PREV_ENTRY);
   km_bindkey ("x", MENU_MAIN, OP_EXIT);
 
+  km_bindkey ("<return>", MENU_MAIN, OP_DISPLAY_MESSAGE);
   km_bindkey ("<enter>", MENU_MAIN, OP_DISPLAY_MESSAGE);
 
   km_bindkey ("x", MENU_PAGER, OP_EXIT);
@@ -815,13 +815,16 @@ void km_init (void)
   km_bindkey ("8", MENU_PAGER, OP_JUMP);
   km_bindkey ("9", MENU_PAGER, OP_JUMP);
 
+  km_bindkey ("<return>", MENU_PAGER, OP_NEXT_LINE);
   km_bindkey ("<enter>", MENU_PAGER, OP_NEXT_LINE);
   
   km_bindkey ("<return>", MENU_ALIAS, OP_GENERIC_SELECT_ENTRY);
   km_bindkey ("<enter>",  MENU_ALIAS, OP_GENERIC_SELECT_ENTRY);
   km_bindkey ("<space>", MENU_ALIAS, OP_TAG);
 
+  km_bindkey ("<return>", MENU_ATTACH, OP_VIEW_ATTACH);
   km_bindkey ("<enter>", MENU_ATTACH, OP_VIEW_ATTACH);
+  km_bindkey ("<return>", MENU_COMPOSE, OP_VIEW_ATTACH);
   km_bindkey ("<enter>", MENU_COMPOSE, OP_VIEW_ATTACH);
 
   /* edit-to (default "t") hides generic tag-entry in Compose menu
diff --git a/main.c b/main.c
index 17e8bf4..5d839f2 100644
--- a/main.c
+++ b/main.c
@@ -538,6 +538,7 @@ static void start_curses (void)
   keypad (stdscr, TRUE);
   cbreak ();
   noecho ();
+  nonl ();
 #if HAVE_TYPEAHEAD
   typeahead (-1);       /* simulate smooth scrolling */
 #endif
diff --git a/mutt_curses.h b/mutt_curses.h
index 543639b..ccdff20 100644
--- a/mutt_curses.h
+++ b/mutt_curses.h
@@ -33,13 +33,6 @@
 #define KEY_DC SL_KEY_DELETE
 #define KEY_IC SL_KEY_IC
 
-/*
- * ncurses and SLang seem to send different characters when the Enter key is
- * pressed, so define some macros to properly detect the Enter key.
- */
-#define M_ENTER_C '\r'
-#define M_ENTER_S "\r"
-
 #else /* USE_SLANG_CURSES */
 
 #if HAVE_NCURSESW_NCURSES_H
@@ -52,9 +45,6 @@
 # include <curses.h>
 #endif
 
-#define M_ENTER_C '\n'
-#define M_ENTER_S "\n"
-
 #endif /* USE_SLANG_CURSES */
 
 /* AIX defines ``lines'' in <term.h>, but it's used as a var name in
-- 
2.5.2

Reply via email to