#include <ctype.h> // for isdigit
#include <stdlib.h> // for atoi
#include "yank.h"
#include "marks.h"
#include "cmds.h"
#include "conf.h"
#include "screen.h"
#include "color.h" // for set_ucolor
#include "cmds_edit.h"
#include "history.h"
#include "hide_show.h"
#include "shift.h"
#include "interp.h"
#include "utils/extra.h"
#ifdef UNDO
#include "undo.h"
#endif
extern int cmd_multiplier;
extern struct history * commandline_history;
extern void start_visualmode(int tlrow, int tlcol, int brrow, int brcol);
char interp_line[100];
void do_normalmode(struct block * buf) {
int bs = get_bufsize(buf);
struct ent * e;
switch (buf->value) {
// Movement commands
case 'j':
case OKEY_DOWN:
currow = forw_row(1)->row;
unselect_ranges();
update(TRUE);
break;
case 'k':
case OKEY_UP:
currow = back_row(1)->row;
unselect_ranges();
update(TRUE);
break;
case 'h':
case OKEY_LEFT:
curcol = back_col(1)->col;
unselect_ranges();
update(TRUE);
break;
case 'l':
case OKEY_RIGHT:
curcol = forw_col(1)->col;
unselect_ranges();
update(TRUE);
break;
case '0':
case OKEY_HOME:
curcol = left_limit()->col;
unselect_ranges();
update(TRUE);
break;
case '$':
case OKEY_END:
curcol = right_limit()->col;
unselect_ranges();
update(TRUE);
break;
case '^':
currow = goto_top()->row;
unselect_ranges();
update(TRUE);
break;
case '#':
currow = goto_bottom()->row;
unselect_ranges();
update(TRUE);
break;
// Tick
case '\'':
if (bs != 2) break;
unselect_ranges();
e = tick(buf->pnext->value);
if (row_hidden[e->row]) {
scerror("Cell row is hidden");
break;
}
if (col_hidden[e->col]) {
scerror("Cell column is hidden");
break;
}
currow = e->row;
curcol = e->col;
update(TRUE);
break;
// CTRL j
case ctl('j'):
{
int p, c = curcol, cf = curcol;
if ( (p = is_range_selected()) != -1) {
struct srange * sr = get_range_by_pos(p);
c = sr->tlcol;
cf = sr->brcol;
}
auto_justify(c, cf, DEFWIDTH); // auto justificado de columnas
update(TRUE);
break;
}
// CTRL d
case ctl('d'): // set date format using current locate D_FMT format
{
#ifdef USELOCALE
#include <locale.h>
#include <langinfo.h>
char * loc = NULL;
char * f = NULL;
loc = setlocale(LC_TIME, "");
if (loc != NULL) {
f = nl_langinfo(D_FMT);
} else {
scerror("No locale set. Nothing changed");
}
int p, r = currow, c = curcol, rf = currow, cf = curcol;
if ( (p = is_range_selected()) != -1) {
struct srange * sr = get_range_by_pos(p);
r = sr->tlrow;
c = sr->tlcol;
rf = sr->brrow;
cf = sr->brcol;
}
if (any_locked_cells(r, c, rf, cf)) {
scerror("Locked cells encountered. Nothing changed");
return;
}
dateformat(lookat(r, c), lookat(rf, cf), f);
update(TRUE);
break;
#else
scinfo("Build made without USELOCALE enabled");
#endif
}
// CTRL f
case ctl('f'):
case OKEY_PGDOWN:
{
int n = LINES - RESROW - 1;
if (atoi(<