nne

No-nonsense editor under 777 SLOC of ANSI C
git clone git://git.luxferre.top/nne.git
Log | Files | Refs | README | LICENSE

commit 1aeace39f0c2b5a145f4504a1902e9fa057a327c
parent 3f4d3e5f1569cf2bb76665e57ba1de98951e8296
Author: luxferre <lux@ferre>
Date:   Fri, 28 Jul 2023 08:18:03 +0300

Updated readme

Diffstat:
MREADME.md | 6+-----
Mnne.c | 31++++++++++++++-----------------
2 files changed, 15 insertions(+), 22 deletions(-)

diff --git a/README.md b/README.md @@ -62,7 +62,7 @@ You get the idea. Currently, nne can't be compiled with [TCC](https://bellard.org/tcc/) and [lacc](https://github.com/larmel/lacc) because they both fail with `undefined reference to '__dso_handle'` error. This symbol is used by the `atexit()` call that sets up the handler to clean up the terminal environment on any abnormal exit. For TCC, the error can be mitigated by directly linking with the `libc.a` from musl (as shown above) but the resulting binary still is dynamically linked with glibc and displays unstable behavior. -Also, [neatcc](https://github.com/aligrudi/neatcc) (+ [neatlibc](https://github.com/aligrudi/neatlibc)) can't compile nne because it lacks support for variadic macros. +Also, [neatcc](https://github.com/aligrudi/neatcc) (+ [neatlibc](https://github.com/aligrudi/neatlibc)) can't compile nne because it gives `strlen undefined` error. ## Usage @@ -147,10 +147,6 @@ No. All the focus is going to be on fixing bugs (if there are any found) and siz It should not be hard. Most (if not all) changes are going to be related to terminal I/O. -### Is there any refactoring planned to get rid of the variadic macro requirement? - -Not in the foreseeable future. It would be nice to make nne buildable on more compilers, but it also might be wise to wait until small compilers such as neatcc start supporting such features. - ### Why does `mod e` (running external command) force saving the currently edited file? Because it can't guarantee that the external command won't kill the nne process itself. Thus, saving is enforced to preserve your data. Also, this shell runner feature is introduced for easy offloading of some functionality to external tools designed to do it much better than any in-editor features would allow, e.g. running `sed` to perform a global substitution on the very file we're editing right now. It would be a shame if this global substitution had been performed on an old copy of the file and any subsequent save had obliterated all the changes made by the external command. diff --git a/nne.c b/nne.c @@ -98,9 +98,6 @@ char* nnmsg(int desc, char *format, ...) { if(r > 0 && desc > 0) write(desc, nne_msgbuf, r); return nne_msgbuf; } -#define nnformat(...) nnmsg(0,__VA_ARGS__) -#define nnprintf(...) nnmsg(1,__VA_ARGS__) -#define nntrace(...) nnmsg(2,__VA_ARGS__) /* write a widechar (internal) to stdout */ void nnwritew(int w) {uchar c;while((c=(w&255))>0){write(1,&c,1);w>>=8;}} @@ -367,10 +364,10 @@ uint inkey() { /* input a single key (logical) */ /* Esc (or double Esc) aborts */ /* returns the resulting amount of input characters */ uint nne_prompt(char *prompt) { - nnprintf(CURSET LINECLR, nne_termh, 1); /* clear the status bar line */ + nnmsg(1, CURSET LINECLR, nne_termh, 1); /* clear the status bar line */ uint c, rd = 0, endinput = 0, l = strlen(prompt); /* print the prompt message and move the cursor after it */ - if(l > 0) nnprintf("%s ", prompt); + if(l > 0) nnmsg(1, "%s ", prompt); memset(nne_cmdbuf, 0, NNE_IOBUFSZ * NNE_CSZ); /* zero out the input buffer */ while(rd < NNE_IOBUFSZ) { c = inkey(); @@ -381,7 +378,7 @@ uint nne_prompt(char *prompt) { nne_cmdbuf[rd-1] = 0; /* zero out the character */ rd--; /* decrement the read counter */ /* move cursor back and erase until the end of the line */ - nnprintf("\x1b[%uD\x1b[0K", c == '\t' ? NNE_TABWIDTH : 1); + nnmsg(1, "\x1b[%uD\x1b[0K", c == '\t' ? NNE_TABWIDTH : 1); } break; case K_ESC: case K_MODCMD: endinput = 1; rd = 0; break; /* abort */ @@ -477,11 +474,11 @@ void render() { /* main screen rendering function */ scrbuf_append(nne_msgbuf); nne_status_override = 0; } - else scrbuf_append(nnformat(CURSET "%c %s %u,%u %02u%% %ux%u", nne_termh, 1, + else scrbuf_append(nnmsg(0, CURSET "%c %s %u,%u %02u%% %ux%u", nne_termh, 1, (nne_mode == NNE_CMD) ? 'C' : '-', nne_fname, nne_row, nne_col, (100*nne_pos/(nne_real_len <= 2 ? 2 : nne_real_len - 2)), nne_termw, nne_termh)); - scrbuf_append(nnformat(CURSET CURSHOW "\0", nne_scry, nne_scrx)); + scrbuf_append(nnmsg(0, CURSET CURSHOW "\0", nne_scry, nne_scrx)); /* actually draw the screen buffer until the first zero byte */ nnputs(nne_scrbuf); } @@ -592,7 +589,7 @@ int motion_save() { /* save the buffer into file */ nne_cmdbuf[i] >>= 8; } } else { /* no new name entered */ - nnformat(CURSET "No file saved", nne_termh, 1); + nnmsg(0, CURSET "No file saved", nne_termh, 1); nne_status_override = 1; return 0; } @@ -609,14 +606,14 @@ int nne_action(int key) { switch(key) { case 's': case 'w': if(motion_save()) { - nnformat(CURSET "Saved %s, %u chars, %u lines", + nnmsg(0, CURSET "Saved %s, %u chars, %u lines", nne_termh, 1, nne_fname, nne_real_len - 2, nne_buflines); nne_status_override = 1; } break; case 'y': /* copy current line */ r = nne_copyregion(nne_linestart(nne_pos), nne_lineend(nne_pos) + 1); - nnformat(CURSET "Copied %u chars", nne_termh, 1, r); + nnmsg(0, CURSET "Copied %u chars", nne_termh, 1, r); nne_status_override = 1; break; case 'Y': /* copy multiple lines starting from the current one */ @@ -624,14 +621,14 @@ int nne_action(int key) { if(r < 1 || r > nne_buflines - nne_row) r = 1; i = nne_lineend(nne_findline(nne_row + r - 1)); r = nne_copyregion(nne_linestart(nne_pos), i + 1); - nnformat(CURSET "Copied %u chars", nne_termh, 1, r); + nnmsg(0, CURSET "Copied %u chars", nne_termh, 1, r); nne_status_override = 1; break; case 'd': /* cut current line */ r = nne_copyregion(i = nne_linestart(nne_pos), nne_lineend(nne_pos) + 1); nne_pos = i; /* go to the current line start */ for(i=0;i<r;i++) motion_del(); - nnformat(CURSET "Cut %u chars", nne_termh, 1, r); + nnmsg(0, CURSET "Cut %u chars", nne_termh, 1, r); nne_status_override = 1; break; case 'D': /* cut multiple lines starting from the current one */ @@ -641,12 +638,12 @@ int nne_action(int key) { r = nne_copyregion(i = nne_linestart(nne_pos), j + 1); nne_pos = i; /* go to the current line start */ for(i=0;i<r;i++) motion_del(); - nnformat(CURSET "Cut %u chars", nne_termh, 1, r); + nnmsg(0, CURSET "Cut %u chars", nne_termh, 1, r); nne_status_override = 1; break; case 'v': case 'p': /* paste */ for(i=0;i<nne_cliplen;i++) nne_inschar(nne_clipbuf[i]); - nnformat(CURSET "Pasted %u chars", nne_termh, 1, nne_cliplen); + nnmsg(0, CURSET "Pasted %u chars", nne_termh, 1, nne_cliplen); nne_status_override = 1; break; case 'l': @@ -673,7 +670,7 @@ int nne_action(int key) { if(r) {nne_pos = nne_searchidx = i; break;} if(i == nne_real_len - 2) { nne_searchidx = -1; - nnformat(CURSET "End of search results", nne_termh, 1); + nnmsg(0, CURSET "End of search results", nne_termh, 1); nne_status_override = 1; break; } @@ -700,7 +697,7 @@ int nne_action(int key) { r = system(rcmd); /* run the shell command */ free(rcmd); /* free command buffer */ nne_loadfile(nne_fname); /* reload file */ - nnformat(CURSET "Command exit code: %d", nne_termh, 1, r); + nnmsg(0, CURSET "Command exit code: %d", nne_termh, 1, r); nne_status_override = 1; } break;