teditor  1.8.0@@fee5e94
Terminal based editor written in C++
Namespaces | Functions
grep/ops.cpp File Reference
#include "core/editor.h"
#include "core/command.h"
#include "core/isearch.h"
#include "core/option.h"
#include "core/utils.h"

Namespaces

 teditor
 
 teditor::grep
 
 teditor::grep::ops
 

Functions

Buffer & teditor::grep::ops::getGrepBuff (Editor &ed)
 
 teditor::grep::ops::DEF_CMD (Grep, "grep", "grep_ops", DEF_OP() { auto cmd=ed.prompt("Run grep (like this): ", nullptr, nullptr, Option::get("grepCmd").getStr());if(cmd.empty()) { CMBAR_MSG(ed, "grep: nothing to run!\n");return;} CMBAR_MSG(ed, "grep cmd = %s\n", cmd.c_str());auto pwd=ed.getBuff().pwd();if(cmd.back()=='.') { cmd.pop_back();cmd+=pwd;} auto res=check_output(cmd);if(res.status !=0) { CMBAR_MSG(ed, "grep failed. Exit status = %d\n", res.status);MESSAGE(ed, "cmd = %s\nerr = %s\n", cmd.c_str(), res.error.c_str());return;} auto &buf=getGrepBuff(ed);buf.clear();buf.insert("Grep\nCommand: "+cmd+"\npwd: "+pwd+"\n\n");buf.insert(res.output);buf.begin();ed.switchToBuff("*grep");})
 
 teditor::grep::ops::DEF_CMD (GrepFindFile, "grep-find-file", "grep_ops", DEF_OP() { auto &buf=getGrepBuff(ed);const auto &cu=buf.getPoint();if(cu.y< 4) { CMBAR_MSG(ed, "grep: Point not on files!\n");return;} const auto &line=buf.at(cu.y).get();auto fileEnd=line.find_first_of(':');if(fileEnd==std::string::npos) { CMBAR_MSG(ed, "grep: bad line!\n");return;} auto lineEnd=line.find_first_of(':', fileEnd+1);if(lineEnd==std::string::npos) { CMBAR_MSG(ed, "grep: bad line!\n");return;} auto file=line.substr(0, fileEnd);auto lineNum=str2num(line.substr(fileEnd+1, lineEnd=fileEnd)) - 1;if(file[0] !='/') { auto pwd=buf.at(2).get().substr(5);if(pwd==".") pwd=buf.pwd();file=pwd+'/'+file;} ed.load(file, lineNum);})