Unryu: Files and Recovery
This page explains everything in the File menu: making new documents and documents from templates, opening and saving files, character encodings and line endings, what happens when a file changes on disk, closing and quitting, how Unryu reopens your last session, how it keeps your unsaved text safe after a crash, printing, and every file that Unryu keeps in your home folder.
1. How Unryu protects your work
Unryu is built so that you do not lose text by accident. Three rules run through everything on this page:
- It asks first. Close, Close All, Close Other Documents, Quit and Reload ask before they throw away unsaved changes. A save never silently overwrites a file that another program changed after Unryu read it.
- A save is all or nothing. When you save, the file on disk is either the old text or the new text, never half of each, even if the power fails in the middle (see section 9).
- Unsaved text survives a crash. While you type, Unryu keeps a copy of every unsaved document in a private folder. If Unryu crashes, is killed, or your X session ends, it offers that text back the next time it starts (see section 16).
An unsaved document shows a * before its name on its tab and in the window title. The window title also
shows the file's full path and the name of its project.
2. The File menu at a glance
| Item | Default key | What it does |
|---|---|---|
| New | Ctrl+N | A new, empty document in a new tab (section 3). |
| New (with Template) | A flyout of your templates; makes a new document from one (section 4). | |
| Open... | Ctrl+O | The Open dialog (section 5). |
| Open Selected File | Ctrl+Shift+O | Opens the file whose name is selected, or under the cursor (section 5). |
| Recent Files | The files you opened or saved most recently (section 5). | |
| Recent Projects | Reopens the files that were open in a project (section 5). | |
| Workbench | Named sets of projects and folders, each with its own tabs and bookmarks (section 5). | |
| Save | Ctrl+S | Saves the document to its file (section 9). |
| Save As... | none | Saves the document under a new name. |
| Save All | Ctrl+Shift+S | Saves every document that has unsaved changes. |
| Reload | Ctrl+R | Reads the file from disk again (section 10). |
| Reload As | Reads the file again in an encoding you choose. | |
| Properties | Facts about the document and its file (section 13). | |
| Page Setup | Paper, orientation and print options (section 17). | |
| Print... | Ctrl+P | Prints the document, or saves it as PDF or PostScript. |
| Close | Ctrl+W | Closes the document in front (section 14). |
| Close Other Documents | Closes every document except the one in front. | |
| Close All | Ctrl+Shift+W | Closes every document. |
| Quit | Ctrl+Q | Ends Unryu. |
You can change any of these keys, and give keys to the items that have none (except the flyouts New (with Template), Recent Files, Recent Projects, Workbench and Reload As), in Preferences > Keybindings (see Keyboard Shortcuts). Help > Keyboard Shortcuts lists the keys as they are now.
If you come from Geany: Ctrl+Shift+S is Save All in Unryu, not Save As. Save As has no key until you give it one.
The toolbar has buttons for the most used items: New, Open, Save, Save All, Reload and Close are on it by default, and Close All, Print and Quit can be added (Preferences > Interface > Toolbar). The small arrow beside the Open button drops down the Recent Files list.
3. New documents
File > New (Ctrl+N, the New button, or a double click on the empty part of the row of tabs, beside the tabs) opens an empty document named "untitled" in a new tab. It has no file yet: the first Save asks for a name. A new document takes its first settings from Preferences:
- the encoding from Preferences > Files > "Default encoding (new files)" (UTF-8 at first);
- the line ending from Preferences > Files > "Default end of line characters" (Unix (LF) at first);
- the indentation type and width, auto-indentation and line wrapping from Preferences > Editor.
Where the new tab goes is set in Preferences > Interface > Notebook tabs: "Placement of new file tabs" (Left or Right end) and "Next to current". Unryu holds at most 256 documents at once; past that, a new one cannot be opened.
There is always at least one document. When you close the last one, Unryu leaves an empty "untitled" tab so that there is somewhere to type. An empty, unchanged "untitled" document is reused: a file you open, or a document from a template, goes into it instead of into a new tab.
Document > Clone (see Editing) is the other way to make a new document: an untitled copy of the one in front.
4. New (with Template) and the templates
File > New (with Template) makes a new document from a template: a small starting file for a language, such as
a C program with its main function, or a Python script with its first line. The new document is unsaved,
the cursor is at its start, and it already has the language of the template, so its highlighting and its build
commands work at once.
Where the templates are
Every template is an ordinary file in the folder ~/.config/unryu/templates/. No template text is built
into the program. The first time you open the File menu and that folder does not exist, Unryu makes the folder and copies the
templates that come with Unryu into it. After that, the folder is yours: a template you deleted stays deleted, and a
template you changed stays as you changed it. A template new in a later version of Unryu is copied in once, the first
time that version opens the File menu (see section 18).
- To add a template, put a file in the folder. Its name decides its language and the name of the new document (see below).
- To remove one, delete its file.
- To change one, edit its file. You can open it from the folder like any other file.
Unryu reads the folder again each time you open the File menu, so a change shows at once, with no restart. Hidden files (names that start with a dot) and folders are ignored. The menu holds at most 64 templates, and a template name must be shorter than 64 characters. When the folder is empty, New (with Template) is greyed out.
To get templates that a newer Unryu ships into a folder you already have, copy them yourself from the
templates folder of the program (<prefix>/share/unryu/templates for an installed
Unryu).
How the menu is arranged
The templates are sorted by the name of their language, not by their file name, and split into groups of first letters, as Tools > Configuration Files > Language Files is. Each group is a flyout, for example "A - E" or "F - J", and each item shows the language and the file, for example "C (main.c)" or "PHP (page.php)". There are at most eight groups. A new template goes into the group of its language at once.
Unryu finds the language of a template in this order:
- A language that knows the whole file name (the
filenameskey of its language file). For example,CMakeLists.txtis CMake. Such a template keeps its own name: the new tab is called "CMakeLists.txt". - The extension, as for a file called "untitled.ext". When two languages share an extension, the template's text
decides (the
detectkey of the language files):main.mstarts with#import, so it is Objective-C and not Matlab. - The
#!line, for a template with no extension.
A template that no language knows goes into a group under its extension in capitals, for example "XYZ (file.xyz)", and its document is plain text. To give it a language, write a language file (see Languages).
The new document
The new tab is called "untitled" plus the template's extension ("untitled.py"), or the template's own name when a language knows the whole name. Save and Save As offer that name in the Name field. If the only open document is an empty "untitled" one, the template goes into it; otherwise it gets a new tab. The status bar says, for example, "New file untitled.py from the template main.py." If the template file cannot be read, it says "The template could not be read." and nothing is made.
Wildcards
A template may contain wildcards in braces. Unryu replaces them when it makes the document. Unryu has Geany's
file-template wildcards, so most templates written for Geany work as they are; Geany's comment wildcards
({gpl}, {bsd}, {fileheader}, {functionname}) are not replaced
(see below).
| Wildcard | Becomes |
|---|---|
{developer} {initial} {mail} {company} {version} | The Developer, Initials, Mail address, Company and Initial version fields of Preferences > Templates. |
{year} {date} {datetime} | The time now, written in the format of the Year, Date and Date & time fields of Preferences > Templates. These fields are strftime formats, for example %Y-%m-%d. |
{filename} | The name of the new document, for example "untitled.py". |
{filetype} | The name of its language, for example "Python". |
{untitled} | The word "untitled". Several shipped templates use it as the name of a module, namespace or program; change it when you save the file under its real name. |
{program} {geanyversion} | "Unryu". |
{ob} {cb} | An opening brace { and a closing brace }. You rarely need them: a brace that is not part of a known wildcard stays as it is, so C code in a template is safe. |
{project} | The name of the project of the document in front (the name of the project's folder; see Build and Run). Nothing when that document belongs to no project. |
{description} | The project's description: the description line of the [project] section in the project's .unryu.conf. Nothing when there is none, or no project. |
{command:a shell command} | What the command prints, run with sh -c, with its last line end removed. Unryu stops the command after 5 seconds and keeps at most 64 KiB of its output. None of the shipped templates uses it. |
Preferences > Templates
The Templates page of Preferences has the eight fields that the wildcards use. Their first values come from your account:
| Field | First value |
|---|---|
| Developer | Your full name from the system's user database, or your user name if it has none. |
| Initials | The first letter of each word of the Developer name. |
| Mail address | user@hostname. |
| Company | Empty. |
| Initial version | 1.0. |
| Year | %Y |
| Date | %Y-%m-%d |
| Date & time | %d.%m.%Y %H:%M:%S %Z |
The templates that come with Unryu
Unryu ships 41 templates. Each one holds only what its language needs for a valid file. Optional lines, such as a script's strict mode or a different first line, are there as comments: remove the comment mark to use one. None of them has a copyright or license notice.
| Templates | What they give |
|---|---|
main.c, main.cpp, main.d, main.go, main.rs, main.kt, main.swift, main.scala, main.cs, main.m, main.vala, main.hs, main.ml, main.nim, main.jl, main.f90, main.R, program.pas | A program with its entry point. main.cs has a file-scoped namespace. program.pas is for Free Pascal ({$mode objfpc}). |
main.java | A compact source file: void main() with no class around it. It needs Java 25 or later. |
main.py, file.rb, main.js, main.ts, script.sh, script.pl, script.ps1 | A script. Every one except main.ts and script.ps1 starts with the full path of its interpreter (#!/bin/bash, #!/usr/bin/python3). The next line is a comment with the other usual first lines, for example #!/usr/bin/env bash or #!/bin/sh. The shell, Perl, Ruby and PowerShell scripts have their strict mode as comments: set -euo pipefail; use strict and use warnings; frozen_string_literal; Set-StrictMode and $ErrorActionPreference. |
file.php | PHP code only, with no closing ?>. declare(strict_types=1) is a comment. |
page.php | A PHP file that writes an HTML5 page. declare(strict_types=1) is a comment in its first PHP block. |
file.html, style.css, component.tsx, file.svg | An HTML5 page; an empty style sheet; a React function component; an SVG image. |
module.erl, module.lua, core.clj, module.sv | A module. module.sv is a SystemVerilog module with no ports. |
file.tex, README.md | A LaTeX article with an empty document; a README with Build, Usage and License headings. |
node.gd, sketch.ino, shader.frag | A Godot script, an Arduino sketch, a GLSL 3.3 fragment shader. |
Unryu has no comment templates. There is no file header, license notice, ChangeLog entry or function description to
insert, and {gpl}, {bsd}, {fileheader} and {functionname} are not
wildcards. Edit > Insert Comments has Insert Multiline Comment and Insert Documentation Comment (see Editing).
5. Opening files
There are several ways to open a file. Whichever you use, a file that is already open is not opened twice: Unryu brings its tab to the front. A file goes into the tab in front if that is an empty, unchanged "untitled" document; otherwise it gets a tab of its own. Each file that opens is added to the top of Recent Files, and the Status tab of the message window logs "File ... opened".
The Open dialog
File > Open (Ctrl+O) shows Unryu's own file dialog. It starts in the folder of the document in front. If that document has no file, it starts in the folder of Preferences > General > Paths > "Startup path", and if that is empty, in your home folder.
| Part of the dialog | What it does |
|---|---|
| Places, at the left | Home, Desktop, Documents, Downloads, Music, Pictures, Videos and File System. A click goes there. Below them are your favorites. |
| Favorites | Right-click the file list and choose Add to Favorites to add the folder you are in (at most eight). Right-click a favorite and choose Remove from Favorites to remove it. |
| The path bar, at the top | Shows the folder you are in as a row of folder names. Click a name to go to that folder. Click beside the names, or press Ctrl+L, to type a path instead: / starts from the root, ~ is your home folder, anything else is inside the folder you are in. Enter goes to a typed folder; in the Open dialog, the full path of a file opens that file at once. Escape gives the path bar back. |
| The file list | Folders first, then files. The ".." entry goes up one folder (from a folder just under the root, such as /home, it goes to /). A folder that cannot be opened (for example one you have no right to read) is not entered: the dialog stays where it was, and its status line gives the reason, such as "Couldn't open "/root": Permission denied". Columns: Name, Size, Type and Modified. Click a column heading to sort by it; click it again to reverse the order. Drag the edge between two headings to make a column wider or narrower. |
| The list's right-click menu | Show Hidden Files (also Ctrl+H; the status line of the dialog shows "Hidden: on" or "Hidden: off"), Size Column, Type Column and Modified Column (show or hide each column), and Add to Favorites. |
| The file type list | "All Files", "Plain Text", and one entry for each language Unryu knows, made from the extensions and file names in its language file. The list shows only the files of the type you choose. Unryu remembers the type you chose last, also after a restart. |
| Set encoding: | "Detect from file" (the default), or an encoding to read the chosen files in. The encodings are in groups; see section 7. With a chosen encoding, a file that cannot be read in it is not opened, and a message says why. |
| New Folder | Makes a folder in the folder you are in (also Ctrl+Shift+N). Type its name, then Create or Enter; Cancel or Escape stops. |
| OK and Cancel | OK opens the chosen file or files. With no file chosen, the dialog stays open and its status line says "Select a file" (in the Save dialog, with no name: "Type a name for the file"). Cancel or Escape closes the dialog and opens nothing. |
In the list, Up, Down, Page Up, Page Down, Home and End move the selection. Enter or a double-click goes into a folder, or opens a file. To open several files at once, select them with Ctrl+click or Shift+click: each one opens in its own tab, in the order you chose them. Ctrl+click on a selected file takes it out of the selection again.
The dialog remembers your favorites, the hidden-files switch, which columns show, their widths and the sort, in
~/.config/unryu/file_dialog.txt: every Open and Save dialog starts with them, also after a restart.
Recent Files and Recent Projects
File > Recent Files lists the files you opened or saved under a new name, the newest first. Each item shows
the file name, then its folder in brackets, with your home folder written as ~ and a long folder shortened
from the left with "...". Choose one to open it. A file that no longer exists leaves the list when you choose it; a file
that exists but cannot be opened stays in the list. The length of the list is Preferences > Files > Miscellaneous
> "Recent files list length" (10 at first, at most 50; 0 keeps no list). The item is greyed out while the list is
empty. Reopening the last session's tabs at startup does not count as using those files, so it does not change the
list.
The small arrow beside the toolbar's Open button shows the same list under the button. With no recent files it says "No recent files yet." in the status bar.
File > Recent Projects lists up to 16 projects that had files open when Unryu stopped, the most recent first (the project of the document that was in front at the last stop comes first). Older projects stay in the list until newer ones push them out. A project is the folder a file belongs to: the nearest folder above it that is a Git repository, or else the highest folder above it with a build file such as a Makefile (see Build and Run). Each item shows the project's name and, in brackets, its folder. Choosing one opens again the files that were open in that project, next to the documents already open; it closes nothing. A file that is gone is passed over; if none of the files is there, the status bar says "None of that project's files is there now." The item is greyed out while the list is empty.
Workbenches
A workbench is a named set of projects that you work on together, with its own session: the tabs that were open in it, the one in front, and the bookmarks (Ctrl+M) in each file. One workbench is open at a time, and its name shows in the window's title in square brackets.
A workbench holds two kinds of folder:
- Projects. These are the projects you chose. Unryu reads the code of each one (see below).
- Folders. A folder, such as the
~/Projectsfolder that holds all your projects, only shows its files in the Files tab. Unryu does not read its code. A folder inside it becomes a project of the workbench only when you add it, so you choose which ones count, one at a time.
A project inside a folder of the workbench shows once, in its place inside that folder, and not a second time on
its own. Adding a folder does not change which projects the workbench has. For example, with ~/Projects
as a folder and unryu, kami and xtk as projects, the Files tab shows the
~/Projects tree with those three marked in it, and Unryu reads the code of those three and of nothing
else in ~/Projects.
File > Workbench has:
- New Workbench... asks for a name. The new workbench starts with the project in front as its first project, and the tabs open now become its session. It is open at once.
- Add Project... adds a project to the open workbench. If the folder you choose is not already a project by
the rules of Build and Run, section 11 (for example, it has no
.git), adding it makes it one, as Tools > Set Project Folder does. - Add Folder... adds a folder to the open workbench, to show its files.
- Remove This Project takes the project in front out of the open workbench.
- Remove the Folder name takes out the folder of the workbench that holds the project in front. The projects inside it stay in the workbench, each shown on its own again.
- Close Workbench keeps its session as it is now and leaves no workbench open; the tabs stay.
- Delete Workbench... asks first, then forgets the open workbench: its folders, files and tabs stay as they are.
- Then each workbench by its name, the open one checked. Choosing another keeps the open one's session, closes every tab (asking about each that has unsaved changes), and opens the files of the one you chose, with its bookmarks. If you keep a tab open (Cancel), the workbench is not changed.
You can also add and remove projects from the Files tab. Right-click a folder there and choose Add to the Workbench as a Project or Take Out of the Workbench.
A workbench holds at most 32 projects and folders together. While a workbench is open, Unryu reads every project
of it, as it reads the project in front: Go to Definition (F12) finds a name that any of the
projects defines, the nearest file first and the project in front before the others, and Go to Anything and Go to
Symbol in the Project (Code Analysis) list their files and symbols, each after its
project's name. The Files tab in the sidebar shows the folder of the workbench that holds the project in front. Each
project and folder of the workbench that is not inside it stands at the top, as a tree of its own
(The Window). Unryu keeps the workbenches in
workbenches.txt, and when you quit with a workbench open, it is open again at the next start, with its
bookmarks on the tabs that come back.
Open Selected File
File > Open Selected File (Ctrl+Shift+O) opens the file whose name you selected in the
text. With no selection, it takes the file name around the cursor: letters, digits and the characters
_ . / - ~ +. A name that starts with / is a full path; ~/ is your home folder;
any other name is looked for in the folder of the document in front. If no such file exists, Unryu beeps and the status
bar says "Could not find file '...'." The jump is recorded, so Navigate > Back (Alt+Left)
returns to where you were.
Starting Unryu with files
You can name files when you start Unryu, for example unryu main.c notes.txt, or open files with Unryu
from a file manager. A relative name is taken from the folder you started Unryu in, so the build commands work in the
file's own folder. The only option Unryu knows is -i (or --new-instance), described below;
every other argument is a file name.
- A name that does not exist opens a new, empty document with that name. Save creates the file. If you turn off Preferences > Files > New files > "Open new documents from the command-line" (on at first), Unryu does not do this and the Status tab says "Could not find file '...'." instead.
- Unsaved text left behind for a named file is offered back once the window is up (see section 16).
One Unryu for each display
Normally only one Unryu runs on a display. When you start Unryu again with files, the new Unryu hands its files to the one that is running and ends at once; the running Unryu opens them and comes to the front. This is what makes a file manager's files all go into one window. Started again with no files, the new Unryu simply brings the running window to the front. If two are started at the same moment, one of them becomes the first and the other hands over. An Unryu that is already shutting down takes no files; the new one then starts as the first. While a dialog is open, including the quit questions, the files wait. If you then quit, Unryu first saves everything as usual and then starts again with those files, so they are opened all the same. If an earlier Unryu crashed, the new one notices that nothing answers and takes over.
- A second window. With Preferences > General > Startup > "Open a new window when Unryu already runs" (off at first), starting Unryu again with no file opens a second window with a new document. Files named on the command line still go to the first window.
unryu -i(or--new-instance) always starts an Unryu of its own and opens the named files in it. It does not take files from Unryus started later.- A second window does not load the files of the last session and does not write them when it closes: the session belongs to the first Unryu. All windows share the other settings files, and the one that stops last writes them.
What Unryu will not open
- A folder, a device, a FIFO or any other special file: "Could not open the file. ... is not a file that can be read."
- A file that has NUL bytes, or bytes that no encoding can read (a program, an image): "The file does not look like a text file." Saving such a file through a text editor would damage it. The only exception is a UTF-16, UTF-32 or UCS-2 file, where NUL bytes are part of normal characters.
- A file you have no permission to read: the message gives the reason from the system.
Dropping files on the window
You can drag files from a file manager and drop them anywhere on Unryu's window. Each file opens in a tab of its own,
just as if you had chosen it in File > Open, and you can drop several at once. Only files open. Each file:// item that
is a folder or does not exist is left out, and the Status tab says "Not opened: "..." is not a file." Items that are not
file:// addresses (web links, network places) are left out with no message. The host name in a
file:// address is not checked.
(Dragging text inside the editor is something else; see Editing.)
You can also open files from the sidebar: the Files tab shows the project's folder, and the Documents tab lists the open documents (see The Window).
6. What Unryu learns from a file when it opens it
The editor always holds the text as UTF-8 with a plain line feed (LF) at the end of each line. That way the highlighting, the search and the analysis all see one form of text. Unryu remembers how the file was written, and writes it back the same way when you save.
- The encoding is found as described in section 7, unless you chose one in the Open dialog or with Reload As.
- A byte order mark (BOM) at the start of the file is noted and removed from the text you see. Save writes it back. Document > Write Unicode BOM is checked for such a file.
- The line ending of the document is the one most lines of the file have. A file with no carriage returns is LF (Unix). See section 8 for files with mixed endings.
- The indentation. With Preferences > Editor > Indentation > "Detect type from file" or "Detect width from file" on (both off at first), Unryu looks at the text to see whether it is indented with tabs or spaces, and how wide one step is, and follows it. The Status tab then says, for example, "Setting Spaces indentation mode for ...". You can ask for the same thing later with Document > Indent Type > Detect from Content and Document > Indent Width > Detect from Content (see Editing).
- Settings in order. A document's settings come first from Preferences, then from the settings file in its
project's folder (
.unryu.conf, see Build and Run), then from what Unryu detects in the text, and last from what you set for this very file in the Document menu (next item). Each later source wins over the earlier ones. - Settings kept for each file. When you change Line Wrapping, Line Breaking, Auto-indentation, Indent Type,
Indent Width or Read Only in the Document menu, Unryu remembers that choice for that file in
file_settings.txt, and uses it every time the file opens again, also after a restart. Only the settings you changed are kept; the others still come from Preferences and the file. Unryu remembers this for up to 1,000 files, the most recently used first. Save As takes the remembered settings along to the new name.
7. Encodings and the byte order mark
An encoding is the way a file's bytes stand for characters. Most files today are UTF-8, but older files and files from other systems may be in Windows-1252, ISO-8859-15, Shift_JIS, UTF-16 and so on. Unryu knows 62 encodings (and "Without encoding") and offers each one that your system can convert.
How Unryu finds the encoding of a file
When you open a file with "Detect from file", Unryu tries these in order and takes the first that reads every byte of the file as valid text:
- A byte order mark at the start of the file: UTF-8, UTF-16, UTF-32 or UTF-7.
- UTF-8, unless the file says it is in another encoding.
- An encoding the file declares in its first 512 bytes: a
coding: latin-1orcoding=...line (as in Python and Emacs files), or an HTML<meta http-equiv="Content-Type" ... charset=...>. - The encoding of your locale (from
LC_ALL,LC_CTYPEorLANG), when it is not UTF-8. - Preferences > Files > Encodings > "Default encoding (existing non-Unicode files)", when you chose one ("Detect from file" at first).
- Each encoding of the list, in a fixed order, starting with the ISO-8859 family.
A result counts only if it is valid text with no NUL character in it. That is how a binary file is refused, and how a UTF-16 file without a BOM is still found. An empty file is UTF-8. The status bar shows the document's encoding next to its path, with "(with BOM)" when the file has a BOM.
The encoding menus
The encodings are shown in groups: West European, East European, East Asian, SE & SW Asian, Middle Eastern and Unicode, each a flyout with entries such as "Western (WINDOWS-1252)". The last entry, Without encoding, reads and writes the bytes exactly as they are, with no conversion.
- Document > Set Encoding sets the encoding that the next Save writes. The text you see does not change; only the bytes written to disk do. The dot shows the document's encoding. The document becomes unsaved, because the file on disk no longer matches. A read-only document refuses the change (with a beep, when Beep on errors is on).
- File > Reload As reads the file from disk again in the encoding you choose. Use it when a file was detected wrongly and its characters look garbled. If the document has unsaved changes, Unryu asks first, as Reload does. If the file cannot be read in that encoding, a message says "Failed to load file ... as ...", and the text stays as it was. Reload As is greyed out for a document with no file.
- Document > Write Unicode BOM adds or removes the byte order mark that the next Save writes. It works only for a Unicode encoding (UTF-8, UTF-16, UTF-32, UTF-7, UCS-2) and is greyed out for the others. The document becomes unsaved.
- The Open dialog's Set encoding list (section 5) has the same encodings, plus "Detect from file".
- Preferences > Files > Encodings has "Default encoding (new files)" (UTF-8 at first), used by File > New and the templates, and "Default encoding (existing non-Unicode files)", which detection tries as described above.
When the text does not fit the encoding
Save converts the text back from UTF-8 to the document's encoding. If a character cannot be written in that encoding (for example the euro sign in ISO-8859-1, or a Chinese character in Windows-1252), the save stops and nothing is written. A message says "An error occurred while converting the file from UTF-8 in ... The file remains unsaved." and shows the character with its line and column, so you can change it, or choose another encoding with Document > Set Encoding, and save again.
8. Line endings
A line ending is the invisible character or characters at the end of each line: LF on Unix and Linux, CR LF on Windows, and CR on old Macintosh systems. Inside Unryu every line ends with LF; the document remembers which ending the file uses, and Save writes that one.
- Document > Set Line Endings has three choices: "Convert and Set to CR/LF (Windows)", "Convert and Set to LF (Unix)" and "Convert and Set to CR (Classic Mac)". The dot shows the document's ending. Choosing one gives every line that ending at the next Save, and makes the document unsaved.
- A file with mixed line endings keeps them. The document's ending is the one most lines have; each line that has another ending keeps its own, also when you edit around it, and Save writes it back. To make all lines the same, use Set Line Endings, or turn on Preferences > Files > Saving files > "Ensure consistent line endings" (off at first), which gives every line the document's ending each time you save.
- New documents get Preferences > Files > New files > "Default end of line characters": Windows (CRLF), Classic Mac (CR) or Unix (LF). It is Unix (LF) at first.
- To see the endings, use View > Show Line Endings (see The Window); File > Properties also names the document's ending.
9. Saving
Save, Save As and Save All
- File > Save (Ctrl+S) writes the document to its file. A document with no file yet asks for a name, as Save As does.
- File > Save As asks for a new name in the Save dialog, writes the document there, and from then on the document belongs to the new file. The new name goes to the top of Recent Files.
- File > Save All (Ctrl+Shift+S) saves every document with unsaved changes, one after the other. A document with no file asks for a name. The document that was in front comes back to the front.
The Save dialog is the same as the Open dialog (section 5), with a Name field and without
the encoding list. The Name field offers the template name ("untitled.py") for a new document from a template. If you
type a folder in the Name field (.., ~/src, /tmp/), OK goes to that folder instead
of saving. If the name you chose already exists, a small menu asks "Overwrite" or "Cancel" before anything is
written.
What happens before the text is written
- Unryu compares the file on disk with what it last read or saved (its size, its inode number and its modification time, to the nanosecond). If another program changed the file in the meantime, it asks: "The file '...' on the disk is more recent than the current buffer. Do you want to overwrite it?" with Cancel (the default) and Overwrite. Cancel leaves the file alone and the text unsaved.
- A document that is Read Only is not saved: "Cannot save read-only document '...'!" (see section 12). This applies to Save As too. A read-only document is refused even after you answer Overwrite.
- The options of Preferences > Files > Saving files change the text, each as one step that Undo can take
back:
- "Strip trailing spaces and tabs" (off at first) removes spaces and tabs at the ends of lines;
- "Replace tabs with space" (off at first) turns each tab into spaces, by the document's indent width;
- "Strip trailing blank lines" (off at first) removes the empty lines, and lines of only spaces and tabs, at the end of the file, keeping the line end after the last line with text;
- "Ensure new line at file end" (on at first) adds a line ending after the last line if it has none.
- The text is converted to the document's encoding, line endings and BOM (sections 7 and 8).
How the file is written safely
Unryu never writes over your file in a way that could leave it half written. It writes the new text into a new file beside it, makes sure that file is on the disk, and only then puts it in the old file's place in one step. If anything goes wrong before that step, the old file is untouched.
When a save fails
If a save fails, a message "Error saving file." gives the reason from the system (for example "Permission denied" or "No space left on device") and tells you where things stand:
- usually "The file on disk is as it was. Your text is still here, unsaved.";
- after a failed write over the file itself, "The file may hold only part of the text. Its old text is kept in:"
followed by the path of the copy in
~/.cache/unryu/backup/.
In both cases your text stays in the editor, unsaved, and the status bar says "Not saved." A save that would go over the system's limit on file size fails with a message too; it does not end Unryu.
After a successful save the status bar says "File ... saved.", the * goes away, the recovery copy of the
document is removed (section 16), and the symbol list is brought up to date.
10. Reload and Reload As
File > Reload (Ctrl+R, or the Reload button) throws away the document's text and reads its file from disk again, in the document's encoding. It is for going back to the saved version, or picking up a change another program made. If the document has unsaved changes, Unryu asks "Are you sure you want to reload '...'? Any unsaved changes will be lost." with Cancel (the default) and Reload. It does not offer to save first, because saving would make the reload pointless. If the file cannot be read, a message says why and the text stays as it was. Reload does nothing for a document that has no file.
File > Reload As does the same in an encoding you choose; see section 7.
11. A file that changed on disk
Another program may change or delete a file while it is open in Unryu: a build that writes it, a version control command, another editor. Unryu checks the file every time its window gets the keyboard focus and every time you bring a tab to the front. While the window has the focus, it also checks every "Disk check timeout" seconds (Preferences > Files > Miscellaneous, 30 at first, from 0 to 60). Setting the timeout to 0 turns all of these checks off. A check costs almost nothing, so Unryu sees a change as soon as you come back to it, however quickly that is. The check waits until the panels show the document, so the question is clearly about the document in front.
Apart from these checks, Save itself always compares the file before it writes (section 9), so a change is never overwritten without a question even with the checks turned off.
12. Read Only
Document > Read Only protects a document from changes. While it is checked, the editor refuses typing and other edits, Save and Save As refuse with "Cannot save read-only document '...'!", and Document > Set Encoding refuses (with a beep, when Beep on errors is on). Uncheck it to edit again. Unryu remembers Read Only for each file (section 6), so a file you marked read-only opens read-only next time too. File > Properties shows whether a document is read-only.
Read Only is Unryu's own setting and does not change the file's permissions. A file that you have no permission to write to opens normally; saving it then fails with "Permission denied", and your text stays unsaved.
13. Properties
File > Properties shows an Information box, headed with the file name ("This text" for a document with no file), with facts about the document in front:
| Line | What it shows |
|---|---|
| Type | The language of the document. |
| Size | The size of the file on disk in bytes; "not saved" for a document with no file; "not on the disk" when the file has gone. |
| Location | The folder of the file, or "(none)". |
| Read-only | Yes or No: the Document > Read Only setting. |
| Encoding | The document's encoding, with "(with BOM)" when it has one. |
| Line endings | CRLF (Windows), LF (Unix) or CR (Classic Mac). |
| Modified, Changed, Accessed | When the file's content was last changed, when its details (such as permissions) were last changed, and when it was last read, in your locale's date format. |
| Permissions | What the owner, the group and others may do, for example "Owner rw-, Group r--, Other r--". |
14. Closing and quitting
- File > Close (Ctrl+W), or the close button on a tab, closes a document. If it has unsaved changes, Unryu asks "The file '...' is not saved. Do you want to save it before closing it?" with Cancel, Don't save and Save (the default). If the save fails or you cancel, the document stays open. After a tab closes, the tab beside it comes to the front, or, with Preferences > Interface > Notebook tabs > "Switch to last used document after closing a tab", the document you used before.
- File > Close Other Documents closes every document except the one in front, and File > Close All (Ctrl+Shift+W) closes them all. Each document with unsaved changes asks the same question, in its own tab, so you can see what you are deciding about. Cancel stops at that document and leaves it and the ones not reached yet open.
- File > Quit (Ctrl+Q), or closing the window, ends Unryu. With Preferences > General > Shutdown > "Confirm exit" on (off at first), it asks "Do you really want to quit?" first. Then each document with unsaved changes asks "Do you want to save it before quitting?", starting with the one in front; Cancel stops the quit. A compiler check or a build that is still running is stopped, so quitting never waits for one.
When Unryu quits, it writes down the open tabs for the next start (next section), the layout of the panels, and the size and place of the window (Preferences > General > Shutdown > "Save window size" and "Save window position", both on at first; see The Window). Choosing "Don't save" throws the text away: its recovery copy is removed too.
15. Reopening the last session
With Preferences > General > Startup > "Load files from the last session" on (it is on at first), Unryu reopens at startup the files that were open when it last stopped, in the same order, with the one that was in front in front again.
- Each file is read in the encoding it had last time. If that no longer works (the file changed), Unryu finds the encoding again.
- A Markdown document that showed its source (the Plain Text switch of its toolbar) shows its source again.
- A file that has been removed or renamed since is passed over without a message.
- A document with no file is not part of the session. Its text, if any, is kept as a recovery copy instead, and offered at the start (next section).
- The tab placement settings do not apply to these tabs, and they are not added to Recent Files.
- Files named on the command line open as well, after the session's files.
- The list is written when Unryu stops, normally or because the system ends the session (a logout). After a crash or a lost connection to the X server, the list from the time before is used.
- A second window (section 5) neither reads nor writes the session.
16. Recovery copies after a crash
While a document has unsaved changes, Unryu keeps a copy of its text in ~/.cache/unryu/recovery/. You
do not need to do anything for this. If Unryu ends without saving (a crash, the program being killed, the computer
losing power, the X server going away), the text is still there the next time Unryu starts.
When Unryu makes a copy
- 2 seconds after you stop typing, and at least every 30 seconds while you keep typing;
- just before any dialog or question opens, because a dialog can stay open a long time;
- when you switch to another document (a document in the background is not timed, so it is copied as you leave it);
- when the connection to the X server is lost, which is usually a logout;
- when the system tells Unryu to stop (the signals SIGTERM, SIGHUP and SIGINT, as at a logout or shutdown). Unryu then stops without asking questions and keeps the unsaved text for next time. If a dialog is open at that moment, Unryu ends after 5 seconds; the copy made when the dialog opened stays. A second such signal ends Unryu at once.
Unryu does not write a copy when it crashes. After a crash, the text in memory may be the very thing that is broken, and it must not replace the last good copy. When you undo back to the saved text, save the document, or close it with "Don't save", its copy is removed.
If a copy cannot be made (a full disk, for example), the Details panel shows an "Unsaved Text" section: "No recovery copy: the reason. A crash now would lose what is not saved, so save your work." Unryu tries again after 30 seconds.
Getting the text back
Unryu offers a copy once its window is on the screen:
- at startup with no file named, any copy that a stopped Unryu left behind, the newest first;
- at startup with files named, the copies of those files;
- each time you open a file that has a copy.
It is not offered while the document already has unsaved changes. The question reads "Unsaved text was left behind when Unryu last stopped.", followed by the file's path (or "A text with no file yet."), "Kept" and the date and time of the copy, and, when it applies, "The file is no longer there." or "The file on disk has changed since then." The buttons are:
| Button | What it does |
|---|---|
| Recover (the default) | Puts the text back. The text of a file goes into that file's tab, never over another document; a text with no file gets a new tab; if the file is gone, a new tab with the file's name is made, and saving writes the file again. Unryu then also says "Could not open the file." and may ask whether to save the file again; that is expected: the text is in the new tab. |
| Keep for Later | Leaves the copy where it is; it is offered again next time. Escape does the same, so a key press never throws text away. |
| Discard | Deletes the copy. If more copies are waiting, the next one is offered. |
The recovered text goes in as one edit over the text on disk. So the document is unsaved, Undo shows you exactly what was different, and the cursor is at the first difference. The Details panel says "Recovered, and not saved yet. Undo goes back to the file on disk." Unryu also keeps the copy's record of what the file looked like on disk, so if the file changed since, your next Save still asks before overwriting it. The old copy is removed only after a new copy of the recovered text is safely on disk.
A copy whose text is the same as the file on disk, or a copy of an empty text with no file, says nothing new and is removed without a question. (This check compares bytes, so for a file with CR LF line endings, a byte order mark or an encoding other than UTF-8, such a copy is still offered; Discard it.)
~/.cache/unryu/recovery/. The folder can be opened only by you, and each
copy is a file that only you can read.- A copy stays until you recover it, discard it, or save over it. Unryu never deletes a copy because it is old.
- A half-written file left by a crash in the middle of writing a copy is removed. A file in the folder that Unryu cannot read as a copy is ignored, not deleted.
Unryu never writes a NUL character into a copy, since a document cannot hold one. If a copy was damaged so that it holds one, its text cannot be put back in full: Unryu then says "Could not put all of the text back. The copy is kept in:" with the path of the copy, and leaves the copy in the recovery folder, where you can rescue it by other means.
17. Printing and Page Setup
File > Print (Ctrl+P) prints the document in front, as it is in the editor, including unsaved changes. How it prints is set in Preferences > Printing:
- "Use native printing (PostScript, to lp or to a file)" (the default): Unryu lays out the pages itself and shows the Print dialog.
- "Use an external command for printing": Unryu runs the "Command:" you give (
lpr %fat first) with no dialog.%fbecomes the name of the file, quoted for the shell. When the document has unsaved changes or no file,%fis instead a copy of the text under the same name, in a new private folder in$XDG_RUNTIME_DIR(or/tmp). The copy is written as saving would write it (the document's encoding, line endings and byte order mark; in UTF-8 if the text does not fit the encoding), but without the changes of Preferences > Files > Saving files. Unryu removes the copy and its folder when the command ends. The Status tab says "File ... sent to the printing command.", or that printing failed.
The Print dialog
| Group | Control | What it does |
|---|---|---|
| Printer | Printer | The printers of your system (CUPS, found with lpstat), and "Print to File". At first the system's default printer is chosen; after that, the one you chose last in this session. With no printer found, a note says "No printer was found: the pages go into a file." |
| Copies | 1 to 99. Only for a printer. | |
| File format | PDF or PostScript. Only for Print to File. | |
| Range | All Pages, Current Page, Pages: | Every page; the page that holds the cursor; or the pages you type, as numbers and ranges such as 1-3, 7, 11- (11- means page 11 to the end). Page numbers are those of the whole document. |
| Page Setup | Paper size | A4, Letter, Legal, A3 or A5. |
| Orientation | Portrait or Landscape. | |
| Document Setup | Print line numbers | Each line's number in front of it. |
| Print page numbers | "Page 2 of 5" on each page: at the right of the header, or centered at the foot when there is no header. | |
| Print page header | A header line on each page with the file name at the left, the date in the middle and the page number at the right, and a rule under it. A name too long for the room is shortened from the left with "...". | |
| Use the basename of the printed file | Only the file's name in the header, not its full path. Available only with the header. | |
| Print in color | The editor's highlighting in color, with colors too pale for white paper darkened and plain text black. Off prints black and white. It is greyed out when there is no highlighting to print (highlighting turned off, an empty document, or a change that has not been analysed yet). | |
| Wrap long lines | A line too long for the paper continues on the next rows. Off cuts it at the margin. | |
| Do not split words | A wrapped line breaks between words, not in the middle of one. Available only with Wrap long lines. | |
| Date format | The date in the header, as a strftime format; %c (the default) is your locale's usual date and time. Empty prints no date. Available only with the header. | |
| Preview | Previous, Next | A picture of each page exactly as it will print, with "Page N of M" between the buttons. It follows every change in the dialog at once. |
Print prints and Cancel closes the dialog. Every choice in the dialog except the printer, the copies and the range is kept as your print preferences for next time. If the Pages field holds anything other than numbers, commas, dashes and spaces, the Status tab says "The pages to print are not numbers and ranges (1-3, 7, 11-)." and nothing prints; if none of the pages asked for exists, it says "No page of the document is in the pages asked for."
Where the pages go
- To a printer: as PostScript to
lp, or tolprwhenlpis not installed. The Status tab says "File ... printed (3 pages) on ...", or that printing failed. With neither program installed, it says "Neither lp nor lpr is installed: nothing can print." - Print to File: a Save dialog titled "Print to File" asks for the name, offering the document's name with
.pdfor.ps. The Status tab says "The pages are in ...".
How the pages look
The text is set in the printing font, with half-inch margins. The font is Preferences > Interface > Fonts > Printing: at first the Editor's font at 9 points. Any font can be chosen; the list shows the monospace fonts first.
- Every character the font has prints. A character it lacks (Chinese in a Latin font, say) comes from another font installed on your system that has it, as on screen. Only a character that no installed font has prints as the font's empty box.
- Each character takes its own column, the width of the font's
0, and a wide character (Chinese, Japanese, Korean) takes two. So the columns of your code stay lined up, whatever the font. - A tab goes to the next tab stop of the document's indent width (8 columns for "Tabs and Spaces" indentation). A form feed character in the text starts a new page.
- Each character is drawn from the outline of its letter in the font, so a printer needs no fonts of its own and a PDF holds no font files. A PDF also holds the text itself, invisible over the drawing, so you can search it and copy from it.
Page Setup and Preferences > Printing
File > Page Setup opens the same dialog without the Range group, with OK in place of Print. OK keeps the paper, the orientation and the other choices as your print preferences, and the status bar says, for example, "Page Setup: A4, portrait."
Preferences > Printing holds the choice between the external command and native printing, the Command, and Print line numbers, Print page numbers, Print page header, Use the basename of the printed file and Date format, which are the same settings as in the Print dialog. The printing font and its size are in Preferences > Interface > Fonts. At first, line numbers, page numbers, the header, color and wrapping without splitting words are on, the base name is off, the paper is A4 portrait, and Print to File makes PDF. See Preferences.
18. The files Unryu keeps
Unryu keeps its settings in ~/.config/unryu/ and its safety copies in ~/.cache/unryu/. When
the environment variable XDG_CONFIG_HOME is set, it replaces ~/.config; when
XDG_CACHE_HOME is set, it replaces ~/.cache. Unryu makes the folders when it needs them. Tools
> Configuration Files opens the main settings files in a tab, and Tools > Reload Configuration reads them all
again after you edited them by hand.
| File or folder | What it holds |
|---|---|
| The program's own files | The language files, editor themes, templates, icons, the terminal's shell integration scripts and this manual. An installed Unryu (make install, or a package) has the program in <prefix>/bin and these files in <prefix>/share/unryu. An Unryu run from its build folder finds them beside it. |
~/.config/unryu/unryu.conf | Your Preferences, the chosen themes and fonts, the file type last chosen in the Open dialog, and what the Find, Replace and Find in Files dialogs remember. See Preferences. |
terminal.conf | The settings of the Terminal tab (see The Window). |
code_tools.conf | Tools > Code Tools, once you changed the list in Preferences > Tools > Code tools (see Build and Run). |
~/.config/xtk/icons.conf | The icon theme of every program built on xtk that does not choose its own (Preferences > Interface > Themes > Icons of all xtk programs; see Themes). It is not in Unryu's folder: the other xtk programs read it too. |
keybindings.conf | The keys you changed in Preferences > Keybindings (see Keyboard Shortcuts). |
build.conf, projects.conf | Your build commands, and your corrections of which folders are projects and which project folders' own commands you approved (see Build and Run). |
snippets.conf | Your own snippets (see Editing). |
documentation.conf | Your own commands for Help > Look Up Documentation (see The Window). |
words.txt | The words you added to the spelling dictionary, a word a line (see Editing). |
open_files.txt | The session: the tabs that were open when Unryu stopped, one full path a line, the one in front marked with * . After each path, separated by a tab character, comes its encoding, and plain for a Markdown document that showed its source (section 15). |
recent_files.txt | File > Recent Files: one full path a line, the newest first. |
recent_projects.txt | File > Recent Projects: each project's folder in square brackets, then the full paths of the files that were open in it. |
workbenches.txt | File > Workbench: each workbench's name in square brackets, then a line for each of its projects (folder) and each of its plain folders (tree), each open file (file, or front for the one in front), and each file's bookmarked lines (marks, the path, then the line numbers). |
marked-folders.txt | The Files tab's marked folders: one full path a line. |
file_settings.txt | The Document menu settings you chose for each file: wrapping, line breaking, auto-indentation, indent type, indent width and read only; at most 1,000 files, the most recently used first (section 6). |
file_dialog.txt | What the Open and Save dialogs remember: the favorites, the hidden-files switch, the columns, their widths and the sort (section 5). |
dock_layout.txt, window.txt | The arrangement of the panels, and the size, place and maximized state of the window (see The Window). |
templates/ | Your file templates (section 4). |
editor_themes/, themes/, languages/ | The editor themes, the window themes and your language files. See Themes and Languages. |
.shipped in templates/, editor_themes/ and languages/ | The names of the files that came with Unryu and were copied into that folder. Unryu copies each file that comes with it into your folder once: a file you delete stays deleted, and a file new in a later version is copied in the first time that version runs. A folder made by a version of Unryu before this list gets each missing file once more, so a file you deleted from it can come back that one time. |
~/.cache/unryu/recovery/ | The recovery copies of unsaved text (section 16). |
~/.cache/unryu/backup/ | The copy of a file's old text that Unryu makes before it has to write over a file in place (section 9). It is removed again once the save succeeds. |
.unryu.conf in a project's folder | Optional settings for one project, such as its indentation and build commands. Unryu never makes this file by itself; Tools > Save Project Settings in Folder writes it when you ask (see Build and Run). |
$XDG_RUNTIME_DIR/unryu-display.socket | How a second Unryu hands its files to the running one (section 5). In /tmp when XDG_RUNTIME_DIR is not set. |
The ~/.cache/unryu folders are private: only you can open them, and each recovery and backup copy can be
read only by you, because they hold copies of your work.
Every one of these files is written with the safe save of section 9: the new text goes into a temporary file beside it, which takes the old one's place only once it is whole. A crash at the very moment a file is written leaves the old file as it was.
Tools > Save Project Settings in Folder will not write .unryu.conf while the project has build commands
in it that you have not approved, so that they are not lost: approve them first (Tools > Approve Project Build
Commands), or edit the file yourself.