diff --git a/src/color.c b/src/color.c index cc0a5f2d..2a0c0134 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 (when requested). */ + if (sntx == NULL && !inhelp && ISSET(USE_MAGIC)) { struct stat fileinfo; magic_t cookie = NULL; const char *magicstring = NULL; diff --git a/src/definitions.h b/src/definitions.h index 4b593624..a01dcd51 100644 --- a/src/definitions.h +++ b/src/definitions.h @@ -542,7 +542,8 @@ enum EMPTY_LINE, INDICATOR, BOOKSTYLE, - STATEFLAGS + STATEFLAGS, + USE_MAGIC }; /* Flags for the menus in which a given function should be present. */ diff --git a/src/nano.c b/src/nano.c index 49ef3775..a9a48e12 100644 --- a/src/nano.c +++ b/src/nano.c @@ -494,9 +494,12 @@ void usage(void) #endif /* TRANSLATORS: The next three are column headers of the --help output. */ print_opt(_("Option"), _("Long option"), N_("Meaning")); -#ifndef NANO_TINY +#ifdef HAVE_LIBMAGIC /* TRANSLATORS: The next forty or so strings are option descriptions * for the --help output. Try to keep them at most 40 characters. */ + print_opt("-!", "--magic", N_("Also try magic to determine syntax")); +#endif +#ifndef NANO_TINY print_opt("-%", "--stateflags", N_("Show some states on the title bar")); print_opt("-A", "--smarthome", N_("Enable smart home key")); if (!ISSET(RESTRICTED)) { @@ -1701,6 +1704,9 @@ int main(int argc, char **argv) /* Whether the quoting regex was compiled successfully. */ #endif const struct option long_options[] = { +#ifdef HAVE_LIBMAGIC + {"magic", 0, NULL, '!'}, +#endif {"boldtext", 0, NULL, 'D'}, #ifdef ENABLE_MULTIBUFFER {"multibuffer", 0, NULL, 'F'}, @@ -1841,9 +1847,14 @@ int main(int argc, char **argv) if (*(tail(argv[0])) == 'r') SET(RESTRICTED); - while ((optchr = getopt_long(argc, argv, "%ABC:DEFGHIJ:KLMNOPQ:RST:UVWX:Y:Z" + while ((optchr = getopt_long(argc, argv, "!%ABC:DEFGHIJ:KLMNOPQ:RST:UVWX:Y:Z" "abcdef:ghijklmno:pqr:s:tuvwxyz$", long_options, NULL)) != -1) { switch (optchr) { +#ifdef HAVE_LIBMAGIC + case '!': + SET(USE_MAGIC); + break; +#endif #ifndef NANO_TINY case '%': SET(STATEFLAGS); diff --git a/src/rcfile.c b/src/rcfile.c index 5d69d374..9ba3badb 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -56,6 +56,9 @@ static const rcoption rcopts[] = { #endif #ifdef ENABLE_LINENUMBERS {"linenumbers", LINE_NUMBERS}, +#endif +#ifdef HAVE_LIBMAGIC + {"magic", USE_MAGIC}, #endif {"morespace", MORE_SPACE}, /* Deprecated; remove in 2021. */ #ifdef ENABLE_MOUSE