teditor  1.8.0@@fee5e94
Terminal based editor written in C++
Functions
teditor::buffer::ops Namespace Reference

Functions

 DEF_CMD (CommandUndo, "command-undo", "buffer_ops", DEF_OP() { if(!ed.getBuff().undo()) CMBAR_MSG(ed, "No further undo information\n");})
 
 DEF_CMD (CommandRedo, "command-redo", "buffer_ops", DEF_OP() { if(!ed.getBuff().redo()) CMBAR_MSG(ed, "No further redo information\n");})
 
 DEF_CMD (InsertChar, ".insert-char", "buffer_ops", DEF_OP() { auto &buf=ed.getBuff();if(buf.isRegionActive()) ed.runCmd(".backspace-char");auto c=(char) ed.getKey();buf.insert(c);})
 
 DEF_CMD (BackspaceChar, ".backspace-char", "buffer_ops", DEF_OP() { ed.getBuff().remove();})
 
 DEF_CMD (DeleteChar, ".delete-char", "buffer_ops", DEF_OP() { ed.getBuff().remove(true);})
 
 DEF_CMD (KillLine, "kill-line", "buffer_ops", DEF_OP() { auto del=ed.getBuff().killLine();ed.setClipboard(del);CMBAR_MSG(ed, "Line killed\n");})
 
void keepRemoveLines (Editor &ed, bool keep)
 
 DEF_CMD (KeepLines, "keep-lines", "buffer_ops", DEF_OP() { keepRemoveLines(ed, true);})
 
 DEF_CMD (RemoveLines, "remove-lines", "buffer_ops", DEF_OP() { keepRemoveLines(ed, false);})
 
 DEF_CMD (ShellToBuffer, "shell-to-buffer", "buffer_ops", DEF_OP() { auto &buf=ed.getBuff();if(buf.isRegionActive()) buf.remove();auto cmd=ed.prompt("Shell Command: ");if(cmd.empty()) return;MESSAGE(ed, "Shell Command: %s\n", cmd.c_str());auto res=check_output(cmd);if(res.output.empty()) return;buf.insert(res.output);MESSAGE(ed, "Exit Code: %d\nError: %s\n", res.status, res.error.c_str());})
 
 DEF_CMD (StartRegion, "start-region", "buffer_ops", DEF_OP() { auto &buf=ed.getBuff();if(!buf.isRegionActive()) { buf.startRegion();} else { buf.stopRegion();buf.startRegion();} })
 
 DEF_CMD (Cancel, "cancel", "buffer_ops", DEF_OP() { auto &buf=ed.getBuff();if(buf.isRegionActive()) buf.stopRegion();})
 
 DEF_CMD (PasteRegion, "paste-region", "buffer_ops", DEF_OP() { auto &buf=ed.getBuff();if(buf.isRegionActive()) buf.remove();auto copy=ed.clipboard();if(!copy.empty()) buf.insert(copy);})
 
 DEF_CMD (CopyRegion, "copy-region", "buffer_ops", DEF_OP() { auto &buf=ed.getBuff();if(!buf.isRegionActive()) { CMBAR_MSG(ed, "No selection to copy!\n");return;} auto cp=buf.regionAsStr();ed.setClipboard(cp);buf.stopRegion();CMBAR_MSG(ed, "Copy done\n");})
 
 DEF_CMD (CutRegion, "cut-region", "buffer_ops", DEF_OP() { auto &buf=ed.getBuff();if(!buf.isRegionActive()) { CMBAR_MSG(ed, "No selection to cut!\n");return;} auto del=buf.removeAndCopy();ed.setClipboard(del);CMBAR_MSG(ed, "Cut done\n");})
 
 DEF_CMD (DownloadBuffer, "download-to-buffer", "buffer_ops", DEF_OP() { auto &buf=ed.getBuff();if(buf.isRegionActive()) buf.remove();auto url=ed.prompt("URL: ");if(url.empty()) return;auto output=downloadUrlToString(url, Option::get("dnldProg").getStr(), Option::get("dnldProgOpts").getStr());if(output.empty()) return;buf.insert(output);})
 
 DEF_CMD (TextSearch, "search", "buffer_ops", DEF_OP() { auto &buf=ed.getBuff();auto pos=buf.getPoint();ISearch is(ed.getWindow(), Option::get("iCaseSearch").getBool());is.reset();auto ret=ed.prompt("Search: ", nullptr, &is);buf.gotoLine(!ret.empty()? is.getChoiceIdx() :pos.y, ed.getWindow().dim());})
 
 DEF_CMD (Save, "save-buffer", "buffer_ops", DEF_OP() { auto &buf=ed.getBuff();if(buf.isRO()) { CMBAR_MSG(ed, "save-buffer: Read Only Buffer!\n");return;} ed.saveBuffer(buf);})
 
 DEF_CMD (Pwd, "pwd", "buffer_ops", DEF_OP() { const auto &buf=ed.getBuff();CMBAR_MSG(ed, "Pwd: %s\n", buf.pwd().c_str());})
 
 DEF_CMD (Next, "next-buffer", "buffer_ops", DEF_OP() { ed.incrementCurrBuff();})
 
 DEF_CMD (Previous, "prev-buffer", "buffer_ops", DEF_OP() { ed.decrementCurrBuff();})
 
 DEF_CMD (KillThis, "kill-this-buffer", "buffer_ops", DEF_OP() { ed.killCurrBuff();})
 
 DEF_CMD (KillOthers, "kill-other-buffers", "buffer_ops", DEF_OP() { ed.killOtherBuffs();})
 
 DEF_CMD (Reload, "reload-buffer", "buffer_ops", DEF_OP() { auto &buf=ed.getBuff();if(!buf.isModified()||ed.promptYesNo("Buffer modified, still reload? ")) buf.reload();})
 

