SkillAgentSearch skills...

NEd

Plain GTK3-Sourceview based Nim editor with nimsuggest support

Install / Use

/learn @StefanSalewski/NEd
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

== NEd (Nim Ed) :experimental: :imagesdir: http://ssalewski.de/tmp (c) Stefan Salewski + Version 0.4, 20-NOV-2017

NOTE: This version is nearly identical with the original one from github.com/ngtk3 but uses the never oldgtk3 low level GTK 3.22 bindings. The original ngtk3 GTK 3.20 low level bindings can be regarded as deprecated and will be deleted at some point in the future. Also note that now the gintro package provides high level GTK3 bindings, so you may not regard this program as an up to date GTK3 example.

NEd is a simple GTK3 text editor with special support for the Nim programming language. It supports syntax highlighting and permanent extended symbol info displayed on the statusbar at the bottom like symbol origin and procedure parameters. Checking for errors is very fast, and extended error information is displayed as tooltips. Plain text search is supported by smart symbol search with optional replace. For each symbol you can display its definitions with source code. Splitting the display horizontally or vertically in unlimited number of views is supported, including multi-view display of a single text file.

=== Visual appearance

image::ned_0.2.png[]

You can optionally hide notebook tabs, scrollbars and line number display.

=== Introduction

This program was started as one more test and example of the https://github.com/ngtk3[GTK3 bindings] for the http://nim-lang.org[Nim] programming language, but has evolved fast to a nice and useful tool for Nim development. Its primary target is GNU/Linux -- it may work also on other operating systems including Windows or macOSX, but that is untested and will currently not be active supported by the original author.

If you have no intention coding in Nim language or absolutely do not like the GTK3 GUI toolkit, then this software is definitely not for you. In the best case you actually consider doing some GTK3 GUI coding yourself, but that is optional. And it should be clear that this tool can not really compare with powerful editors like Vim or Emacs or proprietary editors. Maybe in a later stage it can become comparable to GEdit, the default Gnome/GTK editor. Well not really, https://www.openhub.net/[OpenHub] reports 100k lines of C code for GEdit, while this tool has currently less than 2k lines of Nim code, and it will never have more than a few thousand lines:-)

The largest benefits of this tool is the full nimsuggset integration and easy customization by hacking the source code.

http://www.gtk.org/[GTK] is not very popular currently -- mailing lists and IRC have very low activity, which makes it really hard to find community support for coding problems. Some reasons for this may be that GTK is not really cross platform with native look and feel, and that it's object oriented design coded in plain C is a bit strange. But on the other hand its C API makes language bindings easily available for many programming languages.

