1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486 |
- /* command.c, Ait, BSD 3-Clause, Kevin Bloom, 2023-2024,
- Derived from: Atto January 2017
- Derived from: AnthonyEditor January 93
- */
- #include "header.h"
- #include "termbox.h"
- #include "util.h"
- void quit() { done = 1; }
- void up()
- {
- curbp->b_point = lncolumn(curbp, upup(curbp, curwp, curbp->b_point),curbp->b_pcol - curwp->w_left);
- }
- void down()
- {
- curbp->b_point = lncolumn(curbp, dndn(curbp, curwp, curbp->b_point),curbp->b_pcol - curwp->w_left);
- }
- void lnbegin()
- {
- char_t *p;
- if(curbp->b_point == 0)
- return;
- p = ptr(curbp, curbp->b_point);
- while(*(p = ptr(curbp, curbp->b_point-1)) != '\n' && p > curbp->b_buf)
- --curbp->b_point;
- if(curbp->b_point != 0 && p == curbp->b_buf)
- --curbp->b_point;
- curbp->b_pcol = 0 + curwp->w_left;
- }
- void version() { msg(VERSION); }
- void top()
- {
- shift_pmark(TRUE, NOMARK);
- curbp->b_point = 0;
- curbp->b_pcol = 0 + curwp->w_left;
- }
- void bottom()
- {
- shift_pmark(TRUE, NOMARK);
- curbp->b_point = pos(curbp, curbp->b_ebuf);
- if (curbp->b_epage < pos(curbp, curbp->b_ebuf))
- curbp->b_reframe = 1;
- curbp->b_pcol = 0 + curwp->w_left;
- }
- void block() { curbp->b_mark = curbp->b_point; }
- void copy() { copy_cut(FALSE, TRUE, FALSE); }
- void cut() { copy_cut(TRUE, TRUE, FALSE); }
- void resize_terminal()
- {
- LINES = tb_height();
- COLS = tb_width();
- MSGLINE = LINES-1;
- one_window(curwp);
- }
- void print_to_msgline(const char *msg)
- {
- printf_tb(0, MSGLINE, TB_DEFAULT, TB_DEFAULT, msg);
- tb_set_cursor(strlen(msg), MSGLINE);
- }
- void quit_ask()
- {
- if (modified_buffers() > 0) {
- const char *msg = "Modified buffers exist; really exit (y/N) ?";
- print_to_msgline(msg);
- clrtoeol(msg, MSGLINE);
- if (!yesno(FALSE)) {
- clrtoeol("", MSGLINE);
- return;
- }
- }
- quit();
- }
- void redraw()
- {
- window_t *wp;
- for (wp=wheadp; wp != NULL; wp = wp->w_next)
- wp->w_update = TRUE;
- update_display();
- }
- void left()
- {
- int n = prev_utf8_char_size();
- if(curbp->b_point == 0)
- return;
- while (0 < curbp->b_point && n-- > 0)
- --curbp->b_point;
- }
- void right()
- {
- if(curbp->b_point == pos(curbp, curbp->b_ebuf))
- return;
- int n = utf8_size(*ptr(curbp,curbp->b_point));
- while ((curbp->b_point < pos(curbp, curbp->b_ebuf)) && n-- > 0)
- ++curbp->b_point;
- }
- /* work out number of bytes based on first byte */
- int utf8_size(char_t c)
- {
- return tb_utf8_char_length(c);
- }
- int prev_utf8_char_size()
- {
- int n;
- for (n=2;n<5;n++)
- if (-1 < curbp->b_point - n && (utf8_size(*(ptr(curbp, curbp->b_point - n))) == n))
- return n;
- return 1;
- }
- void lnend()
- {
- char_t *p;
- int cols = 0;
- lnbegin(); // reset the line so we get the right number for `cols`
- while(*(p = ptr(curbp, curbp->b_point)) != '\n' && curbp->b_ebuf > p) {
- ++curbp->b_point;
- }
- /* loop until we get to the correct column */
- while(cols > curwp->w_cols) {
- cols -= curwp->w_cols;
- }
- curbp->b_pcol = cols + curwp->w_left; // set it for column-memory
- }
- void wleft()
- {
- char_t *p;
- if ((!isspace(*(p = ptr(curbp, curbp->b_point))) || !is_symbol(*p)) && curbp->b_buf < p)
- --curbp->b_point;
- while ((isspace(*(p = ptr(curbp, curbp->b_point))) || is_symbol(*p)) && curbp->b_buf < p)
- --curbp->b_point;
- while (!isspace(*(p = ptr(curbp, curbp->b_point))) && !is_symbol(*p) && curbp->b_buf < p)
- --curbp->b_point;
- if(isspace(*(p = ptr(curbp, curbp->b_point))) || is_symbol(*p))
- ++curbp->b_point;
- }
- void wleftdelete()
- {
- currentcommand = KBD_DELETE_CHAR;
- iblock();
- wleft();
- copy_cut(TRUE, TRUE, FALSE);
- }
- void pgdown()
- {
- curbp->b_page = curbp->b_point = upup(curbp, curwp, curbp->b_epage);
- while (0 < curwp->w_top - curbp->b_row) {
- down();
- curbp->b_row--;
- }
- curbp->b_epage = pos(curbp, curbp->b_ebuf);
- curbp->b_pcol = 0 + curwp->w_left;
- }
- void pgup()
- {
- int i = curwp->w_rows;
- while (0 < --i) {
- curbp->b_page = upup(curbp, curwp, curbp->b_page);
- up();
- }
- curbp->b_pcol = 0 + curwp->w_left;
- }
- void wright()
- {
- char_t *p;
- if ((!isspace(*(p = ptr(curbp, curbp->b_point))) || !is_symbol(*p)) && p < curbp->b_ebuf)
- ++curbp->b_point;
- while ((isspace(*(p = ptr(curbp, curbp->b_point))) || is_symbol(*p)) && p < curbp->b_ebuf)
- ++curbp->b_point;
- while (!isspace(*(p = ptr(curbp, curbp->b_point))) && !is_symbol(*p) && p < curbp->b_ebuf)
- ++curbp->b_point;
- }
- void wrightdelete()
- {
- currentcommand = KBD_DELETE_CHAR;
- iblock();
- wright();
- copy_cut(TRUE, TRUE, FALSE);
- }
- void insert()
- {
- assert(curbp->b_gap <= curbp->b_egap);
- if (curbp->b_gap == curbp->b_egap && !growgap(curbp, CHUNK))
- return;
- curbp->b_point = movegap(curbp, curbp->b_point);
- /* overwrite if mid line, not EOL or EOF, CR will insert as normal */
- if ((curbp->b_flags & B_OVERWRITE) && *input != '\r' && *(ptr(curbp, curbp->b_point)) != '\n' && curbp->b_point < pos(curbp,curbp->b_ebuf) ) {
- *(ptr(curbp, curbp->b_point)) = *input;
- if (curbp->b_point < pos(curbp, curbp->b_ebuf))
- ++curbp->b_point;
- } else {
- *curbp->b_gap++ = *input == '\r' ? '\n' : *input;
- curbp->b_point = pos(curbp, curbp->b_egap);
- // force reframe if scrolled off bottom of screen and at EOF
- if (curbp->b_point == pos(curbp, curbp->b_ebuf) && curbp->b_point >= curbp->b_epage &&
- curwp->w_rows == (curwp->w_row - curwp->w_top))
- curbp->b_reframe = 1;
- }
- curbp->b_flags |= B_MODIFIED;
- undoset_flag = TRUE;
- currentcommand = KBD_INSERT;
- }
- void insert_str()
- {
- int len = strlen((const char *)input);
- assert(curbp->b_gap <= curbp->b_egap);
- undoset(1, FALSE);
- if (curbp->b_gap == curbp->b_egap && !growgap(curbp, CHUNK))
- return;
- curbp->b_point = movegap(curbp, curbp->b_point);
- /* overwrite if mid line, not EOL or EOF, CR will insert as normal */
- if ((curbp->b_flags & B_OVERWRITE) && input[0] != '\r' && *(ptr(curbp, curbp->b_point)) != '\n' && curbp->b_point < pos(curbp,curbp->b_ebuf) ) {
- *(ptr(curbp, curbp->b_point)) = *input;
- if (curbp->b_point < pos(curbp, curbp->b_ebuf))
- ++curbp->b_point;
- } else {
- for(int i = 0; i < len; i++) {
- *curbp->b_gap++ = input[i] == '\r' ? '\n' : input[i];
- // if(input[i] == '\n' || input[i] == '\r')
- // curbp->b_line++;
- }
- curbp->b_point = pos(curbp, curbp->b_egap);
- // force reframe if scrolled off bottom of screen and at EOF
- if (curbp->b_point == pos(curbp, curbp->b_ebuf) && curbp->b_point >= curbp->b_epage &&
- curwp->w_rows == (curwp->w_row - curwp->w_top))
- curbp->b_reframe = 1;
- }
- curbp->b_flags |= B_MODIFIED;
- undoset_flag = TRUE;
- }
- void insert_unicode()
- {
- int len = strlen((const char *)unicode_buf);
- assert(curbp->b_gap <= curbp->b_egap);
- undoset(INSERT, lastcommand == KBD_INSERT);
- if (curbp->b_gap == curbp->b_egap && !growgap(curbp, CHUNK))
- return;
- curbp->b_point = movegap(curbp, curbp->b_point);
- /* overwrite if mid line, not EOL or EOF, CR will insert as normal */
- for(int i = 0; i < len; i++) {
- *curbp->b_gap++ = unicode_buf[i];
- }
- curbp->b_point = pos(curbp, curbp->b_egap);
- // force reframe if scrolled off bottom of screen and at EOF
- if (curbp->b_point == pos(curbp, curbp->b_ebuf) && curbp->b_point >= curbp->b_epage &&
- curwp->w_rows == (curwp->w_row - curwp->w_top))
- curbp->b_reframe = 1;
- curbp->b_flags |= B_MODIFIED;
- undoset_flag = TRUE;
- unicode_buf[0] = '\0';
- currentcommand = KBD_INSERT;
- }
- void backsp()
- {
- undoset(3, lastcommand == KBD_DELETE_CHAR);
- if(curbp->b_point != 0 && *ptr(curbp, curbp->b_point - 1) == '\n')
- curbp->b_line--;
- curbp->b_point = movegap(curbp, curbp->b_point);
- if (curbp->b_buf < curbp->b_gap) {
- curbp->b_gap -= prev_utf8_char_size();
- curbp->b_flags |= B_MODIFIED;
- }
- curbp->b_point = pos(curbp, curbp->b_egap);
- currentcommand = KBD_DELETE_CHAR;
- }
- void delete()
- {
- undoset(2, lastcommand == KBD_DELETE_CHAR);
- curbp->b_point = movegap(curbp, curbp->b_point);
- if (curbp->b_egap < curbp->b_ebuf) {
- curbp->b_egap += utf8_size(*curbp->b_egap);
- curbp->b_point = pos(curbp, curbp->b_egap);
- curbp->b_flags |= B_MODIFIED;
- }
- currentcommand = KBD_DELETE_CHAR;
- }
- void gotoline()
- {
- int line;
- point_t p;
- if (getinput("Goto line: ", temp, STRBUF_S, F_CLEAR, FALSE)) {
- line = atoi(temp);
- p = line_to_point(line);
- if (p != -1) {
- shift_pmark(TRUE, NOMARK);
- curbp->b_point = p;
- curbp->b_pcol = 0 + curwp->w_left;
- if (curbp->b_epage < pos(curbp, curbp->b_ebuf)) curbp->b_reframe = 1;
- curwp->w_update = TRUE;
- msg("Line %d", line);
- } else {
- msg("Line %d, not found", line);
- }
- }
- clrtoeol("", MSGLINE);
- }
- void gotocolumn()
- {
- int col, remainder = 0;
- point_t opoint = curbp->b_point, end = pos(curbp, curbp->b_ebuf);
- if (getinput("Goto column: ", temp, STRBUF_S, F_CLEAR, FALSE)) {
- col = atoi(temp);
- remainder = col - curbp->b_col - 1;
- if(remainder > 0) {
- shift_pmark(TRUE, NOMARK);
- if(*ptr(curbp, curbp->b_point) == '\n') {
- msg("Column %d, not found.", col);
- return;
- }
- for(; remainder > 0; remainder--) {
- right();
- printf("%d,",remainder);
- if((*ptr(curbp, curbp->b_point) == '\n' ||
- curbp->b_point == end) &&
- remainder != 1) {
- curbp->b_point = opoint;
- msg("Column %d, not found.", col);
- return;
- }
- }
- } else if(remainder < 0) {
- shift_pmark(TRUE, NOMARK);
- remainder *= -1;
- if(curbp->b_point == 0 ||
- *ptr(curbp, curbp->b_point - 1) == '\n') {
- msg("Column %d, not found.", col);
- return;
- }
- for(; remainder > 0; remainder--) {
- left();
- if((*ptr(curbp, curbp->b_point - 1) == '\n' ||
- curbp->b_point == 0) &&
- remainder != 1) {
- curbp->b_point = opoint;
- msg("Column %d, not found.", col);
- return;
- }
- }
- }
- }
- clrtoeol("", MSGLINE);
- }
- void jumptorow()
- {
- int line = -1, j = 0, i = 0, current, lastln, pageln;
- char num[3] = { 0, 0, 0 };
- struct tb_event ev;
- char *prompt = "Jump to line reference: ";
- int start_col = strlen(prompt), match = FALSE;
- char opts[10] = {'f','j','d','k','s','l','g','h', 'a', ';'};
- char chars[curwp->w_rows][2];
- point_t point;
- char_t *p;
- char f, s;
- int count = 0, fp = 0, sp = 0;
- int w_row = curwp->w_row - curwp->w_top;
- get_line_stats(¤t, &lastln, curbp);
- pageln = current - w_row;
- point = curbp->b_page;
- p = ptr(curbp, point);
- for(int i = 0; i < curwp->w_rows && pageln <= lastln; i++) {
- f = opts[fp];
- s = opts[sp];
- chars[i][0] = f;
- chars[i][1] = s;
- printf_tb(curwp->w_left, curwp->w_top+i, TB_RED, TB_CYAN, "%c%c", f,s);
- sp++;
- count++;
- if(count > 7) {
- fp++;
- sp = 0;
- count = 0;
- }
- int c = 1;
- while(*(p = ptr(curbp, point)) != '\n' &&
- curbp->b_ebuf > p && c < curwp->w_cols) {
- ++point;
- c++;
- }
- if(*p == '\n' || pageln == lastln)
- pageln++;
- ++point;
- p = ptr(curbp, point);
- }
- display_prompt_and_response(prompt, num);
- tb_present();
- while(j < 2) {
- display_prompt_and_response(prompt, num);
- tb_present();
- if(tb_poll_event(&ev) != TB_OK) break;
- if(ev.key == TB_KEY_CTRL_G) {
- clrtoeol("", MSGLINE);
- return;
- }
- if(j < 2) {
- num[j] = ev.ch;
- tb_set_cursor(start_col, MSGLINE);
- addstr(num);
- point = curbp->b_page;
- p = ptr(curbp, point);
- if(j == 0) {
- pageln = current - w_row;
- for(int i = 0; i < curwp->w_rows && pageln <= lastln; i++) {
- if(chars[i][0] == ev.ch) {
- match = TRUE;
- if(*p != '\n')
- p = ptr(curbp, point+1);
- if(*p == '\0')
- *p = ' ';
- printf_tb(curwp->w_left, curwp->w_top+i, TB_RED, TB_CYAN, "%c", chars[i][1]);
- printf_tb(curwp->w_left+1, curwp->w_top+i, TB_DEFAULT, TB_DEFAULT, "%c", *p == '\n' ? ' ' : *p);
- } else {
- printf_tb(curwp->w_left, curwp->w_top+i, TB_DEFAULT, TB_DEFAULT, "%c", *p == '\n' ? ' ' : *p);
- if(*p != '\n')
- p = ptr(curbp, point+1);
- if(*p == '\0')
- *p = ' ';
- printf_tb(curwp->w_left+1, curwp->w_top+i, TB_DEFAULT, TB_DEFAULT, "%c", *p == '\n' ? ' ' : *p);
- }
- int c = 1;
- while(*(p = ptr(curbp, point)) != '\n' &&
- curbp->b_ebuf > p && c < curwp->w_cols) {
- ++point;
- c++;
- }
- if(*p == '\n' || pageln == lastln)
- pageln++;
- ++point;
- p = ptr(curbp, point);
- }
- }
- j++;
- }
- if(!match) {
- clrtoeol("", MSGLINE);
- return;
- }
- }
- for(; i < curwp->w_rows; i++) {
- if(chars[i][0] == num[0] && chars[i][1] == num[1]) {
- line = w_row - i;
- break;
- }
- }
- if(i == curwp->w_rows) {
- msg("Out of bounds");
- return;
- }
- shift_pmark(TRUE, NOMARK);
- if(line > 0) {
- for(; line > 0; line--) {
- up();
- }
- } else {
- for(; line < 0; line++) {
- down();
- }
- }
- clrtoeol("", MSGLINE);
- }
- void jumpword()
- {
- point_t current = curbp->b_page;
- char num[3] = { 'f', 'f', 0 };
- int j = 0, match = FALSE;
- char starting[1];
- struct tb_event ev;
- char *prompt = "Jump to word starting with: ";
- int start_col = strlen(prompt);
- char opts[10] = {'f','j','d','k','s','l','g','h', 'a', ';'};
- int diff = curbp->b_epage - curbp->b_page;
- char chars[diff][2];
- point_t point = -1;
- int begin = TRUE, is_white = FALSE, is_symb = FALSE, charlen = 0;
- char_t *p, *tp;
- char f, s;
- int count = 0, fp = 0, sp = 0, x = 0, y = 0;
- display_prompt_and_response(prompt, starting);
- tb_present();
- if(tb_poll_event(&ev) != TB_OK) return;
- if(ev.key == TB_KEY_CTRL_G) {
- clrtoeol("", MSGLINE);
- return;
- }
- starting[0] = (unsigned)ev.ch;
- for(; current < curbp->b_epage; current++) {
- p = ptr(curbp, current);
- is_white = isspace(*p);
- is_symb = is_symbol(*p);
- if(is_white || is_symb || current == 0)
- begin = TRUE;
- if(*p == (char_t)starting[0] && begin) {
- f = opts[fp];
- s = opts[sp];
- chars[current-curbp->b_page][0] = f;
- chars[current-curbp->b_page][1] = s;
- charlen++;
- printf_tb(curwp->w_left+x, curwp->w_top+y, TB_RED, TB_CYAN, "%c%c", f,s);
- sp++;
- count++;
- if(count > 7) {
- fp++;
- sp = 0;
- count = 0;
- }
- begin = FALSE;
- }
- if(!is_white && !is_symb)
- begin = FALSE;
- x++;
- if(*p == '\t')
- x += (TAB_SIZE - 2);
- if(*p < 31)
- x++;
- if(*p == '\n' || x >= curwp->w_cols) {
- x = 0;
- y++;
- }
- }
- tb_present();
- if(charlen > 1) {
- display_prompt_and_response(prompt, num);
- tb_present();
- while(j < 2) {
- display_prompt_and_response(prompt, num);
- tb_present();
- if(tb_poll_event(&ev) != TB_OK) break;
- if(ev.key == TB_KEY_CTRL_G) {
- clrtoeol("", MSGLINE);
- return;
- }
- if(j < 2) {
- num[j] = ev.ch;
- tb_set_cursor(start_col, MSGLINE);
- addstr(num);
- x = 0;
- y = 0;
- if(j == 0) {
- for(current = curbp->b_page; current < curbp->b_epage; current++) {
- p = ptr(curbp, current);
- tp = ptr(curbp, current);
- is_white = isspace(*p);
- is_symb = is_symbol(*p);
- if(is_white || is_symb || current == 0)
- begin = TRUE;
- if(*p == (char_t)starting[0] && begin) {
- point_t i = current-curbp->b_page;
- if(chars[i][0] == ev.ch) {
- match = TRUE;
- tp = ptr(curbp, current+1);
- printf_tb(curwp->w_left+x, curwp->w_top+y, TB_RED, TB_CYAN, "%c", chars[i][1]);
- printf_tb(curwp->w_left+x+1, curwp->w_top+y, TB_DEFAULT, TB_DEFAULT, "%c", *tp == '\n' ? ' ' : *tp);
- } else {
- printf_tb(curwp->w_left+x, curwp->w_top+y, TB_DEFAULT, TB_DEFAULT, "%c", *tp == '\n' ? ' ' : *tp);
- tp = ptr(curbp, current+1);
- printf_tb(curwp->w_left+x+1, curwp->w_top+y, TB_DEFAULT, TB_DEFAULT, "%c", *tp == '\n' ? ' ' : *tp);
- }
- begin = FALSE;
- }
- if(!is_white && !is_symb)
- begin = FALSE;
- x++;
- if(*p == '\t')
- x += (TAB_SIZE - 2);
- if(*p < 31)
- x++;
- if(*p == '\n' || x >= curwp->w_cols) {
- x = 0;
- y++;
- }
- }
- }
- j++;
- if(!match) {
- clrtoeol("", MSGLINE);
- return;
- }
- }
- }
- }
- for(point_t cur = 0; cur < diff; cur++) {
- if(chars[cur][0] == num[0] && chars[cur][1] == num[1]) {
- point = cur + curbp->b_page;
- break;
- }
- }
- if(point == -1) {
- msg("Out of bounds.");
- } else {
- shift_pmark(TRUE, NOMARK);
- curbp->b_point = point;
- int cols = 0;
- /* Calculate the pcol value */
- lnbegin(); // reset the line so we get the right number for `cols`
- while(curbp->b_point != point) {
- ++curbp->b_point;
- cols++;
- }
- /* loop until we get to the correct column */
- while(cols > curwp->w_cols) {
- cols -= curwp->w_cols;
- }
- curbp->b_pcol = cols + curwp->w_left; // set it for column-memory
- clrtoeol("", MSGLINE);
- }
- /* Clear out the chars array */
- for(int i = 0; i < diff; i++) {
- chars[i][0] = 0;
- chars[i][1] = 0;
- }
- /* TODO: figure out why this has to be here
- Without this printf, the chars array doesn't appear to get
- cleared entirely and you end up jumping to the wrong points.
- */
- printf("%s", chars[0]);
- }
- void get_current_path(char *cur_path)
- {
- int cutoff = 0;
- for(int i = strlen(curbp->b_fname) - 1; i > -1; i--) {
- if(curbp->b_fname[i] == '/') {
- cutoff = i;
- break;
- }
- }
- for(int i = 0; i <= cutoff; i++)
- cur_path[i] = curbp->b_fname[i];
- cur_path[cutoff+1] = '\0';
- }
- void insertfile()
- {
- char cur_path[PATH_MAX] = "\0";
- if(curbp->b_path) {
- get_current_path(cur_path);
- strcpy(temp, cur_path);
- }
- else
- strcpy(temp, editor_dir);
- if (getfilename("Insert file: ", temp, PATH_MAX))
- (void)insert_file(temp, TRUE);
- }
- void readfile()
- {
- buffer_t *bp;
- char cur_path[PATH_MAX];
- if(curbp->b_path) {
- get_current_path(cur_path);
- strcpy(temp, cur_path);
- }
- else
- strcpy(temp, editor_dir);
- int result = getfilename("Find file: ", (char*)temp, PATH_MAX);
- if (result) {
- bp = find_buffer(temp, TRUE);
- disassociate_b(curwp);
- curbp = bp;
- associate_b2w(curbp, curwp);
- if (!growgap(curbp, CHUNK))
- fatal("%s: Failed to allocate required memory.\n");
- movegap(curbp, 0);
- /* load the file if not already loaded */
- if (bp != NULL && bp->b_fname[0] == '\0') {
- if (!load_file(temp)) {
- msg("New file %s", temp);
- }
- strncpy(curbp->b_fname, temp, PATH_MAX);
- curbp->b_fname[PATH_MAX] = '\0'; /* truncate if required */
- }
- }
- }
- void savebuffer()
- {
- const char *message = "No newline at the end of file, add one (Y/n) ?";
- if(curbp->b_flags & B_MODIFIED) {
- /* move the gap to point 0 so that the ebuf is updated. */
- (void) movegap(curbp, 0);
- if(*(curbp->b_ebuf - 1) != '\n') {
- print_to_msgline(message);
- clrtoeol(message, MSGLINE);
- if (yesno(TRUE)) {
- clrtoeol("", MSGLINE);
- *curbp->b_ebuf++ = '\n';
- }
- }
- if (curbp->b_fname[0] != '\0') {
- save(curbp->b_fname);
- return;
- } else {
- writefile();
- }
- } else {
- msg("(No changes need to be saved.)");
- }
- }
- void writefile()
- {
- const char *message = "Write file: ";
- strncpy(temp, curbp->b_fname, PATH_MAX);
- if (getinput((char *)message, temp, PATH_MAX, F_NONE, FALSE))
- if (save(temp) == TRUE)
- strncpy(curbp->b_fname, temp, PATH_MAX);
- clrtoeol(message, MSGLINE);
- }
- void killbuffer()
- {
- buffer_t *kill_bp = curbp;
- buffer_t *bp;
- int bcount = count_buffers();
- const char *message = "Discard changes (y/N) ?";
- /* do nothing if only buffer left is the scratch buffer */
- if (bcount == 1 && 0 == strcmp(get_buffer_name(curbp), "*scratch*"))
- return;
- if (curbp->b_flags & B_MODIFIED) {
- print_to_msgline(message);
- clrtoeol(message, MSGLINE);
- if (!yesno(FALSE))
- return;
- }
- if (bcount == 1) {
- /* create a scratch buffer */
- bp = find_buffer("*scratch*", TRUE);
- strncpy(bp->b_bname, "*scratch*", STRBUF_S);
- bp->b_path = FALSE;
- }
- next_buffer();
- assert(kill_bp != curbp);
- delete_buffer(kill_bp);
- for(window_t *wp = wheadp; wp != NULL; wp = wp->w_next) {
- if(kill_bp == wp->w_bufp) {
- wp->w_bufp = curbp;
- }
- }
- }
- void iblock()
- {
- block();
- msg("Mark set");
- }
- void unmark()
- {
- shift_pmark(TRUE, NOMARK);
- curbp->b_mark = NOMARK;
- msg("Mark removed");
- }
- void toggle_overwrite_mode() {
- if (curbp->b_flags & B_OVERWRITE)
- curbp->b_flags &= ~B_OVERWRITE;
- else
- curbp->b_flags |= B_OVERWRITE;
- }
- void killtoeol()
- {
- if (curbp->b_point == pos(curbp, curbp->b_ebuf))
- return; /* do nothing if at end of file */
- if (*(ptr(curbp, curbp->b_point)) == 0xa) {
- delete(); /* delete CR if at start of empty line */
- } else {
- curbp->b_mark = curbp->b_point;
- lnend();
- if (curbp->b_mark != curbp->b_point) copy_cut(TRUE, TRUE, FALSE);
- }
- }
- void copy_cut(int cut, int displaymsg, int internal)
- {
- char_t *p;
- /* if no mark or point == marker, nothing doing */
- if (curbp->b_mark == NOMARK || curbp->b_point == curbp->b_mark)
- return;
- if (scrap != NULL) {
- free(scrap);
- scrap = NULL;
- }
- if(cut && !internal)
- undoset(4, FALSE);
- if (curbp->b_point < curbp->b_mark) {
- /* point above marker: move gap under point, region = marker - point */
- (void) movegap(curbp, curbp->b_point);
- p = ptr(curbp, curbp->b_point);
- nscrap = curbp->b_mark - curbp->b_point;
- if(cut && currentcommand == KBD_DELETE_CHAR)
- for(point_t pt = curbp->b_mark-1; pt > curbp->b_point; pt--) {
- if(*ptr(curbp, pt) == '\n')
- curbp->b_line--;
- }
- } else {
- /* if point below marker: move gap under marker, region = point - marker */
- (void) movegap(curbp, curbp->b_mark);
- p = ptr(curbp, curbp->b_mark);
- nscrap = curbp->b_point - curbp->b_mark;
- if (cut && currentcommand != KBD_DELETE_CHAR)
- for(point_t pt = curbp->b_mark; pt < curbp->b_point; pt++) {
- if(*ptr(curbp, pt) == '\n')
- curbp->b_line--;
- }
- }
- if ((scrap = (char_t*) malloc(nscrap)) == NULL && displaymsg) {
- msg("No more memory available.");
- } else {
- (void) memcpy(scrap, p, nscrap * sizeof (char_t));
- if (cut) {
- curbp->b_egap += nscrap; /* if cut expand gap down */
- curbp->b_point = pos(curbp, curbp->b_egap); /* set point to after region */
- curbp->b_flags |= B_MODIFIED;
- if(displaymsg)
- msg("%ld bytes cut.", nscrap);
- currentcommand = KBD_CUT;
- } else {
- if(displaymsg)
- msg("%ld bytes copied.", nscrap);
- }
- curbp->b_mark = NOMARK; /* unmark */
- }
- }
- void paste_internal(int internal)
- {
- int new_rows = 0;
- int col = curwp->w_col - curwp->w_left + 1;
- point_t opoint = curbp->b_point;
- if(curbp->b_flags & B_OVERWRITE)
- return;
- if (nscrap <= 0) {
- msg("Scrap is empty. Nothing to paste.");
- } else if (nscrap < curbp->b_egap - curbp->b_gap || growgap(curbp, nscrap)) {
- if(!internal)
- undoset(5, FALSE);
- curbp->b_point = movegap(curbp, curbp->b_point);
- memcpy(curbp->b_gap, scrap, nscrap * sizeof (char_t));
- curbp->b_gap += nscrap;
- curbp->b_point = pos(curbp, curbp->b_egap);
- curbp->b_flags |= B_MODIFIED;
- /* TODO: this assumes 1 char = 1 point (not always true) */
- col += curbp->b_point - opoint;
- for(int i = 0, cc = col; scrap[i] != '\0'; i++) {
- cc++;
- if(scrap[i] == '\n' || cc >= curwp->w_cols) {
- new_rows++;
- cc = 0;
- }
- curbp->b_pcol = cc + curwp->w_left;
- }
- if ((curbp->b_row - curwp->w_top) + new_rows >= curwp->w_rows)
- curbp->b_reframe = 1;
- }
- }
- void paste()
- {
- paste_internal(FALSE);
- }
- void clipboard()
- {
- int new_rows = 0;
- int ntemp = strlen(gtemp);
- if(curbp->b_flags & B_OVERWRITE)
- return;
- if (ntemp <= 0) {
- msg("Temp buffer is empty. Nothing to paste.");
- } else if (ntemp < curbp->b_egap - curbp->b_gap || growgap(curbp, ntemp)) {
- undoset(CLIPBOARD, FALSE);
- curbp->b_point = movegap(curbp, curbp->b_point);
- memcpy(curbp->b_gap, gtemp, ntemp * sizeof (char_t));
- curbp->b_gap += ntemp;
- curbp->b_point = pos(curbp, curbp->b_egap);
- curbp->b_flags |= B_MODIFIED;
- for(int i = 0; gtemp[i] != '\0'; i++) {
- if(gtemp[i] == '\n')
- new_rows++;
- }
- if ((curbp->b_row - curwp->w_top) + new_rows > curwp->w_rows &&
- curbp->b_point >= curbp->b_epage)
- curbp->b_reframe = 1;
- free(gtemp);
- gtemp = malloc(sizeof(char) * TEMPBUF);
- }
- }
- void showpos()
- {
- int current, lastln;
- point_t end_p = pos(curbp, curbp->b_ebuf);
- get_line_stats(¤t, &lastln, curbp);
- if (curbp->b_point == end_p) {
- msg("[EOB] Line = %d/%d Point = %d/%d", current, lastln,
- curbp->b_point, ((curbp->b_ebuf - curbp->b_buf) - (curbp->b_egap - curbp->b_gap)));
- } else {
- char c = unctrl(*(ptr(curbp, curbp->b_point)));
- msg("Char = %c 0x%x Line = %d/%d Point = %d/%d", c, *(ptr(curbp, curbp->b_point)),
- current, lastln,
- curbp->b_point, ((curbp->b_ebuf - curbp->b_buf) - (curbp->b_egap - curbp->b_gap)));
- }
- }
- /* Delete whitespace between non-whitespace */
- void delete_between()
- {
- char_t *p, other;
- struct tb_event ev;
- char *prompt = "Bracket to Zap Between: ";
- int c, is_start = FALSE;
- /* Delete everything between brackets. */
- if(universal_argument > 0) {
- if(character[0] == '\0') {
- display_prompt_and_response(prompt, character);
- tb_present();
- if(tb_poll_event(&ev) != TB_OK) return;
- if(!ev.mod)
- c = ev.ch;
- else
- c = ev.key;
- /* Ignore all control keys other than C-g and ESC*/
- if (c < 32 && c != TB_KEY_CTRL_G && c != TB_KEY_ESC)
- return;
- if(c == TB_KEY_CTRL_G || c == TB_KEY_ESC)
- return;
- else
- character[0] = c;
- display_prompt_and_response(prompt, character);
- tb_present();
- }
- if(!(other = is_bracket(character[0], TRUE, &is_start))) {
- return;
- }
- jumptochar();
- adjust_bline();
- universal_argument = 0;
- lastcommand = KBD_DELETE_CHAR;
- if(is_start) {
- curbp->b_point++;
- while (*(p = ptr(curbp, curbp->b_point)) != other && curbp->b_buf < p)
- delete();
- } else {
- while (*(p = ptr(curbp, curbp->b_point - 1)) != other && curbp->b_buf < p)
- backsp();
- }
- character[0] = '\0';
- return;
- }
- /* If in a word delete the word both directions.
- This is the same as doing a `esc f` then `esc backsp`.
- This does not delete the symbols, just the words.
- */
- if(!isspace(*ptr(curbp, curbp->b_point - 1)) &&
- !isspace(*ptr(curbp, curbp->b_point)) &&
- !isspace(*ptr(curbp, curbp->b_point + 1))) {
- wright();
- wleftdelete();
- return;
- }
- lastcommand = KBD_DELETE_CHAR;
- /* Otherwise just delete whitespace */
- while (isspace(*(p = ptr(curbp, curbp->b_point - 1))) && curbp->b_buf < p && *p != '\n')
- backsp();
- while (isspace(*(p = ptr(curbp, curbp->b_point))) && curbp->b_buf < p && *p != '\n')
- delete();
- }
- void insertnewlinebelow()
- {
- char_t newline[2];
- newline[0] = '\n';
- newline[1] = '\0';
- input = newline;
- undoset(1, lastcommand == KBD_INSERT);
- insert();
- up();
- currentcommand = KBD_INSERT;
- }
- void insertnewline()
- {
- point_t point;
- char_t *p, *space = NULL, *str;
- int spaces = 0, i;
- point = segstart(curbp, curwp, lnstart(curbp, curbp->b_point), curbp->b_point);
- while(point < pos(curbp, curbp->b_ebuf) &&
- isspace(*(p = ptr(curbp, point))) &&
- *p != '\n' &&
- curwp->w_col != 0) {
- if(spaces == 0) {
- space = p;
- }
- if(*p != '\n') {
- spaces++;
- point++;
- }
- }
- str = (char_t *) malloc(sizeof(char_t)*spaces+2);
- str[0] = '\n';
- for(i = 0; i < spaces; i++) {
- str[i+1] = *space;
- }
- str[i+1] = '\0';
- input = str;
- insert_str();
- curbp->b_pcol = spaces + curwp->w_left;
- currentcommand = KBD_INSERT;
- free(str);
- if((curwp->w_row - curwp->w_top) == curwp->w_rows-1) {
- curbp->b_reframe = TRUE;
- }
- }
- void inserttab()
- {
- input = (char_t *)"\t";
- undoset(1, FALSE);
- insert();
- }
- void inserttabasspace()
- {
- char_t spaces[TAB_SPACE_SIZE+1];
- memset(spaces, ' ', sizeof(spaces));
- spaces[TAB_SPACE_SIZE] = '\0';
- input = spaces;
- insert_str();
- }
- void suspend()
- {
- tb_shutdown();
- raise(SIGTSTP);
- }
- void transpose()
- {
- char_t *cur = ptr(curbp, curbp->b_point);
- char_t *prev = ptr(curbp, curbp->b_point-1);
- char_t replace[3];
- if(cur == curbp->b_ebuf) {
- return;
- }
- point_t mark = curbp->b_mark;
- replace[0] = *cur;
- replace[1] = *prev;
- replace[2] = '\0';
- curbp->b_point--;
- curbp->b_mark = curbp->b_point + 2;
- undoset(REPLACE, 2);
- curbp->b_mark = mark;
- curbp->b_point++;
- memcpy(ptr(curbp, curbp->b_point-1), replace, 2 * sizeof (char_t));
- curbp->b_flags |= B_MODIFIED;
- }
- /* Delete a word but don't display any messages. */
- void deleteword(int dir) {
- block();
- if(dir)
- wright();
- else
- wleft();
- copy_cut(TRUE, FALSE, TRUE);
- }
- /* Transpose words and put scrap back to how it was. */
- void transposeword()
- {
- char_t *current_scrap, *p;
- int n_scrap = nscrap, newlines = 0;
- point_t mark = curbp->b_mark, epoint, point, npoint;
- /* copy the current scrap */
- current_scrap = (char_t*) malloc(nscrap);
- (void) memcpy(current_scrap, scrap, nscrap * sizeof (char_t));
- /* Find all the key points for the undo */
- wright();
- epoint = curbp->b_point;
- wleft();
- wleft();
- curbp->b_mark = epoint;
- point = curbp->b_point;
- /* Adjust `b_line` to match the line you'll eventually
- be on. This has to happen before the undo so that the
- undo's line tracker keeps it right.
- */
- npoint = point;
- while(npoint < epoint) {
- p = ptr(curbp, npoint);
- if(*p == '\n')
- newlines++;
- npoint++;
- }
- curbp->b_line -= newlines;
- undoset(REPLACE, curbp->b_mark - point);
- /* Cut the word to the left*/
- curbp->b_mark = point;
- curbp->b_point = point;
- wright();
- copy_cut(TRUE, FALSE, TRUE);
- /* paste the left word */
- right();
- paste_internal(TRUE);
- /* cut the right word */
- curbp->b_mark = curbp->b_point;
- wright();
- copy_cut(TRUE, FALSE, TRUE);
- wleft();
- /* paste the right word */
- left();
- paste_internal(TRUE);
- /* Put it all back together */
- if (scrap != NULL) {
- free(scrap);
- scrap = NULL;
- }
- nscrap = n_scrap;
- scrap = (char_t*) malloc(nscrap);
- (void) memcpy(scrap, current_scrap, nscrap * sizeof (char_t));
- curbp->b_mark = mark;
- }
- void lowercaseword()
- {
- char_t *p, *word;
- char_t c[2];
- point_t sword, eword;
- int olast = lastcommand;
- while ((isspace(*(p = ptr(curbp, curbp->b_point))) || is_symbol(*p)) && p < curbp->b_ebuf)
- ++curbp->b_point;
- sword = curbp->b_point;
- wright();
- eword = curbp->b_point;
- word = (char_t *) malloc(sizeof(char_t)*(eword - sword));
- curbp->b_point = sword;
- lastcommand = KBD_DELETE_CHAR;
- for(int i = sword, k = 0; i < eword; i++, k++) {
- word[k] = *ptr(curbp, curbp->b_point);
- delete();
- }
- lastcommand = olast;
- for(int i = sword, k = 0; i < eword; i++, k++) {
- c[0] = tolower(word[k]);
- c[1] = '\0';
- input = c;
- undoset(INSERT, i != 0);
- insert();
- }
- free(word);
- }
- void capitalizeword()
- {
- char_t *p;
- while (isspace(*(p = ptr(curbp, curbp->b_point))) && p < curbp->b_ebuf)
- ++curbp->b_point;
- p = ptr(curbp, curbp->b_point);
- char_t c[1];
- c[0] = toupper(*p);
- input = c;
- delete();
- undoset(INSERT, FALSE);
- insert();
- if(isspace(*(p = ptr(curbp, curbp->b_point+1))) || is_symbol(*p))
- curbp->b_point++;
- else
- wright();
- }
- void uppercaseword()
- {
- char_t *p, *word;
- char_t c[2];
- point_t sword, eword;
- int olast = lastcommand;
- while ((isspace(*(p = ptr(curbp, curbp->b_point))) || is_symbol(*p)) && p < curbp->b_ebuf)
- ++curbp->b_point;
- sword = curbp->b_point;
- wright();
- eword = curbp->b_point;
- word = (char_t *) malloc(sizeof(char_t)*(eword - sword));
- curbp->b_point = sword;
- lastcommand = KBD_DELETE_CHAR;
- for(int i = sword, k = 0; i < eword; i++, k++) {
- word[k] = *ptr(curbp, curbp->b_point);
- delete();
- }
- lastcommand = olast;
- for(int i = sword, k = 0; i < eword; i++, k++) {
- c[0] = toupper(word[k]);
- c[1] = '\0';
- input = c;
- undoset(INSERT, i != 0);
- insert();
- }
- free(word);
- }
- /* type = 0, zap
- type = 1, jump
- */
- /* TODO: Throw error when putting non-char in.
- */
- void gotochar(int type, int include_char)
- {
- char_t *p;
- point_t opoint = curbp->b_point, eol;
- int c, col = 0;
- struct tb_event ev;
- char *prompt = type == 0 ? "Zap to Char: " : "Jump to Char: ";
- if(character[0] == '\0') {
- display_prompt_and_response(prompt, character);
- tb_present();
- if(tb_poll_event(&ev) != TB_OK) return;
- if(!ev.mod)
- c = ev.ch;
- else
- c = ev.key;
- /* Ignore all control keys other than C-g and ESC*/
- if (c < 32 && c != TB_KEY_CTRL_G && c != TB_KEY_ESC)
- return;
- if(c == TB_KEY_CTRL_G || c == TB_KEY_ESC)
- return;
- else
- character[0] = c;
- display_prompt_and_response(prompt, character);
- tb_present();
- }
- if(type == 0) {
- block();
- }
- if(*ptr(curbp, curbp->b_point) == character[0] || curbp->b_point == 0) {
- if(negated)
- left();
- else
- right();
- }
- while (*(p = ptr(curbp, curbp->b_point + (include_char ? 0 : (negated ? -1 : 1)))) != character[0] &&
- p < curbp->b_ebuf && curbp->b_point > 0) {
- if(negated)
- left();
- else
- right();
- }
- if(type == 0 && !negated)
- right();
- if(type == 0)
- copy_cut(TRUE, FALSE, FALSE);
- tb_set_cursor(0, MSGLINE);
- clrtoeol("", MSGLINE);
- eol = lnstart(curbp, curbp->b_point);
- for(point_t poi = curbp->b_point; poi > eol; poi -= utf8_size(*ptr(curbp,poi)))
- col++;
- curbp->b_pcol = col + curwp->w_left;
- if(p >= ptr(curbp, curbp->b_epage)) {
- curbp->b_reframe = TRUE;
- }
- if((!negated && p >= curbp->b_ebuf) || (negated && curbp->b_point <= 0)) {
- msg("No match found.");
- curbp->b_point = opoint;
- }
- negated = FALSE;
- }
- void zaptochar()
- {
- gotochar(0, universal_argument == 0);
- universal_argument = 0;
- }
- void negated_zaptochar()
- {
- negated = TRUE;
- gotochar(0, universal_argument == 0);
- universal_argument = 0;
- }
- void jumptochar()
- {
- shift_pmark(TRUE, NOMARK);
- gotochar(1, TRUE);
- }
- void negated_jumptochar()
- {
- shift_pmark(TRUE, NOMARK);
- negated = TRUE;
- gotochar(1, TRUE);
- }
- void poptomark()
- {
- if(curbp->b_mark != NOMARK)
- curbp->b_point = curbp->b_mark;
- else if(curbp->b_pmark[0] != NOMARK)
- curbp->b_point = shift_pmark(FALSE, NOMARK);
- else {
- msg("No valid mark to pop to.");
- return;
- }
- if(curbp->b_point < curbp->b_page || curbp->b_point > curbp->b_epage)
- curbp->b_reframe = TRUE;
- }
- void universal_argument_load()
- {
- universal_argument++;
- msg("C-u %d", universal_argument);
- }
- void numeric_argument_load()
- {
- numeric_argument = (numeric_argument * 10) + atoi((const char *)&input_char);
- msg("C-u %d", numeric_argument);
- }
- void back_to_indentation()
- {
- char_t *p;
- while (isspace(*(p = ptr(curbp, curbp->b_point))) && p < curbp->b_ebuf)
- ++curbp->b_point;
- }
- void negate()
- {
- negated = !negated;
- msg("C-u -");
- }
- void forward_bracket()
- {
- point_t p, eol;
- int col = 0;
- if((p = find_matching_bracket(curbp, curwp, 1, FALSE)) >= 0)
- curbp->b_point = curbp->b_mark == NOMARK ? p : p + 1;
- /* Make sure the column memory updates to the new column */
- eol = lnstart(curbp, curbp->b_point);
- for(p = curbp->b_point; p > eol; p -= utf8_size(*ptr(curbp,p)))
- col++;
- curbp->b_pcol = col + curwp->w_left;
- }
- void backward_bracket()
- {
- point_t p, eol;
- int col = 0;
- if((p = find_matching_bracket(curbp, curwp, -1, FALSE)) >= 0) {
- curbp->b_point = p;
- if(curbp->b_mark != NOMARK)
- curbp->b_mark++;
- }
- /* Make sure the column memory updates to the new column */
- eol = lnstart(curbp, curbp->b_point);
- for(p = curbp->b_point; p > eol; p -= utf8_size(*ptr(curbp,p)))
- col++;
- curbp->b_pcol = col + curwp->w_left;
- }
- void start_kbd_macro()
- {
- record_input = TRUE;
- for(int i = 0; i < record_buffer_index; i++) {
- memset(&record_buffer[i], 0, sizeof(record_buffer[i]));
- }
- record_buffer_index = 0;
- msg("Started keyboard macro...");
- }
- void end_kbd_macro()
- {
- record_input = FALSE;
- msg("Ended keyboard macro.");
- }
- void run_kbd_macro()
- {
- if(numeric_argument > 0)
- numeric_argument--;
- execute_kbd_macro = TRUE;
- }
- void open_file_from_shell()
- {
- get_popen_data(1);
- }
- void insert_from_shell()
- {
- get_popen_data(0);
- }
- void insert_control_char()
- {
- struct tb_event ev;
- char *prompt = "Insert Control Char: ";
- display_prompt_and_response(prompt, character);
- tb_present();
- if(tb_poll_event(&ev) != TB_OK) return;
- tb_set_cursor(0, MSGLINE);
- clrtoeol("", MSGLINE);
- if(ev.key > 0x1a) {
- return;
- }
- input[0] = (char)ev.key;
- input[1] = '\0';
- undoset(1, lastcommand == KBD_INSERT);
- insert();
- currentcommand = KBD_INSERT;
- ignorenotbound = TRUE;
- }
|