📄 cmd.c
字号:
joe_snprintf_0(bf,sizeof(bf),LOCKMSG2); if (mkqw(bw->parent, sz(bf), steal_lock, NULL, b, NULL)) { uquery(bw); if (!b->locked) return 0; } else return 0; } else { /* Remember to unlock it */ b->locked = 1; } } return 1;}/* Called when we are about to modify a buffer *//* Returns 0 if we're not allowed to modify buffer */#define CHECK_INTERVAL 15int nomodcheck;int modify_logic(BW *bw,B *b){ if (last_time > b->check_time + CHECK_INTERVAL) { b->check_time = last_time; if (!nomodcheck && !b->gave_notice && check_mod(b)) { file_changed(bw,0,b,NULL); return 0; } } if (b != bw->b) { if (!b->didfirst) { /* This happens when we try to block move from a window which is not on the screen */ if (bw->o.mfirst) { msgnw(bw->parent,joe_gettext(_("Modify other window first for macro"))); return 0; } b->didfirst = 1; if (bw->o.mfirst) exmacro(bw->o.mfirst,1); } if (b->rdonly) { msgnw(bw->parent,joe_gettext(_("Other buffer is read only"))); if (joe_beep) ttputc(7); return 0; } else if (!b->changed && !b->locked) { if (!try_lock(bw,b)) return 0; } } else { if (!b->didfirst) { b->didfirst = 1; if (bw->o.mfirst) exmacro(bw->o.mfirst,1); } if (b->rdonly) { msgnw(bw->parent,joe_gettext(_("Read only"))); if (joe_beep) ttputc(7); return 0; } else if (!b->changed && !b->locked) { if (!try_lock(bw,b)) return 0; } } return 1;}/* Execute a command n with key k */int execmd(CMD *cmd, int k){ BW *bw = (BW *) maint->curwin->object; int ret = -1; /* Warning: bw is a BW * only if maint->curwin->watom->what & (TYPETW|TYPEPW) */ /* Send data to shell window: this is broken ^K ^H (help) sends its ^H to shell */ if ((maint->curwin->watom->what & TYPETW) && bw->b->pid && piseof(bw->cursor) && (k==3 || k==9 || k==13 || k==8 || k==127 || k==4 || (cmd->func==utype && k>=32 && k<256))) { unsigned char c = k; joe_write(bw->b->out, &c, 1); return 0; } if (cmd->m) return exmacro(cmd->m, 0); /* We don't execute if we have to fix the column position first * (i.e., left arrow when cursor is in middle of nowhere) */ if (cmd->flag & ECHKXCOL) { if (bw->o.hex) bw->cursor->xcol = piscol(bw->cursor); else if (bw->cursor->xcol != piscol(bw->cursor)) goto skip; } /* Don't execute command if we're in wrong type of window */ if (!(cmd->flag & maint->curwin->watom->what)) goto skip; /* Complete selection for block commands */ if ((cmd->flag & EBLOCK) && nowmarking) utoggle_marking(maint->curwin->object); /* We are about to modify the file */ if ((maint->curwin->watom->what & TYPETW) && (cmd->flag & EMOD)) { if (!modify_logic(bw,bw->b)) goto skip; } /* Execute command */ ret = cmd->func(maint->curwin->object, k); if (smode) --smode; /* Don't update anything if we're going to leave */ if (leave) return 0; /* cmd->func could have changed bw on us */ /* This is bad: maint->curwin might not be the same window */ /* Safer would be to attach a pointer to curwin- if curwin gets clobbered, so does pointer. */ bw = (BW *) maint->curwin->object; /* Maintain position history */ /* If command was not a positioning command */ if (!(cmd->flag & EPOS) && (maint->curwin->watom->what & (TYPETW | TYPEPW))) afterpos(); /* If command was not a movement */ if (!(cmd->flag & (EMOVE | EPOS)) && (maint->curwin->watom->what & (TYPETW | TYPEPW))) aftermove(maint->curwin, bw->cursor); if (cmd->flag & EKILL) justkilled = 1; else justkilled = 0; skip: /* Make dislayed cursor column equal the actual cursor column * for commands which arn't simple vertical movements */ if (cmd->flag & EFIXXCOL) bw->cursor->xcol = piscol(bw->cursor); /* Recenter cursor to middle of screen */ if (cmd->flag & EMID) { int omid = mid; mid = 1; dofollows(); mid = omid; } if (joe_beep && ret) ttputc(7); return ret;}void do_auto_scroll(){ static CMD *scrup = 0; static CMD *scrdn = 0; static CMD *drag = 0; if (!scrup) { scrup = findcmd(USTR "upslide"); scrdn = findcmd(USTR "dnslide"); drag = findcmd(USTR "defmdrag"); } if (auto_scroll > 0) execmd(scrdn,0); else if (auto_scroll < 0) execmd(scrup,0); execmd(drag,0); reset_trig_time();}/* Return command table index for given command name */HASH *cmdhash = NULL;static void izcmds(void){ int x; cmdhash = htmk(256); for (x = 0; x != sizeof(cmds) / sizeof(CMD); ++x) htadd(cmdhash, cmds[x].name, cmds + x);}CMD *findcmd(unsigned char *s){ if (!cmdhash) izcmds(); return (CMD *) htfind(cmdhash, s);}void addcmd(unsigned char *s, MACRO *m){ CMD *cmd = (CMD *) joe_malloc(sizeof(CMD)); if (!cmdhash) izcmds(); cmd->name = zdup(s); cmd->flag = 0; cmd->func = NULL; cmd->m = m; cmd->arg = 1; cmd->negarg = NULL; htadd(cmdhash, cmd->name, cmd);}static unsigned char **getcmds(void){ unsigned char **s = vaensure(NULL, sizeof(cmds) / sizeof(CMD)); int x; HENTRY *e; for (x = 0; x != cmdhash->len; ++x) for (e = cmdhash->tab[x]; e; e = e->next) s = vaadd(s, vsncpy(NULL, 0, sz(e->name))); vasort(s, aLen(s)); return s;}/* Command line */unsigned char **scmds = NULL; /* Array of command names */static int cmdcmplt(BW *bw){ if (!scmds) scmds = getcmds(); return simple_cmplt(bw,scmds);}static int docmd(BW *bw, unsigned char *s, void *object, int *notify){ MACRO *mac; int ret = -1; mac = mparse(NULL, s, &ret); if (ret < 0) { msgnw(bw->parent,joe_gettext(_("No such command"))); } else { ret = exmacro(mac, 1); rmmacro(mac); }#ifdef junk CMD *cmd = findcmd(s); vsrm(s); /* allocated in pw.c::rtnpw() */ if (!cmd) msgnw(bw->parent,joe_gettext(_("No such command"))); else { mac = mkmacro(-1, 0, 0, cmd); ret = exmacro(mac, 1); rmmacro(mac); }#endif if (notify) *notify = 1; return ret;}B *cmdhist = NULL;int uexecmd(BW *bw){ if (wmkpw(bw->parent, joe_gettext(USTR _("Command: ")), &cmdhist, docmd, USTR "cmd", NULL, cmdcmplt, NULL, NULL, locale_map, 0)) { return 0; } else { return -1; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -