Coder Social home page Coder Social logo

e's Introduction

e

Braindead editor. Feels like Vim, only simpler. Inspired by kilo, of course, and a large swath of the code is similar.

It can be scripted through Lua.

asciicast

Features

  • Scripting through intuitive Lua interface
  • Incremental search (and replace)
  • Multiple modi (similar to Vim)
  • Mnemonic movement (feels like Vim, just different enough for you to be frustrated)
  • Limitless Undo (until memory runs out)
  • Extensible syntax highlighting
  • No global state in the library part (just in main.c)
  • Can be used as a library
  • Ships with syntax highlighting for
    • C/C++ (stable)
    • Python (experimental)
    • JavaScript (experimental)
    • Go (experimental)
    • Haskell (experimental)
    • Carp (experimental)
    • Markdown (unfinished)

Installation

git clone https://github.com/hellerve/e
cd e
make install # install_lua for Lua support

If there are any problems—particularly with Lua—, please refer to the Troubleshooting page on the wiki.

Usage

There are two major modes, init and edit. edit mode works like a normal text editor would. init mode enables the user to navigate and do meta work, such as saving the file, searching, and replacing.

init mode mnemonics

Use wasd or the arrow keys for movement. Editing (backspace, etc.) works normally.

  • n: insert a line below the cursor and start editing (next)
  • p: insert a line above the cursor and start editing (previous)
  • b: jump to the beginning of the line and start editing
  • t: jump to the end of the line and start editing (terminus)
  • h: hide a line (delete it) and add it to the system clipboard (clipboard only on Windows and OS X)
  • c: copy a line to the system clipboard (only on Windows and OS X)
  • v: view (i.e. paste) the contents of the system clipboard (only on Windows and OS X)
  • /: incremental highlighted search
  • r: search and replace first occurrence
  • R: search and replace all occurrences
  • Space: quick save (might be prompted for a file name)

In meta mode (reachable by pressing the colon character :), there are the following commands:

  • s: save and quit (might be prompted for a file name)
  • q: exit (will abort if the file has unsaved content)
  • !: force exit
  • Number n: jump to line n

Writing syntax files

By default, e creates a directory called .estx in the user's home directory (the location is overridable by providing STXDIR to make install). There, e will search for syntax files on startup. Their grammar is very minimal, see the C file below:

displayname: c
extensions: .*\.cpp$
            .*\.hpp$
            .*\.c$
            .*\.h$
comment|no_sep: //.*$
keyword: (restrict|switch|if|while|for|break|continue|return|else|try|catch|else|struct|union|class|typedef|static|enum|case|asm|default|delete|do|explicit|export|extern|inline|namespace|new|public|private|protected|sizeof|template|this|typedef|typeid|typename|using|virtual|friend|goto)
type: (auto|bool|char|const|double|float|inline|int|mutable|register|short|unsigned|volatile|void|int8_t|int16_t|int32_t|int64_t|uint8_t|uint16_t|uint32_t|uint64_t|size_t|ssize_t|time_t)
comment|no_sep: /\*.*\*/
comment|no_sep: /\*.*
                 .*\*/
pragma: \s*#(include|pragma|define|undef) .*$
predefined: (NULL|stdout|stderr)
pragma: \s*#(ifdef|ifndef|if) .*$
pragma: \s*#(endif)
string|no_sep: "([^\\\"]|\\.)*"
string|no_sep: '([^\\\']|\\.)'
number: [+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)[fl]?

displayname is the string displayed at the bottom of e. extensions is a list of regexes to match the filenames. Highlighting keys are comment, keyword, type, pragma, string, number, and predefined. By appending |no_sep, the user signals to e that no separator is needed, i.e. highlighting works even if the matched string is part of a longer word. The values are regexes.

If you provide a second regex (must by divided by a newline), e assumes that everything between the two matches should be colored (useful for e.g. multiline comments).

Scripting through Lua

