nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/2] possible new feature : allow specifying a custom nanorc file


From: Benno Schulenberg
Subject: [PATCH 1/2] possible new feature : allow specifying a custom nanorc file on the command line
Date: Tue, 14 Jan 2020 16:24:29 +0100

This fulfills https://savannah.gnu.org/bugs/?57547.
Requested-by: Saagar Jha <address@hidden>
---
 src/global.c |  3 +++
 src/nano.c   | 12 +++++++++++-
 src/proto.h  |  3 +++
 src/rcfile.c |  8 +++++++-
 4 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/src/global.c b/src/global.c
index 87715940..dc8b9b48 100644
--- a/src/global.c
+++ b/src/global.c
@@ -249,6 +249,9 @@ char *statedir = NULL;
 char *startup_problem = NULL;
                /* An error message (if any) about nanorc files or history 
files. */
 #endif
+#ifdef ENABLE_NANORC
+char *custom_nanorc = NULL;
+#endif
 
 bool spotlighted = FALSE;
        /* Whether any text is spotlighted. */
diff --git a/src/nano.c b/src/nano.c
index 08581be2..051ab9ce 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -635,6 +635,10 @@ void usage(void)
        print_opt("-d", "--rebinddelete",
                                        N_("Fix Backspace/Delete confusion 
problem"));
        print_opt("-e", "--emptyline", N_("Keep the line below the title bar 
empty"));
+#ifdef ENABLE_NANORC
+       print_opt(_("-f <file>"), _("--rcfile=<file>"),
+                                       N_("Use only this file for configuring 
nano"));
+#endif
 #ifdef ENABLE_BROWSER
        if (!ISSET(RESTRICTED))
                print_opt("-g", "--showcursor", N_("Show cursor in file browser 
& help text"));
@@ -1779,6 +1783,9 @@ int main(int argc, char **argv)
                {"constantshow", 0, NULL, 'c'},
                {"rebinddelete", 0, NULL, 'd'},
                {"emptyline", 0, NULL, 'e'},
+#ifdef ENABLE_NANORC
+               {"rcfile", 1, NULL, 'f'},
+#endif
 #ifdef ENABLE_BROWSER
                {"showcursor", 0, NULL, 'g'},
 #endif
@@ -1887,7 +1894,7 @@ int main(int argc, char **argv)
 
        while ((optchr =
                getopt_long(argc, argv,
-                               
"ABC:DEFGHIJ:KLMNOPQ:RST:UVWX:Y:Zabcdeghijklmno:pr:s:tuvwxyz$",
+                               
"ABC:DEFGHIJ:KLMNOPQ:RST:UVWX:Y:Zabcdef:ghijklmno:pr:s:tuvwxyz$",
                                long_options, NULL)) != -1) {
                switch (optchr) {
 #ifndef NANO_TINY
@@ -2027,6 +2034,9 @@ int main(int argc, char **argv)
                        case 'e':
                                SET(EMPTY_LINE);
                                break;
+                       case 'f':
+                               custom_nanorc = mallocstrcpy(custom_nanorc, 
optarg);
+                               break;
                        case 'g':
                                SET(SHOW_CURSOR);
                                break;
diff --git a/src/proto.h b/src/proto.h
index 2ae8f827..07cfb0f8 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -175,6 +175,9 @@ extern char *statedir;
 #if defined(ENABLE_NANORC) || defined(ENABLE_HISTORIES)
 extern char *startup_problem;
 #endif
+#ifdef ENABLE_NANORC
+extern char *custom_nanorc;
+#endif
 
 extern bool spotlighted;
 extern size_t light_from_col;
diff --git a/src/rcfile.c b/src/rcfile.c
index ddbed507..11f9c760 100644
--- a/src/rcfile.c
+++ b/src/rcfile.c
@@ -1647,11 +1647,16 @@ void do_rcfiles(void)
 {
        const char *xdgconfdir;
 
+       if (custom_nanorc)
+               nanorc = custom_nanorc;
+       else
+               nanorc = mallocstrcpy(nanorc, SYSCONFDIR "/nanorc");
+
        /* First process the system-wide nanorc, if it exists and is suitable. 
*/
-       nanorc = mallocstrcpy(nanorc, SYSCONFDIR "/nanorc");
        if (is_good_file(nanorc))
                parse_one_nanorc();
 
+       if (custom_nanorc == NULL) {
        get_homedir();
        xdgconfdir = getenv("XDG_CONFIG_HOME");
 
@@ -1663,6 +1668,7 @@ void do_rcfiles(void)
                parse_one_nanorc();
        else if (homedir == NULL && xdgconfdir == NULL)
                jot_error(N_("I can't find my home directory!  Wah!"));
+       }
 
        check_vitals_mapped();
 
-- 
2.24.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]