From d508a921bf352714d6ea35e07cc9a49c74f1581d Mon Sep 17 00:00:00 2001 From: Sean Bright Date: Thu, 5 May 2011 21:20:00 +0000 Subject: [PATCH] Add some new editline bindings by default, and allow for user specified configuration. I excluded the part of this patch that used the HOME environment variable since the built-in editline library goes to great lengths to disallow that. Instead only settings the EDITRC environment variable will use a user specified file. Also, the default environment variable use to determine the edit more is AST_EDITMODE instead of AST_EDITOR (although the latter is still supported). (closes issue #15929) Reported by: kkm Patches: astcli-editrc-v2.diff uploaded by kkm (license 888) 015929-astcli-editrc-trunk.240324.diff uploaded by kkm (license 888) Tested by: seanbright git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@317395 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- main/asterisk.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/main/asterisk.c b/main/asterisk.c index 01db3a036a..b3bcfe2306 100644 --- a/main/asterisk.c +++ b/main/asterisk.c @@ -2569,7 +2569,13 @@ static char *cli_complete(EditLine *editline, int ch) static int ast_el_initialize(void) { HistEvent ev; - char *editor = getenv("AST_EDITOR"); + char *editor, *editrc = getenv("EDITRC"); + + if (!(editor = getenv("AST_EDITMODE"))) { + if (!(editor = getenv("AST_EDITOR"))) { + editor = "emacs"; + } + } if (el != NULL) el_end(el); @@ -2580,7 +2586,7 @@ static int ast_el_initialize(void) el_set(el, EL_PROMPT, cli_prompt); el_set(el, EL_EDITMODE, 1); - el_set(el, EL_EDITOR, editor ? editor : "emacs"); + el_set(el, EL_EDITOR, editor); el_hist = history_init(); if (!el || !el_hist) return -1; @@ -2597,6 +2603,18 @@ static int ast_el_initialize(void) el_set(el, EL_BIND, "?", "ed-complete", NULL); /* Bind ^D to redisplay */ el_set(el, EL_BIND, "^D", "ed-redisplay", NULL); + /* Bind Delete to delete char left */ + el_set(el, EL_BIND, "\\e[3~", "ed-delete-next-char", NULL); + /* Bind Home and End to move to line start and end */ + el_set(el, EL_BIND, "\\e[1~", "ed-move-to-beg", NULL); + el_set(el, EL_BIND, "\\e[4~", "ed-move-to-end", NULL); + /* Bind C-left and C-right to move by word (not all terminals) */ + el_set(el, EL_BIND, "\\eOC", "vi-next-word", NULL); + el_set(el, EL_BIND, "\\eOD", "vi-prev-word", NULL); + + if (editrc) { + el_source(el, editrc); + } return 0; } -- 2.47.2