Function Documentation

◆ DEF_CMD() [1/23]

teditor::buffer::ops::DEF_CMD ( BackspaceChar  ,
".backspace-char"  ,
"buffer_ops"  ,
DEF_OP() { ed.getBuff().remove();}   
)

◆ DEF_CMD() [2/23]

teditor::buffer::ops::DEF_CMD ( Cancel  ,
"cancel"  ,
"buffer_ops"  ,
DEF_OP() { auto &buf=ed.getBuff();if(buf.isRegionActive()) buf.stopRegion();}   
)

◆ DEF_CMD() [3/23]

teditor::buffer::ops::DEF_CMD ( CommandRedo  ,
"command-redo"  ,
"buffer_ops"  ,
DEF_OP() { if(!ed.getBuff().redo()) CMBAR_MSG(ed, "No further redo information\n");}   
)

◆ DEF_CMD() [4/23]

teditor::buffer::ops::DEF_CMD ( CommandUndo  ,
"command-undo"  ,
"buffer_ops"  ,
DEF_OP() { if(!ed.getBuff().undo()) CMBAR_MSG(ed, "No further undo information\n");}   
)

◆ DEF_CMD() [5/23]

teditor::buffer::ops::DEF_CMD ( CopyRegion  ,
"copy-region"  ,
"buffer_ops"  ,
DEF_OP() { auto &buf=ed.getBuff();if(!buf.isRegionActive()) { CMBAR_MSG(ed, "No selection to copy!\n");return;} auto cp=buf.regionAsStr();ed.setClipboard(cp);buf.stopRegion();CMBAR_MSG(ed, "Copy done\n");}   
)

◆ DEF_CMD() [6/23]

teditor::buffer::ops::DEF_CMD ( CutRegion  ,
"cut-region"  ,
"buffer_ops"  ,
DEF_OP() { auto &buf=ed.getBuff();if(!buf.isRegionActive()) { CMBAR_MSG(ed, "No selection to cut!\n");return;} auto del=buf.removeAndCopy();ed.setClipboard(del);CMBAR_MSG(ed, "Cut done\n");}   
)

◆ DEF_CMD() [7/23]

teditor::buffer::ops::DEF_CMD ( DeleteChar  ,
".delete-char"  ,
"buffer_ops"  ,
DEF_OP() { ed.getBuff().remove(true);}   
)

◆ DEF_CMD() [8/23]

teditor::buffer::ops::DEF_CMD ( DownloadBuffer  ,
"download-to-buffer"  ,
"buffer_ops"  ,
DEF_OP() { auto &buf=ed.getBuff();if(buf.isRegionActive()) buf.remove();auto url=ed.prompt("URL: ");if(url.empty()) return;auto output=downloadUrlToString(url, Option::get("dnldProg").getStr(), Option::get("dnldProgOpts").getStr());if(output.empty()) return;buf.insert(output);}   
)

◆ DEF_CMD() [9/23]

teditor::buffer::ops::DEF_CMD ( InsertChar  ,
".insert-char"  ,
"buffer_ops"  ,
DEF_OP() { auto &buf=ed.getBuff();if(buf.isRegionActive()) ed.runCmd(".backspace-char");auto c=(char) ed.getKey();buf.insert(c);}   
)

◆ DEF_CMD() [10/23]

teditor::buffer::ops::DEF_CMD ( KeepLines  ,
"keep-lines"  ,
"buffer_ops"  ,
DEF_OP() { keepRemoveLines(ed, true);}   
)

