]> git.neil.brown.name Git - edlib.git/commitdiff
Move welcome text into a separate file.
authorNeilBrown <neil@brown.name>
Fri, 25 Aug 2023 00:44:02 +0000 (10:44 +1000)
committerNeilBrown <neil@brown.name>
Fri, 25 Aug 2023 05:35:31 +0000 (15:35 +1000)
This makes it easier to edit the welcome text, and to have different
welcome text for different editors.

Signed-off-by: NeilBrown <neil@brown.name>
DOC/TODO.md
data/Welcome-edlib.txt [new file with mode: 0644]
edlib.c

index 4252eb7c1929f159465937fbc7665b80a0429b00..a7f360ecff446ad49fd9ad2181fc55d0f3e606b6 100644 (file)
@@ -48,7 +48,7 @@ the file.
 - [ ] Review the options for editing a merge - it doesn't always do what
       I want.  Maybe have a menu of choices to remind me
 - [ ] Teach render-lines to pad spaces to left/right align text
-- [ ] Store welcome page in a separate document
+- [X] Store welcome page in a separate document
 - [ ] revise *Welcome* page
 - [ ] history doesn't restore initial default (or empty) string when
       returning after excursion into history or favourites.
diff --git a/data/Welcome-edlib.txt b/data/Welcome-edlib.txt
new file mode 100644 (file)
index 0000000..00ad06f
--- /dev/null
@@ -0,0 +1,25 @@
+
+Welcome to 'edlib' - a document editor that comes in well defined pieces.
+
+Current functionality includes:
+  splitting and closing windows (C-x 0,1,2,3)
+  Resize current window (C-x },{,^)
+  Move among windows (C-x o,O  or mouse click)
+  Opening a file or directory (C-x C-f)
+    TAB performs file-name completion in a menu
+  Save files - current one (C-x C-s) or all (C-x s)
+  Open a document by name (C-x b) - with TAB completion
+  Open a file or document in another pane (C-x 4 C-f,b)
+  Kill the current document (C-x k)
+  Movement by char, word, line, page, start/end file (standard emacs keys)
+  Insert/delete text
+  C-_ to undo and redo changes
+  C-s to search (incrementally) in text document
+  Visit list of documents (C-x C-b)
+  Open file from directory list, or document from document list ('f').
+  Open file in 'hex' view from directory listing ('h').
+  Numeric prefixes with M-0 to M-9.
+  Run make (C-c C-m) or grep (M-x grep Return)
+
+And C-x C-c to close - type 's' to save or '%' to not save in the pop-up
+Mouse clicks move the cursor, and clicking on the scroll bar scrolls
diff --git a/edlib.c b/edlib.c
index 2a60580e4077738931deb2806050badad8df4276..9955a8e8c83e8ef8d4d11263bd2afa039c3fba94 100644 (file)
--- a/edlib.c
+++ b/edlib.c
 #include "core.h"
 #include "misc.h"
 
-static const char WelcomeText[] =
-       "\n"
-       "Welcome to 'edlib' - a document editor that comes in well defined pieces.\n"
-       "\n"
-       "Current functionality includes:\n"
-       "  splitting and closing windows (C-x 0,1,2,3)\n"
-       "  Resize current window (C-x },{,^)\n"
-       "  Move among windows (C-x o,O  or mouse click)\n"
-       "  Opening a file or directory (C-x C-f)\n"
-       "    TAB performs file-name completion in a menu\n"
-       "  Save files - current one (C-x C-s) or all (C-x s)\n"
-       "  Open a document by name (C-x b) - with TAB completion\n"
-       "  Open a file or document in another pane (C-x 4 C-f,b)\n"
-       "  Kill the current document (C-x k)\n"
-       "  Movement by char, word, line, page, start/end file (standard emacs keys)\n"
-       "  Insert/delete text\n"
-       "  C-_ to undo and redo changes\n"
-       "  C-s to search (incrementally) in text document\n"
-       "  Visit list of documents (C-x C-b)\n"
-       "  Open file from directory list, or document from document list ('f').\n"
-       "  Open file in 'hex' view from directory listing ('h').\n"
-       "  Numeric prefixes with M-0 to M-9.\n"
-       "  Run make (C-c C-m) or grep (M-x grep Return)\n"
-       "\n"
-       "And C-x C-c to close - type 's' to save or '%' to not save in the pop-up\n"
-       "Mouse clicks move the cursor, and clicking on the scroll bar scrolls\n"
-       ;
-
 static const char shortopt[] = "gtx";
 
 int main(int argc, char *argv[])
@@ -94,9 +66,33 @@ int main(int argc, char *argv[])
                }
        }
 
-       if (!doc)
+       if (!doc) {
+               char *welcome_file = call_ret(str, "xdg-find-edlib-file", ed,
+                                             0, NULL, "Welcome-edlib.txt",
+                                             0, NULL, "data");
+               char *WelcomeText = NULL;
+               if (welcome_file) {
+                       int fd = open(welcome_file, O_RDONLY);
+                       if (fd >= 0) {
+                               int len = lseek(fd, 0, SEEK_END);
+                               lseek(fd, 0, SEEK_SET);
+                               if (len > 0 && len < 10000) {
+                                       WelcomeText = malloc(len+1);
+                                       read(fd, WelcomeText, len);
+                                       WelcomeText[len] = 0;
+                               }
+                               close(fd);
+                       }
+                       free(welcome_file);
+               }
+
+               if (!WelcomeText)
+                       WelcomeText = strdup("Welcome.\n");
+
                doc = call_ret(pane, "doc:from-text", ed, 0, NULL,
                               "*Welcome*", 0, NULL, WelcomeText);
+               free(WelcomeText);
+       }
        if (!doc) {
                fprintf(stderr, "edlib: cannot create default document.\n");
                exit(1);