void farsi_fkey(cmdarg_T *cap) { int c = cap->cmdchar; if (c == K_F8) { if (p_altkeymap) { if (curwin->w_farsi & W_R_L) { p_fkmap = 0; do_cmdline_cmd((char_u *)"set norl"); MSG(""); } else { p_fkmap = 1; do_cmdline_cmd((char_u *)"set rl"); MSG(""); } curwin->w_farsi = curwin->w_farsi ^ W_R_L; } } if (c == K_F9) { if (p_altkeymap && curwin->w_p_rl) { curwin->w_farsi = curwin->w_farsi ^ W_CONV; if (curwin->w_farsi & W_CONV) { conv_to_pvim(); } else { conv_to_pstd(); } } } }
String vim_command_output(String str, Error *err) { do_cmdline_cmd("redir => v:command_output"); vim_command(str, err); do_cmdline_cmd("redir END"); if (err->set) { return (String) STRING_INIT; } return cstr_to_string((char *)get_vim_var_str(VV_COMMAND_OUTPUT)); }
int Gpm_GetEvent(Gpm_Event *e){ VimEvent event; int n = read(gpm_fd, (void*)&event, sizeof(VimEvent)); if(event.type == VIM_EVENT_TYPE_GPM) { memcpy(e, (void*)&event.event.gpm, sizeof(Gpm_Event)); return 1; }else if(event.type == VIM_EVENT_TYPE_CMD) { do_cmdline_cmd((char_u *) event.event.cmd); }else if(event.type == VIM_EVENT_TYPE_RELINE) { char* str = event.event.cmd; ml_replace(curwin->w_cursor.lnum,(char_u*)str, TRUE); changed_lines(curwin->w_cursor.lnum, 0, curwin->w_cursor.lnum, 1L); }else if(event.type == VIM_EVENT_TYPE_UPDATE){ vimtouch_lock(); update_screen(0); setcursor(); out_flush(); vimtouch_unlock(); }else if(event.type == VIM_EVENT_TYPE_SETCOL){ curwin->w_cursor.col = event.event.num; }else if(event.type == VIM_EVENT_TYPE_SCROLL){ int do_scroll = event.event.num; scroll_redraw(do_scroll > 0, do_scroll>0?do_scroll:-do_scroll); }else if(event.type == VIM_EVENT_TYPE_RESIZE){ out_flush(); shell_resized_check(); redraw_later(CLEAR); update_screen(CLEAR); out_flush(); } return 0; }
static int luaV_command(lua_State *L) { do_cmdline_cmd((char_u *) luaL_checkstring(L, 1)); update_screen(VALID); return 0; }
/* * Convert the Farsi VIM into Farsi 3342 standard. */ void conv_to_pstd(void) { char_u *ptr; int lnum, llen, i; /* * Following line contains Farsi encoded character. */ do_cmdline_cmd((char_u *)"%s/\232/\202\231/g"); for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum) { ptr = ml_get((linenr_T)lnum); llen = (int)STRLEN(ptr); for ( i = 0; i < llen; i++) { ptr[i] = toF_TyA(ptr[i]); } } /* Assume the screen has been messed up: clear it and redraw. */ redraw_later(CLEAR); MSG_ATTR(farsi_text_2, hl_attr(HLF_S)); }
int Gpm_GetEvent(Gpm_Event *e){ VimEvent event; int n = read(gpm_fd, (void*)&event, sizeof(VimEvent)); if(event.type == VIM_EVENT_TYPE_GPM) { memcpy(e, (void*)&event.event.gpm, sizeof(Gpm_Event)); return 1; }else if(event.type == VIM_EVENT_TYPE_ANDROID_SEND) { vimtouch_send_android_event(event.event.num, (char_u *) &event.event.nums[1]); return 0; }else if(event.type == VIM_EVENT_TYPE_CMD) { do_cmdline_cmd((char_u *) event.event.cmd); }else if(event.type == VIM_EVENT_TYPE_RELINE) { char* str = event.event.cmd; ml_replace(curwin->w_cursor.lnum,(char_u*)str, TRUE); changed_lines(curwin->w_cursor.lnum, 0, curwin->w_cursor.lnum, 1L); }else if(event.type == VIM_EVENT_TYPE_UPDATE){ //vimtouch_lock(); update_screen(0); setcursor(); out_flush(); //vimtouch_unlock(); }else if(event.type == VIM_EVENT_TYPE_CURSOR){ mouse_col = event.event.nums[0]; mouse_row = event.event.nums[1]; jump_to_mouse(MOUSE_DID_MOVE, NULL, 0); }else if(event.type == VIM_EVENT_TYPE_SETCOL){ curwin->w_cursor.col = event.event.num; }else if(event.type == VIM_EVENT_TYPE_SCROLL){ int do_scroll = event.event.num; scroll_redraw(do_scroll > 0, do_scroll>0?do_scroll:-do_scroll); }else if(event.type == VIM_EVENT_TYPE_RESIZE){ out_flush(); shell_resized_check(); redraw_later(CLEAR); out_flush(); }else if(event.type == VIM_EVENT_TYPE_SETTAB){ int nr = event.event.nums[0]; if (nr != tabpage_index(curtab)){ current_tab = nr; if (current_tab == 255) /* -1 in a byte gives 255 */ current_tab = -1; goto_tabpage(current_tab); update_screen(CLEAR); out_flush(); } }else if(event.type == VIM_EVENT_TYPE_HISTORY){ char buf[1024]; int i = 1; for(i = 1; i <= 10; i++){ sprintf(buf, "HISTORY:%d,%s\n",i-1,get_history_entry(HIST_CMD,i)); write(gpm_fd,buf,strlen(buf)); } } vimtouch_sync(); return 0; }
void workshop_postinit(void) { do_cmdline_cmd((char_u *)initialFileCmd); ALT_INPUT_LOCK_OFF; free(initialFileCmd); initialFileCmd = NULL; }
/// Executes an ex-mode command str /// /// @param str The command str /// @param[out] err Details of an error that may have occurred void vim_command(String str, Error *err) { // Run the command try_start(); do_cmdline_cmd((char_u *) str.data); update_screen(VALID); try_end(err); }
/// Executes an ex-command. /// On VimL error: Returns the VimL error; v:errmsg is not updated. /// /// @param command Ex-command string /// @param[out] err Error details (including actual VimL error), if any void nvim_command(String command, Error *err) { // Run the command try_start(); do_cmdline_cmd(command.data); update_screen(VALID); try_end(err); }
static void vimtouch_Exec_doCommand(JNIEnv *env, jobject clazz, jstring cmd){ if(!cmd) return; const char* str = env->GetStringUTFChars(cmd, NULL); if(!str) return; vimtouch_lock(); do_cmdline_cmd((char_u *)str); vimtouch_unlock(); env->ReleaseStringUTFChars(cmd, str); }
void vim_command(String str, Error *err) { // We still use 0-terminated strings, so we must convert. char *cmd_str = xstrndup(str.data, str.size); // Run the command try_start(); do_cmdline_cmd((char_u *)cmd_str); free(cmd_str); update_screen(VALID); try_end(err); }
/// Convert the Farsi 3342 standard into Farsi VIM. void conv_to_pvim(void) { char_u *ptr; int lnum, llen, i; for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum) { ptr = ml_get((linenr_T)lnum); llen = (int)STRLEN(ptr); for (i = 0; i < llen - 1; i++) { if (canF_Ljoin(ptr[i]) && canF_Rjoin(ptr[i + 1])) { ptr[i] = toF_leading(ptr[i]); i++; while (canF_Rjoin(ptr[i]) && i < llen) { ptr[i] = toF_Rjoin(ptr[i]); if (F_isterm(ptr[i]) || !F_isalpha(ptr[i])) { break; } i++; } if (!F_isalpha(ptr[i]) || !canF_Rjoin(ptr[i])) { ptr[i - 1] = toF_ending(ptr[i - 1]); } } else { ptr[i] = toF_TyA(ptr[i]); } } } // Following lines contains Farsi encoded character. do_cmdline_cmd((char_u *)"%s/\202\231/\232/g"); do_cmdline_cmd((char_u *)"%s/\201\231/\370\334/g"); // Assume the screen has been messed up: clear it and redraw. redraw_later(CLEAR); MSG_ATTR(farsi_text_1, hl_attr(HLF_S)); }
/// Convert the Farsi VIM into Farsi 3342 standard. static void conv_to_pstd(void) { char_u *ptr; int lnum, llen, i; // Following line contains Farsi encoded character. do_cmdline_cmd("%s/\232/\202\231/ge"); for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; lnum++) { ptr = ml_get((linenr_T)lnum); llen = (int)STRLEN(ptr); for (i = 0; i < llen; i++) { ptr[i] = toF_TyA(ptr[i]); } } // Assume the screen has been messed up: clear it and redraw. redraw_later(CLEAR); msg_attr((const char *)farsi_text_2, hl_attr(HLF_S)); }
/* * Jump to a sign. */ linenr_T sign_jump(int sign_id, char_u *sign_group, buf_T *buf) { linenr_T lnum; if ((lnum = buf_findsign(buf, sign_id, sign_group)) <= 0) { semsg(_("E157: Invalid sign ID: %d"), sign_id); return -1; } // goto a sign ... if (buf_jump_open_win(buf) != NULL) { // ... in a current window curwin->w_cursor.lnum = lnum; check_cursor_lnum(); beginline(BL_WHITE); } else { // ... not currently in a window char_u *cmd; if (buf->b_fname == NULL) { emsg(_("E934: Cannot jump to a buffer that does not have a name")); return -1; } cmd = alloc((unsigned)STRLEN(buf->b_fname) + 25); if (cmd == NULL) return -1; sprintf((char *)cmd, "e +%ld %s", (long)lnum, buf->b_fname); do_cmdline_cmd(cmd); vim_free(cmd); } # ifdef FEAT_FOLDING foldOpenCursor(); # endif return lnum; }
static void coloncmd( char *cmd, /* the command to print */ Boolean force) /* force cursor update */ { char_u *cpo_save = p_cpo; #ifdef WSDEBUG if (WSDLEVEL(WS_TRACE_COLONCMD)) wsdebug("Cmd: %s\n", cmd); #endif p_cpo = empty_option; ALT_INPUT_LOCK_ON; do_cmdline_cmd((char_u *)cmd); ALT_INPUT_LOCK_OFF; p_cpo = cpo_save; if (force) gui_update_screen(); }
/// Set up key mapping tables for the 'keymap' option. /// /// @return NULL if OK, an error message for failure. This only needs to be /// used when setting the option, not later when the value has already /// been checked. char_u* keymap_init(void) { curbuf->b_kmap_state &= ~KEYMAP_INIT; if (*curbuf->b_p_keymap == NUL) { // Stop any active keymap and clear the table. Also remove // b:keymap_name, as no keymap is active now. keymap_unload(); do_cmdline_cmd("unlet! b:keymap_name"); } else { char *buf; size_t buflen; // Source the keymap file. It will contain a ":loadkeymap" command // which will call ex_loadkeymap() below. buflen = STRLEN(curbuf->b_p_keymap) + STRLEN(p_enc) + 14; buf = xmalloc(buflen); // try finding "keymap/'keymap'_'encoding'.vim" in 'runtimepath' vim_snprintf(buf, buflen, "keymap/%s_%s.vim", curbuf->b_p_keymap, p_enc); if (source_runtime((char_u *)buf, 0) == FAIL) { // try finding "keymap/'keymap'.vim" in 'runtimepath' vim_snprintf(buf, buflen, "keymap/%s.vim", curbuf->b_p_keymap); if (source_runtime((char_u *)buf, 0) == FAIL) { xfree(buf); return (char_u *)N_("E544: Keymap file not found"); } } xfree(buf); } return NULL; }
/* * Free everything that we allocated. * Can be used to detect memory leaks, e.g., with ccmalloc. * NOTE: This is tricky! Things are freed that functions depend on. Don't be * surprised if Vim crashes... * Some things can't be freed, esp. things local to a library function. */ void free_all_mem(void) { buf_T *buf, *nextbuf; static int entered = FALSE; /* When we cause a crash here it is caught and Vim tries to exit cleanly. * Don't try freeing everything again. */ if (entered) return; entered = TRUE; block_autocmds(); /* don't want to trigger autocommands here */ /* Close all tabs and windows. Reset 'equalalways' to avoid redraws. */ p_ea = FALSE; if (first_tabpage->tp_next != NULL) do_cmdline_cmd((char_u *)"tabonly!"); if (firstwin != lastwin) do_cmdline_cmd((char_u *)"only!"); /* Free all spell info. */ spell_free_all(); /* Clear user commands (before deleting buffers). */ ex_comclear(NULL); /* Clear menus. */ do_cmdline_cmd((char_u *)"aunmenu *"); do_cmdline_cmd((char_u *)"menutranslate clear"); /* Clear mappings, abbreviations, breakpoints. */ do_cmdline_cmd((char_u *)"lmapclear"); do_cmdline_cmd((char_u *)"xmapclear"); do_cmdline_cmd((char_u *)"mapclear"); do_cmdline_cmd((char_u *)"mapclear!"); do_cmdline_cmd((char_u *)"abclear"); do_cmdline_cmd((char_u *)"breakdel *"); do_cmdline_cmd((char_u *)"profdel *"); do_cmdline_cmd((char_u *)"set keymap="); free_titles(); free_findfile(); /* Obviously named calls. */ free_all_autocmds(); clear_termcodes(); free_all_options(); free_all_marks(); alist_clear(&global_alist); free_homedir(); free_users(); free_search_patterns(); free_old_sub(); free_last_insert(); free_prev_shellcmd(); free_regexp_stuff(); free_tag_stuff(); free_cd_dir(); free_signs(); set_expr_line(NULL); diff_clear(curtab); clear_sb_text(); /* free any scrollback text */ /* Free some global vars. */ vim_free(last_cmdline); vim_free(new_last_cmdline); set_keep_msg(NULL, 0); /* Clear cmdline history. */ p_hi = 0; init_history(); { win_T *win; tabpage_T *tab; qf_free_all(NULL); /* Free all location lists */ FOR_ALL_TAB_WINDOWS(tab, win) qf_free_all(win); } /* Close all script inputs. */ close_all_scripts(); /* Destroy all windows. Must come before freeing buffers. */ win_free_all(); /* Free all buffers. Reset 'autochdir' to avoid accessing things that * were freed already. */ p_acd = FALSE; for (buf = firstbuf; buf != NULL; ) { nextbuf = buf->b_next; close_buffer(NULL, buf, DOBUF_WIPE, FALSE); if (buf_valid(buf)) buf = nextbuf; /* didn't work, try next one */ else buf = firstbuf; } free_cmdline_buf(); /* Clear registers. */ clear_registers(); ResetRedobuff(); ResetRedobuff(); /* highlight info */ free_highlight(); reset_last_sourcing(); free_tabpage(first_tabpage); first_tabpage = NULL; # ifdef UNIX /* Machine-specific free. */ mch_free_mem(); # endif /* message history */ for (;; ) if (delete_first_msg() == FAIL) break; eval_clear(); free_termoptions(); /* screenlines (can't display anything now!) */ free_screenlines(); clear_hl_tables(); vim_free(NameBuff); }