/* * Load library and get all pointers. * Parameter 'libname' provides name of DLL. * Return OK or FAIL. */ static int python_runtime_link_init(char *libname, int verbose) { int i; PYTHON_PROC *ucs_as_encoded_string = (PYTHON_PROC*)&py_PyUnicode_AsEncodedString; # if !(defined(PY_NO_RTLD_GLOBAL) && defined(PY3_NO_RTLD_GLOBAL)) && defined(UNIX) && defined(FEAT_PYTHON3) /* Can't have Python and Python3 loaded at the same time. * It cause a crash, because RTLD_GLOBAL is needed for * standard C extension libraries of one or both python versions. */ if (python3_loaded()) { if (verbose) emsg(_("E836: This Vim cannot execute :python after using :py3")); return FAIL; } # endif if (hinstPython) return OK; hinstPython = load_dll(libname); if (!hinstPython) { if (verbose) semsg(_(e_loadlib), libname); return FAIL; } for (i = 0; python_funcname_table[i].ptr; ++i) { if ((*python_funcname_table[i].ptr = symbol_from_dll(hinstPython, python_funcname_table[i].name)) == NULL) { close_dll(hinstPython); hinstPython = 0; if (verbose) semsg(_(e_loadfunc), python_funcname_table[i].name); return FAIL; } } /* Load unicode functions separately as only the ucs2 or the ucs4 functions * will be present in the library. */ *ucs_as_encoded_string = symbol_from_dll(hinstPython, "PyUnicodeUCS2_AsEncodedString"); if (*ucs_as_encoded_string == NULL) *ucs_as_encoded_string = symbol_from_dll(hinstPython, "PyUnicodeUCS4_AsEncodedString"); if (*ucs_as_encoded_string == NULL) { close_dll(hinstPython); hinstPython = 0; if (verbose) semsg(_(e_loadfunc), "PyUnicode_UCSX_*"); return FAIL; } return OK; }
/* * Initialize the text for a new sign */ static int sign_define_init_text(sign_T *sp, char_u *text) { char_u *s; char_u *endp; int cells; int len; endp = text + (int)STRLEN(text); // Remove backslashes so that it is possible to use a space. for (s = text; s + 1 < endp; ++s) if (*s == '\\') { STRMOVE(s, s + 1); --endp; } // Count cells and check for non-printable chars if (has_mbyte) { cells = 0; for (s = text; s < endp; s += (*mb_ptr2len)(s)) { if (!vim_isprintc((*mb_ptr2char)(s))) break; cells += (*mb_ptr2cells)(s); } } else { for (s = text; s < endp; ++s) if (!vim_isprintc(*s)) break; cells = (int)(s - text); } // Currently sign text must be one or two display cells if (s != endp || cells < 1 || cells > 2) { semsg(_("E239: Invalid sign text: %s"), text); return FAIL; } vim_free(sp->sn_text); // Allocate one byte more if we need to pad up // with a space. len = (int)(endp - text + ((cells == 1) ? 1 : 0)); sp->sn_text = vim_strnsave(text, len); // For single character sign text, pad with a space. if (sp->sn_text != NULL && cells == 1) STRCPY(sp->sn_text + len - 1, " "); return OK; }
/* * Place a sign at the specified file location or update a sign. */ int sign_place( int *sign_id, char_u *sign_group, char_u *sign_name, buf_T *buf, linenr_T lnum, int prio) { sign_T *sp; // Check for reserved character '*' in group name if (sign_group != NULL && (*sign_group == '*' || *sign_group == '\0')) return FAIL; for (sp = first_sign; sp != NULL; sp = sp->sn_next) if (STRCMP(sp->sn_name, sign_name) == 0) break; if (sp == NULL) { semsg(_("E155: Unknown sign: %s"), sign_name); return FAIL; } if (*sign_id == 0) *sign_id = sign_group_get_next_signid(buf, sign_group); if (lnum > 0) // ":sign place {id} line={lnum} name={name} file={fname}": // place a sign buf_addsign(buf, *sign_id, sign_group, prio, lnum, sp->sn_typenr); else // ":sign place {id} file={fname}": change sign type lnum = buf_change_sign_type(buf, *sign_id, sign_group, sp->sn_typenr); if (lnum > 0) redraw_buf_line_later(buf, lnum); else { semsg(_("E885: Not possible to change sign %s"), sign_name); return FAIL; } return OK; }
/* * List the signs matching 'name' */ static void sign_list_by_name(char_u *name) { sign_T *sp; sp = sign_find(name, NULL); if (sp != NULL) sign_list_defined(sp); else semsg(_("E155: Unknown sign: %s"), name); }
/* * ":sign define {name} ..." command */ static void sign_define_cmd(char_u *sign_name, char_u *cmdline) { char_u *arg; char_u *p = cmdline; char_u *icon = NULL; char_u *text = NULL; char_u *linehl = NULL; char_u *texthl = NULL; int failed = FALSE; // set values for a defined sign. for (;;) { arg = skipwhite(p); if (*arg == NUL) break; p = skiptowhite_esc(arg); if (STRNCMP(arg, "icon=", 5) == 0) { arg += 5; icon = vim_strnsave(arg, (int)(p - arg)); } else if (STRNCMP(arg, "text=", 5) == 0) { arg += 5; text = vim_strnsave(arg, (int)(p - arg)); } else if (STRNCMP(arg, "linehl=", 7) == 0) { arg += 7; linehl = vim_strnsave(arg, (int)(p - arg)); } else if (STRNCMP(arg, "texthl=", 7) == 0) { arg += 7; texthl = vim_strnsave(arg, (int)(p - arg)); } else { semsg(_(e_invarg2), arg); failed = TRUE; break; } } if (!failed) sign_define_by_name(sign_name, icon, linehl, text, texthl); vim_free(icon); vim_free(text); vim_free(linehl); vim_free(texthl); }
/* * Lookup a property type by name. First in "buf" and when not found in the * global types. * When not found gives an error message and returns NULL. */ static proptype_T * lookup_prop_type(char_u *name, buf_T *buf) { proptype_T *type = find_prop(name, buf); if (type == NULL) type = find_prop(name, NULL); if (type == NULL) semsg(_(e_type_not_exist), name); return type; }
/* * Free the sign specified by 'name'. */ int sign_undefine_by_name(char_u *name) { sign_T *sp_prev; sign_T *sp; sp = sign_find(name, &sp_prev); if (sp == NULL) { semsg(_("E155: Unknown sign: %s"), name); return FAIL; } sign_undefine(sp, sp_prev); return OK; }
/* * 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; }