Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,7 @@ tests/src/Makefile
tests/src/filemanager/Makefile
tests/src/editor/Makefile
tests/src/editor/edit_complete_word_cmd_test_data.txt
tests/src/viewer/Makefile
tests/src/vfs/Makefile
tests/src/vfs/extfs/Makefile
tests/src/vfs/extfs/helpers-list/Makefile
Expand Down
2 changes: 2 additions & 0 deletions doc/hints/mc.hint
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ Hint: To look at the output of a command in the viewer, use M-!

Hint: F13 (or Shift-F3) invokes the viewer in raw mode.

Hint: Press Shift-F8 in the viewer for syntax highlighting. 's' chooses the backend.

Hint: You may specify the editor for F4 with the shell variable EDITOR.

Hint: You may specify the external viewer with the shell vars VIEWER or PAGER.
Expand Down
32 changes: 32 additions & 0 deletions doc/man/mc.1.in
Original file line number Diff line number Diff line change
Expand Up @@ -2933,6 +2933,30 @@ Some character sequences, which appear most often in preformatted manual
pages, are displayed bold and underlined, thus making a pretty display
of your files.
.PP
The viewer supports syntax highlighting via an external highlighter.
Press
.B Shift\-F8
to toggle syntax highlighting. Press
.B s
to choose the highlighting backend.
Five backends are supported:
.BR bat ,
.BR chroma ,
.BR highlight ,
.BR pygmentize ,
and
.BR source\-highlight .
A custom command can also be configured via the backend chooser dialog.
The command template must contain
.B %s
as a placeholder for the filename.
The viewer pipes the file through the chosen highlighter and renders
the ANSI\-colored output. The backend and file extension are shown in
the status bar, e.g.
.IR [bat:py] .
The syntax mode and backend choice are persisted in
.IR ~/.config/mc/ini .
.PP
When in hex mode, the search function accepts text in quotes and
constant numbers. Text in quotes is matched exactly after removing
the quotes. Each number matches one byte. You can mix quoted text
Expand Down Expand Up @@ -3025,6 +3049,14 @@ Jump to the next file.
.B C\-b
Jump to the previous file.
.TP
.B Shift\-F8
Toggle syntax highlighting. Requires an external highlighter
.RB ( bat ", " chroma ", " highlight ", " pygmentize ", or " source\-highlight ).
.TP
.B s
Open the syntax highlighting backend chooser dialog. Installed
backends and a "Custom..." option for arbitrary commands are shown.
.TP
.B Alt\-r
Toggle the ruler.
.TP
Expand Down
2 changes: 2 additions & 0 deletions lib/keybind.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ static name_keymap_t command_names[] = {
ADD_KEYMAP_NAME (HexMode),
ADD_KEYMAP_NAME (MagicMode),
ADD_KEYMAP_NAME (NroffMode),
ADD_KEYMAP_NAME (SyntaxMode),
ADD_KEYMAP_NAME (SyntaxOptions),
ADD_KEYMAP_NAME (BookmarkGoto),
ADD_KEYMAP_NAME (Ruler),
ADD_KEYMAP_NAME (SearchForward),
Expand Down
2 changes: 2 additions & 0 deletions lib/keybind.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@ enum
CK_WrapMode = 600L,
CK_MagicMode,
CK_NroffMode,
CK_SyntaxMode,
CK_SyntaxOptions,
CK_HexMode,
CK_HexEditMode,
CK_BookmarkGoto,
Expand Down
2 changes: 2 additions & 0 deletions misc/mc.default.keymap
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,8 @@ HalfPageDown = d
HalfPageUp = u
Top = home; ctrl-home; ctrl-pgup; a1; alt-lt; g
Bottom = end; ctrl-end; ctrl-pgdn; c1; alt-gt; shift-g
SyntaxMode = f18
SyntaxOptions = s
BookmarkGoto = m
Bookmark = r
FileNext = ctrl-f
Expand Down
2 changes: 2 additions & 0 deletions misc/mc.emacs.keymap
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,8 @@ HalfPageDown = d
HalfPageUp = u
Top = home; ctrl-home; ctrl-pgup; a1; alt-lt; g
Bottom = end; ctrl-end; ctrl-pgdn; c1; alt-gt; shift-g
SyntaxMode = f18
SyntaxOptions = s
BookmarkGoto = m
Bookmark = r
FileNext = ctrl-f
Expand Down
2 changes: 2 additions & 0 deletions misc/mc.vim.keymap
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ HalfPageDown = d
HalfPageUp = u
Top = home; ctrl-home; ctrl-pgup; a1; alt-lt; g
Bottom = end; ctrl-end; ctrl-pgdn; c1; alt-gt; shift-g
SyntaxMode = f18
SyntaxOptions = s
BookmarkGoto = m
Bookmark = r
FileNext = ctrl-f
Expand Down
2 changes: 2 additions & 0 deletions src/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,8 @@ static const global_keymap_ini_t default_viewer_keymap[] = {
{ "SearchBackwardContinue", "ctrl-r" },
{ "SearchOppositeContinue", "shift-n" },
{ "History", "alt-shift-e" },
{ "SyntaxMode", "s" },
{ "SyntaxOptions", "shift-s" },
{
NULL,
NULL,
Expand Down
3 changes: 3 additions & 0 deletions src/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
#endif

#include "src/viewer/mcviewer.h" // For the externs
#include "src/viewer/syntax.h" // mcview_syntax_command

#include "setup.h"

Expand Down Expand Up @@ -310,6 +311,7 @@ static const struct
{ "mouse_close_dialog", &mouse_close_dialog },
{ "drop_menus", &drop_menus },
{ "wrap_mode", &mcview_global_flags.wrap },
{ "syntax_mode", &mcview_global_flags.syntax },
{ "old_esc_mode", &old_esc_mode },
{ "cd_symlinks", &mc_global.vfs.cd_symlinks },
{ "show_all_if_ambiguous", &mc_global.widget.show_all_if_ambiguous },
Expand Down Expand Up @@ -418,6 +420,7 @@ static const struct
{ "editor_stop_format_chars", &edit_options.stop_format_chars, "-+*\\,.;:&>" },
#endif
{ "mcview_eof", &mcview_show_eof, "" },
{ "syntax_command", &mcview_syntax_command, MCVIEW_SYNTAX_DEFAULT_CMD },
{ NULL, NULL, NULL },
};

Expand Down
4 changes: 3 additions & 1 deletion src/viewer/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ noinst_LTLIBRARIES = libmcviewer.la

libmcviewer_la_SOURCES = \
actions_cmd.c \
ansi.c ansi.h \
ascii.c \
coord_cache.c \
datasource.c \
Expand All @@ -16,6 +17,7 @@ libmcviewer_la_SOURCES = \
mcviewer.h \
move.c \
nroff.c \
search.c
search.c \
syntax.c syntax.h

AM_CPPFLAGS = -I$(top_srcdir) $(GLIB_CFLAGS)
35 changes: 34 additions & 1 deletion src/viewer/actions_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
#include "src/keymap.h"

#include "internal.h"
#include "syntax.h"

/*** global variables ****************************************************************************/

Expand Down Expand Up @@ -156,7 +157,14 @@ mcview_hook (void *v)
if (fe == NULL)
return;

mcview_done (view);
// save global flags β€” quick view panel refresh must not clobber
// flags set by the standalone viewer (e.g. syntax mode toggled via F3)
{
mcview_mode_flags_t saved_global = mcview_global_flags;

mcview_done (view);
mcview_global_flags = saved_global;
}
mcview_init (view);
mcview_load (view, 0, fe->fname->str, 0, 0, 0);
mcview_display (view);
Expand Down Expand Up @@ -466,6 +474,31 @@ mcview_execute_cmd (WView *view, long command)
case CK_NroffMode:
mcview_toggle_nroff_mode (view);
break;
case CK_SyntaxMode:
// warn if trying to enable syntax but highlighter is missing
if (!view->mode_flags.syntax && !mcview_syntax_command_available ())
{
message (D_ERROR, _ ("Syntax Highlighting"), "%s",
_ ("No syntax highlighting tool found.\n"
"Please install one of:\n"
" bat, chroma, highlight,\n"
" pygmentize, source-highlight\n"
"or press Shift-S to set a custom command."));
break;
}
mcview_toggle_syntax_mode (view);
break;
case CK_SyntaxOptions:
if (mcview_syntax_options_dialog ())
{
// backend changed β€” re-toggle to reload with new command
if (view->mode_flags.syntax)
{
view->mode_flags.syntax = FALSE;
mcview_toggle_syntax_mode (view);
}
}
break;
case CK_Home:
mcview_moveto_bol (view);
break;
Expand Down
Loading
Loading