nano-devel
[Top][All Lists]
Advanced

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

[PATCH] options: allow disabling the use of magic with --nomagic / 'set


From: Benno Schulenberg
Subject: [PATCH] options: allow disabling the use of magic with --nomagic / 'set nomagic'
Date: Sun, 6 Sep 2020 15:24:39 +0200

Most distros do not configure nano with --disable-libmagic, but trying
to determine which syntax to apply with the help of libmagic can be a
somewhat time-consuming and yet often still fruitless affair.  Allow
the user to tell nano not to waste time with libmagic when it can't
determine the applicable syntax from the file's name or first line.

The short form of the option is -. because we have run out of letters.

This fulfills https://savannah.gnu.org/bugs/?59028.
---
 src/color.c       | 4 ++--
 src/definitions.h | 3 ++-
 src/nano.c        | 9 ++++++++-
 src/rcfile.c      | 1 +
 4 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/color.c b/src/color.c
index cc0a5f2d..ecdce999 100644
--- a/src/color.c
+++ b/src/color.c
@@ -189,8 +189,8 @@ void find_and_prime_applicable_syntax(void)
        }
 
 #ifdef HAVE_LIBMAGIC
-       /* If we still don't have an answer, try using magic. */
-       if (sntx == NULL && !inhelp) {
+       /* If we still don't have an answer, try using magic (if not disabled). 
*/
+       if (sntx == NULL && !inhelp && !ISSET(NO_MAGIC)) {
                struct stat fileinfo;
                magic_t cookie = NULL;
                const char *magicstring = NULL;
diff --git a/src/definitions.h b/src/definitions.h
index ffe28a90..88c2bfe3 100644
--- a/src/definitions.h
+++ b/src/definitions.h
@@ -541,7 +541,8 @@ enum
        JUMPY_SCROLLING,
        EMPTY_LINE,
        INDICATOR,
-       BOOKSTYLE
+       BOOKSTYLE,
+       NO_MAGIC
 };
 
 /* Flags for the menus in which a given function should be present. */
diff --git a/src/nano.c b/src/nano.c
index c8901801..ba27dfd2 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -577,6 +577,9 @@ void usage(void)
 #endif
 #ifndef NANO_TINY
        print_opt("-Z", "--zap", N_("Let Bsp and Del erase a marked region"));
+#ifdef HAVE_LIBMAGIC
+       print_opt("-.", "--nomagic", N_("Do not make use of libmagic"));
+#endif
        print_opt("-a", "--atblanks", N_("When soft-wrapping, do it at 
whitespace"));
 #endif
 #ifdef ENABLE_WRAPPING
@@ -1752,6 +1755,7 @@ int main(int argc, char **argv)
                {"wordbounds", 0, NULL, 'W'},
                {"wordchars", 1, NULL, 'X'},
                {"zap", 0, NULL, 'Z'},
+               {"nomagic", 0, NULL, '.'},
                {"atblanks", 0, NULL, 'a'},
                {"autoindent", 0, NULL, 'i'},
                {"cutfromcursor", 0, NULL, 'k'},
@@ -1814,7 +1818,7 @@ int main(int argc, char **argv)
                SET(RESTRICTED);
 
        while ((optchr = getopt_long(argc, argv, 
"ABC:DEFGHIJ:KLMNOPQ:RST:UVWX:Y:Z"
-                               "abcdef:ghijklmno:pqr:s:tuvwxyz$", 
long_options, NULL)) != -1) {
+                               ".abcdef:ghijklmno:pqr:s:tuvwxyz$", 
long_options, NULL)) != -1) {
                switch (optchr) {
 #ifndef NANO_TINY
                        case 'A':
@@ -1934,6 +1938,9 @@ int main(int argc, char **argv)
                        case 'Z':
                                SET(LET_THEM_ZAP);
                                break;
+                       case '.':
+                               SET(NO_MAGIC);
+                               break;
                        case 'a':
                                SET(AT_BLANKS);
                                break;
diff --git a/src/rcfile.c b/src/rcfile.c
index b908f2ce..5fa46998 100644
--- a/src/rcfile.c
+++ b/src/rcfile.c
@@ -67,6 +67,7 @@ static const rcoption rcopts[] = {
        {"multibuffer", MULTIBUFFER},
 #endif
        {"nohelp", NO_HELP},
+       {"nomagic", NO_MAGIC},
        {"nonewlines", NO_NEWLINES},
        {"nopauses", NO_PAUSES},  /* Obsolete; remove in 2021. */
 #ifdef ENABLE_WRAPPING
-- 
2.25.4




reply via email to

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