The currently used oldgtk3 GTK3 bindings for Nim are not really high level. This means that the GTK3 widgets can not be extended in the same way as Nim objects, and that it can be necessary to free objects or memory manually. Both is not really a big problem, we can use GObject macro system to subclass widgets, we can put widgets into Nim object or create other references between Nim objects and GTK widgets, maybe with hash maps. Or we may use g_object_set_data()/g_object_get_data() to extend widgets derived from GObject base class with custom data. And manual memory deallocation is only necessary in rare cases, because GTK uses reference counting: Widgets are generally put into containers like boxes or windows -- when the containers are destroyed the children are unreferenced and destroyed automatically. This works not bad in C, and works in Nim also. The low level structure of the oldgtk3 GTK3 bindings has the advantage, that the Nim code has the same basic structure as C code, so the available C examples can be used as guides. For example this tool is based on GTK_Source_View C examples and Gnome application examples.footnote:[https://developer.gnome.org/gtk3/stable/ch01s04.html#id-1.2.3.12.5]

Maybe later someone will port NEd to the high level gintro bindings.

The biggest problem is unfortunately that we need some knowledge of GTK3 and the related libraries when we intent to do serious GUI development. The C API documentation is really not that bad, but it is large and learning it can take some time and effort.

=== Install

Currently this editor is only tested on 64 bit GNU/Linux with GTK 3.22 (Gentoo AMD64). You need a working Nim compiler (version 0.17.2 or higher) and a working installation of Nim's nimsuggest tool. And GTK 3.22 or higher and related packages, including GtkSourceView and maybe additional the related developer files.

This repository uses the oldgtk3 nimble package.

Install through Nim's package Manager Nimble is currently not supported due to name conflicts with old legacy GTK2 packages which are part of Nim's standard software base.

To install oldgtk3 package and NEd editor open a terminal window and execute these commands:


nimble install oldgtk3 git clone https://github.com/stefansalewski/NEd cd NEd bash ./make_it

The make_it build script is necessary because we have to generate resource files from the XML source files for the GUI. That script calls gcc C compiler, you may try to modify it for clang. And you may add option -d:release to get a smaler and faster executable without included debugging code.

Note: This tool uses Gnome's gsettings for permanently storing user preferences. To reset these states this command can be used:

`gsettings --schemadir "." reset-recursively "org.gtk.ned"''

Maybe you want to try the included color scheme and syntax highlight XML file? In that case you may consult the gedit instructions. On my Linux box I put these file where the other GtkSourceView files reside:


as root

cp nimdark1.xml /usr/share/gtksourceview-3.0/styles/ cp nim.lang /usr/share/gtksourceview-3.0/language-specs/

That nim.lang file contains code to generate vertical bars to indicate indentation, which may look ugly with other color schemes. For that case, just remove these lines at the bottom of file nim.lang:


<context ref="indent-pat0"/> <context ref="indent-pat12"/> <context ref="indent-pat8"/> <context ref="indent-pat4"/> ----

Or you may try the syntax-highlighting file from https://github.com/nim-lang/Aporia[Aporia Editor].

=== Launching the Editor


./ned file1.nim file2.nim

Unfortunately you can launch it for testing only this way, from inside its directory. When that test is sucessfull, and you intend to really use it, then installing the gsettings configuration is necessary. One method would be this:


And for making gsettings available system wide one method is, as root

https://developer.gnome.org/gio/stable/glib-compile-schemas.html

echo $XDG_DATA_DIRS

/usr/share/gnome:/usr/local/share:/usr/share:/usr/share/gdm

cd /usr/local/share/glib-2.0/schemas

cp org.gtk.ned.gschema.xml .

glib-compile-schemas .


Unfortunately that can be done only with administrator rights, and I don't know how it could be done on Windows or Mac.

=== Using the Editor

The title bar of the Gnome Desktop should display a NEd menu with a Preferences item, which allows you to select fonts and color schemes, and other configuration options. Proportional fonts are supported, but some have tiny spaces unfortunately. You may try the Input font series, which are free of charge for personal use. For medium size (27") 4k displays the overpass fonts look nice, I am using them for the whole Gnome desktop currently. The preferences dialog allows to tune display of line numbers, notebook tabs and scrollbars. And you can change some search options. The Gears menu on the top right of the main window has entries for splitting the current view vertically or horizontally -- you can change the size of the split views with an invisible slider. And you can reposition notebook tabs by grabbing the tab with the textual label and moving it onto other tabs (drag and drop). (That does not work when tabs are hidden, and needs some skills: Mouse pointer changes shape when drop position is reached.) Generally new views are opened in the notebookfootnote:[A Notebook is the container widget which displays one of multiple files stacked on each other, clicking on the tabs above the text display switches the visible text files.] which contains the last active view -- the one which had focus (input cursor ) recently. If the active view has title Unsaved and contains no text, that one is used for the new file. (Remember, it has to be active, so you may have to click into that text area before to indicate that you really want to fill that one.) If you try to open an already opened file again, you will get a new view of that file using the already existing test buffer. Generally you use a different notebook for that so that both views are visible at the same time and you can edit the buffer at different locations.

For vertical scrolling you can use the mouse wheel, the slider at the right side of the text, or keyboards keys. Pressing the right mouse button opens a context menu with cut/copy/past and undo support.

Most functionality is provided by GtkSourceView and related widgets, that includes text input, cursor movement, scrolling, selecting text with the mouse and much more.

You may enter search terms into the search text entry -- occurrences are highlighted immediately in the text area. If you enter a number prefixed with ':' view will scroll to that line. If the cursor is in the text area, you may press Ctrl / to activate the search entry -- pressing Return key brings you back into text area

Ctrl+G and Ctrl+Shift+G scrolls to next or previous occurrence. Or you can use Ctrl+F in the text area to find the word under

View on GitHub
GitHub Stars8
CategoryCustomer
Updated1y ago
Forks0

Languages

Nim

Security Score

70/100

Audited on Mar 24, 2025

No findings