The editor has scripting capabilities in Lua. Thus far I've only documented them in a blog post, but this post should give you a good overview of how to write Lua scripts for e. There is also an example .erc file in the repository that you can look at for inspiration.

That's it!

Tabs vs. Spaces

I personally always use spaces for indentation, thus e does the same. It will always convert all of the tabs in your file to spaces automatically for you, and I understand if that bit of behavior is undesired by some. It is very much by design, though, and probably won’t change.


Have fun!

e's People

Contributors

hellerve avatar jonruttan avatar markmontymark avatar nextlevelshit avatar rcshubhadeep avatar shaneharrigan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

e's Issues

Syntax highlighting is buggy in some cases

The cases I've seen:

  • Closing a multiline pattern doesn't always update the highlighting
  • Highlighting search results doesn't end where it's supposed to (highlights entire line)

Segmentation Fault

I just downloaded e for both Raspberry Pi (arm) and MAC OSX. e compiled cleanly on both machines however I get a segmentation fault on Raspberry Pi. Runs cleanly on Mac. Just an FYI.

e license would be useful

Hi,

Have you put any consideration into the license you plan to use for e? I'm working on a FreeBSD port at the minute and it would be great to be able to put that into the initial port submission.

Pressing <esc> in binary files leads to segfault

For reasons I’m not entirely certain of at the moment, pressing when working with a binary file leads to a segmentation fault. It seems to be related with drawing, but pressing shouldn’t do anything in edit mode, so I’m a bit confused.

Cheers

Skin-tone modifiers et al confuse the cursor

Related to #28: when using new-fangled Unicode fetures like skin-tone modifiers or emoji ligatures, the cursor becomes very unhappy as well. It is sort of the reverse problem that we have with full-width characters. We should probably handle all of those problems in one fell (and hopefully graceful) swoop.

heap buffer overflow int syntax_read_file

cp ./poc.stx ./stx
run ./bin/e

touch a file contains "\x00\x00\x00\x00" like poc.stx. run

fgets not return NULL but strlen return 0. so "ln =-1", line[ln] will error.

while (fgets(line, MAX_LINE_WIDTH, f)) {
    lineno++;
    ln = strlen(line)-1;
    line[ln] = '\0';                 //error
}
==2851==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x61d00001ea7f at pc 0x00000040d428 bp 0x7ffd417b66f0 sp 0x7ffd417b66e0
WRITE of size 1 at 0x61d00001ea7f thread T0
    #0 0x40d427 in syntax_read_file src/syntax.c:126
    #1 0x40d5d0 in syntax_init src/syntax.c:174
    #2 0x401d69 in main /home/fuzz/github/e_bak/main.c:49
    #3 0x7f32df71e82f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
    #4 0x401fc8 in _start (/home/fuzz/github/e_bak/bin/e+0x401fc8)

0x61d00001ea7f is located 1 bytes to the left of 2048-byte region [0x61d00001ea80,0x61d00001f280)
allocated by thread T0 here:
    #0 0x7f32dfb60602 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98602)
    #1 0x40d17e in syntax_read_file src/syntax.c:109

SUMMARY: AddressSanitizer: heap-buffer-overflow src/syntax.c:126 syntax_read_file
Shadow bytes around the buggy address:
  0x0c3a7fffbcf0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c3a7fffbd00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c3a7fffbd10: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c3a7fffbd20: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c3a7fffbd30: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x0c3a7fffbd40: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa[fa]
  0x0c3a7fffbd50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c3a7fffbd60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c3a7fffbd70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c3a7fffbd80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c3a7fffbd90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:       fa
  Heap right redzone:      fb
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack partial redzone:   f4
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
==2851==ABORTING

testcase:https://github.com/xcainiao/poc/blob/master/e_heap-buffer-overflow_syntax_read_file.stx

Make WASD customizable

WASD is not ergonomic on some keyboard layouts, and it would be a good idea to create a simple way to change them. Currently, we do these movements in a switch statement, meaning we cannot have non-constants. It would make sense to make this scriptable through Lua, though.