◆ DEF_CMD() [11/23]

teditor::buffer::ops::DEF_CMD ( KillLine  ,
"kill-line"  ,
"buffer_ops"  ,
DEF_OP() { auto del=ed.getBuff().killLine();ed.setClipboard(del);CMBAR_MSG(ed, "Line killed\n");}   
)

◆ DEF_CMD() [12/23]

teditor::buffer::ops::DEF_CMD ( KillOthers  ,
"kill-other-buffers"  ,
"buffer_ops"  ,
DEF_OP() { ed.killOtherBuffs();}   
)

◆ DEF_CMD() [13/23]

teditor::buffer::ops::DEF_CMD ( KillThis  ,
"kill-this-buffer"  ,
"buffer_ops"  ,
DEF_OP() { ed.killCurrBuff();}   
)

◆ DEF_CMD() [14/23]

teditor::buffer::ops::DEF_CMD ( Next  ,
"next-buffer"  ,
"buffer_ops"  ,
DEF_OP() { ed.incrementCurrBuff();}   
)

◆ DEF_CMD() [15/23]

teditor::buffer::ops::DEF_CMD ( PasteRegion  ,
"paste-region"  ,
"buffer_ops"  ,
DEF_OP() { auto &buf=ed.getBuff();if(buf.isRegionActive()) buf.remove();auto copy=ed.clipboard();if(!copy.empty()) buf.insert(copy);}   
)

◆ DEF_CMD() [16/23]

teditor::buffer::ops::DEF_CMD ( Previous  ,
"prev-buffer"  ,
"buffer_ops"  ,
DEF_OP() { ed.decrementCurrBuff();}   
)

◆ DEF_CMD() [17/23]

teditor::buffer::ops::DEF_CMD ( Pwd  ,
"pwd"  ,
"buffer_ops"  ,
DEF_OP() { const auto &buf=ed.getBuff();CMBAR_MSG(ed, "Pwd: %s\n", buf.pwd().c_str());}   
)

◆ DEF_CMD() [18/23]

teditor::buffer::ops::DEF_CMD ( Reload  ,
"reload-buffer"  ,
"buffer_ops"  ,
DEF_OP() { auto &buf=ed.getBuff();if(!buf.isModified()||ed.promptYesNo("Buffer modified, still reload? ")) buf.reload();}   
)

◆ DEF_CMD() [19/23]

teditor::buffer::ops::DEF_CMD ( RemoveLines  ,
"remove-lines"  ,
"buffer_ops"  ,
DEF_OP() { keepRemoveLines(ed, false);}   
)

◆ DEF_CMD() [20/23]

teditor::buffer::ops::DEF_CMD ( Save  ,
"save-buffer"  ,
"buffer_ops"  ,
DEF_OP() { auto &buf=ed.getBuff();if(buf.isRO()) { CMBAR_MSG(ed, "save-buffer: Read Only Buffer!\n");return;} ed.saveBuffer(buf);}   
)

◆ DEF_CMD() [21/23]

teditor::buffer::ops::DEF_CMD ( ShellToBuffer  ,
"shell-to-buffer"  ,
"buffer_ops"  ,
DEF_OP() { auto &buf=ed.getBuff();if(buf.isRegionActive()) buf.remove();auto cmd=ed.prompt("Shell Command: ");if(cmd.empty()) return;MESSAGE(ed, "Shell Command: %s\n", cmd.c_str());auto res=check_output(cmd);if(res.output.empty()) return;buf.insert(res.output);MESSAGE(ed, "Exit Code: %d\nError: %s\n", res.status, res.error.c_str());}   
)

◆ DEF_CMD() [22/23]

teditor::buffer::ops::DEF_CMD ( StartRegion  ,
"start-region"  ,
"buffer_ops"  ,
DEF_OP() { auto &buf=ed.getBuff();if(!buf.isRegionActive()) { buf.startRegion();} else { buf.stopRegion();buf.startRegion();} }   
)

◆ DEF_CMD() [23/23]

teditor::buffer::ops::DEF_CMD ( TextSearch  ,
"search"  ,
"buffer_ops"  ,
DEF_OP() { auto &buf=ed.getBuff();auto pos=buf.getPoint();ISearch is(ed.getWindow(), Option::get("iCaseSearch").getBool());is.reset();auto ret=ed.prompt("Search: ", nullptr, &is);buf.gotoLine(!ret.empty()? is.getChoiceIdx() :pos.y, ed.getWindow().dim());}   
)

◆ keepRemoveLines()

void teditor::buffer::ops::keepRemoveLines ( Editor ed,
bool  keep 
)