NanoEmacs is a minimal version of JASSPA's MicroEmacs. JASSPA's MicroEmacs is by far the most common version of MicroEmacs today, but NanoEmacs does not seem to have gained much of a following. A Google search of “NanoEmacs” only brings up 370 results. For comparison, “MicroEmacs” gets 32,300 hits, “GNU Emacs” gets 1,090,000 hits, and “XEmacs” gets 2,200,000 hits. However, I think NanoEmacs is a pretty nifty editor and I prefer it to the full-blown MicroEmacs. However, I feel it works better after some customizations, and since actual documentation for NanoEmacs is sparse (largely limited to what one can glean off the MicroEmacs documentation) I've made this publicly available. Note these customizations represent my needs and preferences, and might not be optimal for other people.
Note this file uses Emacs shorthand. On most platforms, C-x means Ctrl and the ‘x’ key. Likewise, M-x is either Alt and the ‘x’ key, or Esc then the ‘x’ key.
The MicroEmacs source code. The NanoEmacs source is integrated into that. After downloading it, make sure to unpack it.
The GNU Toolchain. If you're running any version of Unix (such as GNU/Linux), everything you need is probably installed. For Windows, install MinGW or Cygwin; however, note that only the former will be able to create native Windows executables. It is possible to build the source code with other compilers, but this file doesn't go over that.
Within the src directory is two files: build and build.bat. Typing in build at the command line will run the former in Unix-like environments and the latter in Windows. Read the file build.txt for information on using the script. For Windows using MinGW, you'll probably want something like this:
build -m mingw32.gmk -ne -t cw
Note that -t cw specifies you want to create an executable capable of running in both GUI and console mode. This is normally not the default. The shipped Windows executable only runs in GUI mode, and the shipped executable for most other platforms only runs in console mode. If you only want one or the other, omit the ‘c’ or the ‘w’.
At the very least, -ne is required, else MicroEmacs is built instead.
NanoEmacs looks for a file in the same directory as the executable called ne.emf. Most binary distributions (with the exception of the Windows version) don't come with the file, and building from source code doesn't generate one, so create it. You can use this file for a lot more than it's referenced here for (including significant improvements to how NanoEmacs looks) but be warned that the syntax is complicated.
Word-wrap is what inserts a new line of text once a line of text grows to a certain length, which is useful for text documents. This step also enables fill-paragraph (M-q in GNU Emacs), indent (which auto-indents the text when appropriate), and some other features.
(This process is also covered briefly in the MicroEmacs FAQ, see Question 43 in faq.txt.)
Open up emain.h in a text editor. If the file is unchanged, we're interested in line 459. This line should start with #define MEOPT_WORDPRO and exist in a section marked “NanoEmacs Configuration options - Cut down version”. Simply change the number 0 following the #define MEOPT_WORDPRO to a 1. Yes, the authors made customization fairly easy. Just to be clear, the line should now be:
#define MEOPT_WORDPRO 1 /* Advanced word processing features */
You can now compile the editor (see above) and it should work. Open up the next executable and type M-q. If the editor doesn't object that “A-q” isn't bound, then everything is in order.
Wrap and indent can be toggled on and off by typing M-x global-mode and then typing “wrap” or “indent”. If you have difficulty remembering the entire name, tab-completion is supported.
If you use wrap or indent frequently you might prefer to not be required to enable them every time you open NanoEmacs. You can add the following lines to ne.emf to enable them by default:
; Turn on wrap and indent by default.
global-mode wrap 1
global-mode indent 1
NanoEmacs has the ability to split windows horizontally (C-x 2), but lacks the feature to split vertically (C-x 3). For those of use using wide screens, this is an unacceptable waste of space. Luckily, this is also easily fixed.
Open up file emain.h. As before, we're interested in the “NanoEmacs Configuration options - Cut down version” section. Find #define MEOPT_HSPLIT 0 on line 482 and change it to a 1. You'll also need to change #define MEOPT_EXTENDED 0 on line 478 to a 1. Technically, this is all you need to do. However, the result is not desirable. Vertical splitting will be possible, but no divider is created to mark the split, which is awkward. Thus, also flip #define MEOPT_SCROLL 0 on line 481 to a 1. Yeah, I know it says this will “enable scroll bars”, as a GUI minimalist I was put off by this as well. However, in NanoEmacs it doesn't actually enable a scrollbar, but simply a divider, which is what we want.
After making those three changes simply recompile. If C-x 3 works, everything went well.
Saving should not erase one's ability to undo past changes. Add this to your ne.emf file:
; Keep undo history after saves.
set-variable $system &bor $system 0x8000
In every text editor I've ever worked with, the Home key sends the cursor to the beginning of the line, and the End key to the end of the line. While Emacs-like editors have the same functionality much more conveniently found in the C-a and C-e commands, I still sometimes use the Home/End keys out of habit. Now, in NanoEmacs, Home goes to the beginning of the document (like M-<) and End goes to the end of the document (like M->). This is easily fixed by amending the ne.emf file:
; Home/End work as in GNU Emacs.
global-bind-key end-of-line "end"
global-bind-key beginning-of-line "home"
By default, NanoEmacs uses four spaces instead of the tab characters. Well, when I press tab, I want a tab character. Another problem easily fixed via the ne.emf file:
; Use real tabs, not spaces.
global-mode tab 0
Alternatively, this can be toggled manually via M-x global-mode [enter] tab [enter].
Under Windows, when using a GUI-enabled executable NanoEmacs has an annoying habit of employing an annoying alert menu at times. For example, the command for help, ne -h (or maybe new32 -h or necw32 -h on Windows) displays a little pop-up GUI window. While not the end of the world, it seems far more sensible to print out this information to the console, which is what every other program does.
To fix this, we're interested in a snippet of code running from lines 238 through 246 occurring in eextrn.h. It's reproduced below:
#ifdef _WIN32
#ifdef _ME_WINDOW
#define mePrintMessage(mm) MessageBox(NULL,(char *)
mm,ME_FULLNAME " '" meVERSION,MB_OK);
#else
#define mePrintMessage(mm) do{ int dummyInt;
WriteFile(GetStdHandle(STD_ERROR_HANDLE),mm,meStrlen(mm),&dummyInt,NULL); } while(0)
#endif
#else
#define mePrintMessage(mm) write(2,mm,meStrlen(mm))
#endif
Delete the whole block with the exception of this line:
#define mePrintMessage(mm) write(2,mm,meStrlen(mm))
This defines mePrintMessage() to always use the console. Simply recompile and it should work.
Everything above should work as expected, but I found it took a little more work to get NanoEmacs to compile under Debian. This might also be helpful in getting NanoEmacs to compile on other GNU/Linux distros or other Unices, or maybe not.
To compile the console version, the following packages and their dependencies are required: gcc, libc6-dev, libncurses5-dev. These can be installed via apt-get install [package] as root or through the Synaptic Package Manager.
To get the X (GUI) version, install libxt-dev and all its dependencies (there will be quite a few of them). This may be all you need to do, so try building. However, on my machine I got a fatal error related to “TCAPgetattr”. This is a function in unixterm.c, and the error comes from the function XTERMstart(void), specifically, lines 3075-3077:
#ifdef _USG
TCAPgetattr (&otermio, 1);
#endif
I hate to advocate the easy way out, but...:
#ifdef _USG
/* TCAPgetattr (&otermio, 1); */
#endif
With this, it built for me, and I haven't noticed any problems yet.
The shipped NanoEmacs executable for Windows is 224 KB. With these changes, this increases rather modestly to 279 KB. Compared to MicroEmacs (448 KB executable plus 5.1 MB of macros) or GNU Emacs (126 MB), that's not bad at all.
For those interested, my ne.emf. Basically, in addition to all the stuff mentioned here, it contains some modifications to the editor's appearance under Windows and some licensing/copyright information since it was based off JASSPA's example config file.
Here's ne(1), the NanoEmacs man page. You might also be interested in JASSPA's MicroEmacs documentation, or the EmacsWiki. See also other text editors.