MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / vi_match

Function vi_match

extern/editline/src/vi.c:802–843  ·  view source on GitHub ↗

vi_match(): * Vi go to matching () {} or [] * [%] */

Source from the content-addressed store, hash-verified

800 * [%]
801 */
802protected el_action_t
803/*ARGSUSED*/
804vi_match(EditLine *el, Int c __attribute__((__unused__)))
805{
806 const Char match_chars[] = STR("()[]{}");
807 Char *cp;
808 size_t delta, i, count;
809 Char o_ch, c_ch;
810
811 *el->el_line.lastchar = '\0'; /* just in case */
812
813 i = Strcspn(el->el_line.cursor, match_chars);
814 o_ch = el->el_line.cursor[i];
815 if (o_ch == 0)
816 return CC_ERROR;
817 delta = (size_t)(Strchr(match_chars, o_ch) - match_chars);
818 c_ch = match_chars[delta ^ 1];
819 count = 1;
820 delta = 1 - (delta & 1) * 2;
821
822 for (cp = &el->el_line.cursor[i]; count; ) {
823 cp += delta;
824 if (cp < el->el_line.buffer || cp >= el->el_line.lastchar)
825 return CC_ERROR;
826 if (*cp == o_ch)
827 count++;
828 else if (*cp == c_ch)
829 count--;
830 }
831
832 el->el_line.cursor = cp;
833
834 if (el->el_chared.c_vcmd.action != NOP) {
835 /* NB posix says char under cursor should NOT be deleted
836 for -ve delta - this is different to netbsd vi. */
837 if (delta > 0)
838 el->el_line.cursor++;
839 cv_delfini(el);
840 return CC_REFRESH;
841 }
842 return CC_CURSOR;
843}
844
845/* vi_undo_line():
846 * Vi undo all changes to line

Callers

nothing calls this directly

Calls 1

cv_delfiniFunction · 0.85

Tested by

no test coverage detected