Thanks to this comment on HN for making me aware of this issue.

Make tab width non-global

Currently there is a global variable E_TAB_WIDTH that tells us how wide the tab should be. This shouldn't be too hard to convert into a local variable in the editor state.

Double 'h' key crashes e

In INIT mode, if you type 'h' to "hide" on an empty line, follow it then with an additional 'h' with cause e to crash on Ubuntu 16.04 and Fedora 26 respectfully.

Full-Width characters confuse the cursor

Fullwidth characters, such as kana (e.g. なんでやねん) or even fullwidth roman characters (e.g. oh no) confuse the cursor: it gets place at a normal halfwidth position, which is obviously wrong. Example:

bildschirmfoto 2017-09-07 um 15 19 15

This does not affect the capabilities of editing such a text, but the application still becomes more or less useless, because the cursor position is not correct.

Installation issue

Hey, when I try to make install on Fedora 25 I get this. Any ideas?

❯ make install                                                                  
mkdir -p /home/oskar/.estx
cp stx/* /home/oskar/.estx
mkdir -p bin/
cc main.c src/editor.c src/buffer.c src/util.c src/colors.c src/syntax.c -DSTXDIR=\"/home/oskar/.estx\" -o bin/e -Werror -Wall -g -fPIC -O2 -DNDEBUG -ftrapv -Wfloat-equal -Wundef -Wwrite-strings -Wuninitialized -pedantic
In file included from main.c:3:0:
src/editor.h:1:0: error: "_DEFAULT_SOURCE" redefined [-Werror]
 #define _DEFAULT_SOURCE
 
In file included from /usr/include/signal.h:28:0,
                 from main.c:1:
/usr/include/features.h:185:0: note: this is the location of the previous definition
 # define _DEFAULT_SOURCE 1
 
cc1: all warnings being treated as errors
Makefile:10: recipe for target 'all' failed
make: *** [all] Error 1

Compilation failure error: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Werror=unused-result]

GCC version.

$ cc --version
cc (Ubuntu 6.3.0-12ubuntu2) 6.3.0 20170406
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Errors.

$ make
mkdir -p /home/foobar/.estx
cp stx/* /home/foobar/.estx
mkdir -p bin/
cc main.c src/clipboard.c src/editor.c src/buffer.c src/util.c src/colors.c src/syntax.c -DSTXDIR=\"/home/foobar/.estx\" -o bin/e -Werror -Wall -g -fPIC -O2 -DNDEBUG -ftrapv -Wfloat-equal -Wundef -Wwrite-strings -Wuninitialized -pedantic -std=c11
src/editor.c: In function ‘e_die’:
src/editor.c:24:3: error: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Werror=unused-result]
   write(STDOUT_FILENO, "\x1b[2J\x1b[?47l\x1b""8", 12);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/editor.c: In function ‘e_exit’:
src/editor.c:31:3: error: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Werror=unused-result]
   write(STDOUT_FILENO, "\x1b[2J\x1b[?47l\x1b""8", 12);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/editor.c: In function ‘e_clear_screen’:
src/editor.c:214:3: error: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Werror=unused-result]
   write(STDOUT_FILENO, ab.b, ab.len);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/editor.c: In function ‘e_setup’:
src/editor.c:1214:3: error: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Werror=unused-result]
   write(STDOUT_FILENO, "\x1b""7\x1b[?47h", 8);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
src/syntax.c: In function ‘syntax_read_extensions’:
src/syntax.c:26:5: error: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Werror=unused-result]
     fgets(line, MAX_LINE_WIDTH, f);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/syntax.c: In function ‘syntax_read_pattern’:
src/syntax.c:55:5: error: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Werror=unused-result]
     fgets(line, MAX_LINE_WIDTH, f);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
Makefile:11: recipe for target 'all' failed
make: *** [all] Error 1

0 on all lines

On WSL Ubuntu 16.04, all lines start 0, and the cursor is one/two to the left of where it should be.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.