2 * Copyright Neil Brown ©2015-2021 <neil@brown.name>
3 * May be distributed under terms of GPLv2 - see file:COPYING
20 static char WelcomeText[] =
22 "Welcome to 'edlib' - a document editor that comes in well defined pieces.\n"
24 "Current functionality includes:\n"
25 " splitting and closing windows (C-x 0,1,2,3)\n"
26 " Resize current window (C-x },{,^)\n"
27 " Move among windows (C-x o,O or mouse click)\n"
28 " Opening a file or directory (C-x C-f)\n"
29 " TAB performs file-name completion in a menu\n"
30 " Save files - current one (C-x C-s) or all (C-x s)\n"
31 " Open a document by name (C-x b) - with TAB completion\n"
32 " Open a file or document in another pane (C-x 4 C-f,b)\n"
33 " Kill the current document (C-x k)\n"
34 " Movement by char, word, line, page, start/end file (standard emacs keys)\n"
35 " Insert/delete text\n"
36 " C-_ to undo and redo changes\n"
37 " C-s to search (incrementally) in text document\n"
38 " Visit list of documents (C-x C-b)\n"
39 " Open file from directory list, or document from document list ('f').\n"
40 " Open file in 'hex' view from directory listing ('h').\n"
41 " Numeric prefixes with M-0 to M-9.\n"
42 " Run make (C-c C-m) or grep (M-x grep Return)\n"
44 "And C-x C-c to close - type 's' to save or '%' to not save in the pop-up\n"
45 "Mouse clicks move the cursor, and clicking on the scroll bar scrolls\n"
48 static char shortopt[] = "gtx";
50 int main(int argc, char *argv[])
52 struct pane *ed = editor_new();
53 struct pane *first_window = NULL;
54 struct pane *p, *doc = NULL;
55 bool gtk = False, term = False, x11 = False;
61 while ((opt = getopt(argc, argv, shortopt)) != EOF) {
65 case 't': term = True;
70 fprintf(stderr, "Usage: edlib [-g] [-t] [file ...]\n");
74 if (!gtk && !term && !x11)
77 setlocale(LC_ALL, "");
78 setlocale(LC_CTYPE, "enUS.UTF-8");
80 call("attach-doc-docs", ed);
81 call("global-load-module", ed, 0, NULL, "lib-linecount");
82 call("global-load-module", ed, 0, NULL, "lib-search");
83 call("global-load-module", ed, 0, NULL, "lib-popup");
84 call("global-load-module", ed, 0, NULL, "lang-python");
85 call("global-load-module", ed, 0, NULL, "doc-text");
86 call("global-load-module", ed, 0, NULL, "doc-dir");
87 call("global-load-module", ed, 0, NULL, "render-hex");
88 call("global-load-module", ed, 0, NULL, "render-present");
89 call("global-load-module", ed, 0, NULL, "render-lines");
90 call("global-load-module", ed, 0, NULL, "module-notmuch");
91 call("global-load-module", ed, 0, NULL, "doc-email");
92 call("global-load-module", ed, 0, NULL, "lib-viewer");
93 call("global-load-module", ed, 0, NULL, "lib-qprint");
94 call("global-load-module", ed, 0, NULL, "lib-copybuf");
95 call("global-load-module", ed, 0, NULL, "lib-colourmap");
96 call("global-load-module", ed, 0, NULL, "lib-textfill");
97 call("global-load-module", ed, 0, NULL, "lib-autosave");
98 call("global-load-module", ed, 0, NULL, "render-format");
100 call("global-load-module", ed, 0, NULL, "render-c-mode");
101 call("global-load-module", ed, 0, NULL, "lib-make");
102 call("global-load-module", ed, 0, NULL, "lib-server");
103 call("global-load-module", ed, 0, NULL, "lib-utf8");
104 call("global-load-module", ed, 0, NULL, "lib-charset");
106 call("global-load-module", ed, 0, NULL, "config");
108 while (optind < argc) {
109 char *file = argv[optind++];
110 int fd = open(file, O_RDONLY);
112 /* '4' says 'allow create' */
113 doc = call_ret(pane, "doc:open", ed, -1, NULL, file, 4);
115 doc = call_ret(pane, "doc:open", ed, fd, NULL, file);
121 doc = call_ret(pane, "doc:from-text", ed, 0, NULL,
122 "*Welcome*", 0, NULL, WelcomeText);
124 fprintf(stderr, "edlib: cannot create default document.\n");
129 char *TERM = getenv("TERM");
131 p = call_ret(pane, "attach-display-ncurses", ed,
132 0, NULL, "-", 0, NULL, TERM);
135 e = getenv("SSH_CONNECTION");
137 attr_set_str(&p->attrs, "REMOTE_SESSION", "yes");
139 attr_set_str(&p->attrs, "DISPLAY", getenv("DISPLAY"));
140 p = call_ret(pane, "editor:activate-display", p);
143 p = home_call_ret(pane, doc, "doc:attach-view",
148 call("Display:set-noclose", p, 1, NULL,
149 "Cannot close primary display");
153 p = call_ret(pane, "attach-display-gtk",
154 ed, 0, NULL, getenv("DISPLAY"));
156 p = call_ret(pane, "editor:activate-display", p);
158 p = home_call_ret(pane, doc, "doc:attach-view",
165 p = call_ret(pane, "attach-display-x11",
166 ed, 0, NULL, getenv("DISPLAY"));
168 p = call_ret(pane, "editor:activate-display", p);
170 p = home_call_ret(pane, doc, "doc:attach-view",
177 call("global-multicall-startup-", first_window);
178 time_start(TIME_REFRESH);
180 time_stop(TIME_REFRESH);
181 while (call("event:run", ed) == 1) {
182 time_start(TIME_IDLE);
183 call("global-multicall-on_idle-", ed);
184 time_stop(TIME_IDLE);
185 time_start(TIME_REFRESH);
187 time_stop(TIME_REFRESH);
190 fprintf(stderr, "edlib: cannot create a display\n");