[dev] Sandy editor

From: pancake <pancake_AT_youterm.com>
Date: Thu, 26 May 2011 00:33:50 +0200

Here's my notes on sandy editor after some testing.

About moving sandy to hg.suckless.orgshould be discussed with Anselm. We can setup a cron sync to clone your repo.. But it would be better to have it there.

I think this editor fits very well in the suckless philosophy and project. Maybe other projects like star should then also move.. So this requires some
discussion in other trhread.

bug1) In BSDs regcomp(3) if you pass "" as first argument, you get a segfault.

bug2) Segfault I commented in the previous mail

I was able to reproduce the segfault:

  - write some text
  - press ^x
  - move cursor to select some text
  - press 'y'
  - got segflute in sandy.c:636

I wrote a patch that fixes the segfaults:

diff -r 9b1967b65738 sandy.c
--- a/sandy.c Thu May 19 21:06:57 2011 +0200
+++ b/sandy.c Wed May 25 23:29:33 2011 +0200
@@ -441,7 +441,9 @@
                                  : !regexec(syntaxes[i].file_re, filename, 1, NULL, 0)) {
                       for(j=0; j<SYN_COLORS; j++) {
                               if(syntx && syntx->re[j]) regfree(syntx->re[j]);
- if(regcomp(syntaxes[i].re[j], syntaxes[i].re_text[j], REG_EXTENDED|REG_NEWLINE)) i_die("Faulty regex.\n");
+ if(*syntaxes[i].re_text[j])
+ if(regcomp(syntaxes[i].re[j], syntaxes[i].re_text[j], REG_EXTENDED|REG_NEWLINE))
+ i_die("Faulty regex.\n");
                       setenv(envs[EnvSyntax], syntx->name, 1);
@@ -629,7 +631,7 @@
       Filepos pos0, pos1;
       pos0.l=l0, pos1.l=l1, pos0.o=pos1.o=0;
       i_sortpos(&pos0, &pos1);
- for(;pos0.l != pos1.l->next ;pos0.l=pos0.l->next) pos0.l->dirty=TRUE;
+ for(; pos0.l && pos0.l != pos1.l->next; pos0.l=pos0.l->next) pos0.l->dirty=TRUE;

void /* Delete text between pos0 and pos1, which MUST be in order, fcur and fsel integrity is NOT assured after deletion */

* ncurses sucks. but it's the only portable solution atm. at some point we can
 write a suckless curses library, removing all the old stuff and make it cleaner.
 - So.. minor changes would be required to make your editor run without ncurses.
* Remove utf8 enable/disable option. or make it compile-time option-only (-u flag)
 - I think nowadays all our apps should be utf8 ready
* Non-printable characters are printed (i know this is in config.h)
 - I prefer not to see what it's not going to be seen
 - What do you guys like? do you
 - If you print those chars, I suggest you to also display \r and \n chars
 - Imho it's smarter if you just see the text
* Strings with escaped quotes are not correctly highlighted
* i_die does not resets terminal configuration
* Linking fails in OSX because missing ncursesw name
 - there's a ncurses5-config that works like pkg-config and this
   should be used to make this portable
 - Or just drop the 'w' in the ncursesw5 libname (-lncurses works fine)
* I would prefer not to depend on dmenu/xsel
 - The terminal is usually implementing this copypasta into the Xselection buffer
 - On OSX/WayLand/W32 takes no sense to use this
 - I have an implementation of dmenu in text mode (ANSI, without curses)
 - about xsel... i would prefer to be able to use copypasta, without depending on X11
   - write 'csel' which stores the buffer in a file at home and uses xsel if possible.
 - the text input can be done in ncurses inside the editor, adding a text input
   entry at the bottom of the screen (or on top?), so dmenu is not a dependency.
 - Do you think it's important to have the possibility to use an external program
   to get text? in a text editor, which it's primary use is for entering text?
 - Another option would be to copy this buffer inside the editor which is simpler
   than using files or running programs, but letting the user to put in config.h
   a keybinding to pass the selection to a external program for stdin.
* I don't think support for modes is that important, and in fact, it makes the editor suck
 more, as long as you will never use the command mode for batch mode, and duplicates the
 input for doing the same thing in different ways. So imho it's more suckless if there are
 no modes. But emacs keybindings are a bit insame imho, we can think in a mix of the vim
 and emacs (see above)
* I tend to prefer a mode editor, because there are less keybindings in each mode
 and im am addicted to vim. These are the changes I propose for the keybindings. Let
 me know your feelings.
 - Maybe an Emacs guy would be happy with those keybindings. But i think these ones
   will be saner (without modes):
 - ^[hjkl] - move around
 - ^[HJKL] - move around selecting text
 - ^[fb] - go next/prev page
 - ^[np] - go next/prev page
 - ^k - find manpage on word under cursor
 - ^w - save
 - ^W - save as
 - ^q - quit
 - ^Z - save+quit (it's similar to vim's ZZ)
 - ^! - prompt to run program on selected/full text (indent, etc..)
 - ^z - must not be handled, because it's used by the shell for backgrounding apps
 - Whats the point of having aliases for newline for example? ^j, ^M, ..
 - meta shift q: is something that some ppl use in dwm to quit. It can be dangerous :) i think is better to only handle control and shift. At least for default keybindings
* Use -ggdb instead of -g, in OSX you have to specify the dwarf format to make gdb work with it.
 - I dont think -g should be in default makefile, it's useful for now, but must be
   removed when release.
* support for ascii art mode (do not limit cursor to end of text line
 - add support for inline copy and paste (select rectangle of text, and paste respecting
   the horitzontal position and replacing text. (like ^v in vim)

Other features
* show number line at the begining of line
* BUG: i_die() does not closes ncurses
* BUG: escaped quotes are not detected by syntax highlight
       printf ("hello \"world\""); -> stop highlight at first '"'
* FEATURE: add support for marks (like ma/'a in vim)
* Match brackets and go opening/closing bracket
* Find next/prev apparition of word under cursor

Btw.. i loved this macro:

#define UTF8LEN(ch) ((unsigned char)ch>=0xFC ? 6 : \
                       ((unsigned char)ch>=0xF8 ? 5 : \
                       ((unsigned char)ch>=0xF0 ? 4 : \
                       ((unsigned char)ch>=0xE0 ? 3 : \
                       ((unsigned char)ch>=0xC0 ? 2 : 1)))))

* I'm sorry about your ferret
Received on Thu May 26 2011 - 00:33:50 CEST

This archive was generated by hypermail 2.2.0 : Thu May 26 2011 - 00:36:03 CEST