Lines 67-73
__FBSDID("$FreeBSD$");
Link Here
|
67 |
History *hist; /* history cookie */ |
67 |
History *hist; /* history cookie */ |
68 |
EditLine *el; /* editline cookie */ |
68 |
EditLine *el; /* editline cookie */ |
69 |
int displayhist; |
69 |
int displayhist; |
|
|
70 |
int histedit_init; |
70 |
static FILE *el_in, *el_out, *el_err; |
71 |
static FILE *el_in, *el_out, *el_err; |
|
|
72 |
static int e1v2; |
71 |
|
73 |
|
72 |
static char *fc_replace(const char *, char *, char *); |
74 |
static char *fc_replace(const char *, char *, char *); |
73 |
static int not_fcnumber(const char *); |
75 |
static int not_fcnumber(const char *); |
Lines 76-87
static int str_to_event(const char *, int);
Link Here
|
76 |
/* |
78 |
/* |
77 |
* Set history and editing status. Called whenever the status may |
79 |
* Set history and editing status. Called whenever the status may |
78 |
* have changed (figures out what to do). |
80 |
* have changed (figures out what to do). |
|
|
81 |
* If force is set then an editline reinit is issued even if the actual edit |
82 |
* mode hasn't changed - necessary after the locale has changed because |
83 |
* editline bases it's decision what is reported or not upon isprint(3) |
79 |
*/ |
84 |
*/ |
80 |
void |
85 |
void |
81 |
histedit(void) |
86 |
histedit(int force) |
82 |
{ |
87 |
{ |
|
|
88 |
int nedstate; |
83 |
|
89 |
|
84 |
#define editing (Eflag || Vflag) |
90 |
if (! histedit_init) |
|
|
91 |
return; |
92 |
|
93 |
histedit_init = 2; |
94 |
/* options.c ensures these are mutual exclusive */ |
95 |
nedstate = (Eflag ? 1 : 0) | (Vflag ? 2 : 0); |
85 |
|
96 |
|
86 |
if (iflag) { |
97 |
if (iflag) { |
87 |
if (!hist) { |
98 |
if (!hist) { |
Lines 97-103
histedit(void)
Link Here
|
97 |
else |
108 |
else |
98 |
out2fmt_flush("sh: can't initialize history\n"); |
109 |
out2fmt_flush("sh: can't initialize history\n"); |
99 |
} |
110 |
} |
100 |
if (editing && !el && isatty(0)) { /* && isatty(2) ??? */ |
111 |
if (nedstate && ! el && isatty(0)) { /* && isatty(2) ??? */ |
101 |
/* |
112 |
/* |
102 |
* turn editing on |
113 |
* turn editing on |
103 |
*/ |
114 |
*/ |
Lines 130-146
bad:
Link Here
|
130 |
out2fmt_flush("sh: can't initialize editing\n"); |
141 |
out2fmt_flush("sh: can't initialize editing\n"); |
131 |
} |
142 |
} |
132 |
INTON; |
143 |
INTON; |
133 |
} else if (!editing && el) { |
144 |
} else if (! nedstate && el) { |
134 |
INTOFF; |
145 |
INTOFF; |
135 |
el_end(el); |
146 |
el_end(el); |
136 |
el = NULL; |
147 |
el = NULL; |
137 |
INTON; |
148 |
INTON; |
138 |
} |
149 |
} |
139 |
if (el) { |
150 |
if (el && (nedstate != e1v2 || force)) { |
140 |
if (Vflag) |
151 |
el_set(el, EL_EDITOR, (nedstate & 1) ? "emacs" : "vi"); |
141 |
el_set(el, EL_EDITOR, "vi"); |
|
|
142 |
else if (Eflag) |
143 |
el_set(el, EL_EDITOR, "emacs"); |
144 |
el_set(el, EL_BIND, "^I", "sh-complete", NULL); |
152 |
el_set(el, EL_BIND, "^I", "sh-complete", NULL); |
145 |
el_source(el, NULL); |
153 |
el_source(el, NULL); |
146 |
} |
154 |
} |
Lines 155-161
bad:
Link Here
|
155 |
hist = NULL; |
163 |
hist = NULL; |
156 |
} |
164 |
} |
157 |
INTON; |
165 |
INTON; |
|
|
166 |
nedstate = 0; |
158 |
} |
167 |
} |
|
|
168 |
|
169 |
e1v2 = nedstate; |
159 |
} |
170 |
} |
160 |
|
171 |
|
161 |
|
172 |
|