Editor
Source code editor in pure Go.
- This is a know-what-you're-doing source code editor
- As the editor is being developed, the rules of how the UI interacts will become more well defined.
Features
- Auto-indentation of wrapped lines.
- No code coloring (except comments).
- Many TextArea utilities: undo/redo, replace, comment, ...
- Start external processes from the toolbar with a click, capturing the output to a row.
- Drag and drop files/directories to the editor.
- Detects if files opened are changed outside of the editor.
- Calls goimports if available when saving a .go file.
- Clicking on
.gofiles identifiers will jump to the identifier definition (Ex: a function definition). - Auto-completion (suggestions) in
.gofiles. (experimental) - Debugger utility for go programs. (experimental)
Installation and usage
go get -u github.com/jmigpin/editor
cd $GOPATH/src/github.com/jmigpin/editor
go build
./editor
Usage of ./editor:
-colortheme string
available: light, dark, acme (default "light")
-commentscolor int
Colorize comments. Can be set to zero to use a percentage of the font color. Ex: 0=auto, 1=Black, 0xff0000=red.
-cpuprofile string
profile cpu filename
-dpi float
monitor dots per inch (default 72)
-font string
font: regular, medium, mono, or a filename (default "regular")
-fonthinting string
font hinting: none, vertical, full (default "full")
-fontsize float
(default 12)
-scrollbarleft
set scrollbars on the left side (default true)
-scrollbarwidth int
Textarea scrollbar width in pixels. A value of 0 takes 3/4 of the font size.
-sessionname string
open existing session
-shadows
shadow effects on some elements (default true)
-tabwidth int
(default 8)
-usemultikey
use multi-key to compose characters ([multi-key, ~, a]=ã, ...)
-wraplinerune int
code for wrap line rune, can be set to zero (default 8594)
Basic Layout
The editor has a top toolbar and columns. Columns have rows. Rows have a toolbar and a textarea.
These row toolbars are also textareas where clicking on the text will run that text as a command.
The row toolbar has a square showing the state of the row.
Toolbar usage examples
Commands in toolbars are separated by "|" (not to be confused with the shell pipe). If a shell pipe is needed it should be escaped with a backslash.
All commands implemented by the editor start with an Uppercase letter. Otherwise it tries to run an existent external program.
Examples:
~/tmp/subdir/file1.txt | lsClicking atlswill runlsat~/tmp/subdir~/tmp/subdir/file1.txt | ls -l \| grep fiNotice how "|" is escaped, allowing to runls -l | grep fi~/tmp/subdir/file1.txtClicking atfile1.txtopens a new row to edit the same file. Clicking at~/tmpopens a new row located at that directory.gorename -offset $edPosOffset -to abcUsage of external command with active row position as argument. gorename godoc, go tools.guru -scope fmt callers $edPosOffsetUsage of external command with active row position as argument. guru godoc, go tools.grep -niIR somewordGrep results with line positions that are clickable.xdg-open $edDirOpen favorite external application with active row directory.xtermOpen an xterm at the active row directory.
Commands
Top toolbar commands
ListSessions: lists saved sessionsSaveSession <name>: save session to ~/.editor_sessions.jsonDeleteSession <name>: deletes the session from the sessions fileNewColumn: opens new columnNewRow: opens new empty row located at the active-row directory, or if there is none, the current directory. Useful to run commands in a directory.ReopenRow: reopen a previously closed rowSaveAllFiles: saves all filesReloadAll: reloads all filepathsReloadAllFiles: reloads all filepaths that are filesColorTheme: cycles through available color themes.FontTheme: cycles through available font themes.Exit: exits the program
Row toolbar commands
These commands run on a row toolbar, or on the top toolbar with the active-row.
Save: save fileReload: reload contentCloseRow: close rowCloseColumn: closes row columnFind: find string (ignores case)GotoLine <num>: goes to line numberReplace <old> <new>: replaces old string with new, respects selectionsStop: stops current process (external cmd) running in the rowListDir: lists directory-sub: lists directory and sub directories-hidden: lists directory including hidden
MaximizeRow: maximize row. Will push other rows up/down.CopyFilePosition: copy to clipboard/primary the cursor file position in the format "file:line:col". Useful to paste a clickable text with the file position.ToggleRowHBar: toggles row textarea horizontal scrollbar.XdgOpenDir: callsxdg-opento open the row directory with the preferred external application (ex: a filemanager).GoRename <new-name>: callsgorenameto rename the identifier under the text cursor. Uses the row/active-row filename, and the cursor index as the "offset" argument. Reloads the calling row at the end if there are no errors.GoDebug {run,test} <filename.go>: debugger utility for go programs.-dirs: directories to include in the debug session.- use
esckey to stop the debug session.
- toolbar first part (usually the row filename): clicking on a section of the path of the filename will open a new row (possibly duplicate) with that content. Ex: if a row filename is "/a/b/c.txt" clicking on "/a" will open a new row with that directory listing, while clicking on "/a/b/c.txt" will open a duplicate of that file.
Textarea commands
OpenSession <name>: opens previously saved session<url>: opens url in preferred application.<filename(:number?)(:number?)>: opens filename, possibly at line/column (usual output from compilers). Check common locations like$GOROOTand C include directories.<identifier-in-a-.go-file>: opens definition of the identifier. Ex: clicking inPrintlnonfmt.Printlnwill open the file at the line that contains thePrintlnfunction definition.
Environment variables set available to external commands
$edName: row name.$edDir: row directory.$edPosOffset: filename with offset position from active row cursor. Ex: "filename:#123".
Row states
- background colors:
blue: row file has been edited.orange: row file doesn't exist.
- dot colors:
black: row currently active. There is only one active row.red: row file was edited outside (changed on disk) and doesn't match last known save. UseReloadcmd to update.blue: there are other rows with the same filename (2 or more).yellow: there are other rows with the same filename (2 or more). Color will change when the pointer is over one of the rows.
Key/button shortcuts
Global key/button shortcuts
esc:close context float box- stop debugging session
f1:toggle context float box(work in progress)does auto-completion in.gofiles.
Column key/button shortcuts
buttonLeft:- on left border: drag to move/resize
- on square-button: close
Row key/button shortcuts
ctrl+s: save filectrl+f: warp pointer to "Find" cmd in row toolbarbuttonLefton square-button: close row- on top border:
buttonLeft: drag to move/resize rowbuttonMiddle: close rowbuttonWheelUp: adjust row vertical position, pushing other rows upbuttonWheelDown: adjust row vertical position, pushing other rows down
- Any button/key press: make row active to layout toolbar commands
Textarea key/button shortcuts
left: move cursor leftright: move cursor rightup: move cursor updown: move cursor downhome: start of lineend: end of linedelete: delete current runebackspace: delete previous runepageUp: page uppageDown: page downtab(if selection is on): insert tab at beginning of linesshift+left: move cursor left adding to selectionshift+right: move cursor right adding to selectionshift+up: move cursor up adding to selectionshift+down: move cursor down adding to selectionshift+home: start of string adding to selectionshift+end: end of string adding to selectionshift+tab: remove tab from beginning of linectrl+a: select allctrl+c: copy to clipboardctrl+d: comment linesctrl+k: remove linesctrl+v: paste from clipboardctrl+x: cutctrl+z: undoctrl+alt+down: move line downctrl+alt+shift+down: duplicate linesctrl+shift+z: redoctrl+shift+d: uncomment linesbuttonLeft: move cursor to point- drag: selects text - works as copy making it available for paste (primary selection).
over a debug annotation: print the shortened annotation string.
buttonMiddle: paste from primarybuttonRight: move cursor to point + text area cmdbuttonWheelUp: scroll upbuttonWheelDown: scroll downbuttonWheelUpon scrollbar: page upbuttonWheelDownon scrollbar: page downshift+buttonLeft: move cursor to point adding to selectionctrl+buttonLeft:godebug: select annotation
ctrl+buttonWheelUp:godebug: show previous debug stepon textarea: show previous debug stepover a debug annotation: show same line previous annotation
ctrl+buttonWheelDown:godebug: show next debug stepon textarea: show next debug stepover a debug annotation: show same line next annotation
Notes
- Uses X shared memory extension (MIT-SHM).
- MacOS might need to have XQuartz installed.
- Notable projects that inspired many features:
- Oberon OS: https://www.youtube.com/watch?v=UTIJaKO0iqU
- Acme editor: https://www.youtube.com/watch?v=dP1xVpMPn8M


