From 1dc39f900c1307407894f1ca207a1a2a869c43dc Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch
Date: Tue, 27 Jan 2026 15:35:03 +0100
Subject: Add and integrate sdn-edit
---
CMakeLists.txt | 4 ++--
NEWS | 6 ++++++
sdn-edit | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
sdn-edit.1 | 24 ++++++++++++++++++++++++
sdn.cpp | 22 ++++++++++++++++------
5 files changed, 96 insertions(+), 8 deletions(-)
create mode 100755 sdn-edit
create mode 100644 sdn-edit.1
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ce5a6c4..fd662ec 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -36,9 +36,9 @@ include (GNUInstallDirs)
# sdn-mc-ext should be in libexec, but we prefer it in PATH.
install (TARGETS sdn sdn-mc-ext
DESTINATION ${CMAKE_INSTALL_BINDIR})
-install (PROGRAMS sdn-install sdn-open sdn-view
+install (PROGRAMS sdn-install sdn-open sdn-view sdn-edit
DESTINATION ${CMAKE_INSTALL_BINDIR})
-install (FILES sdn.1 sdn-install.1 sdn-open.1 sdn-view.1
+install (FILES sdn.1 sdn-install.1 sdn-open.1 sdn-view.1 sdn-edit.1
DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
install (FILES LICENSE DESTINATION ${CMAKE_INSTALL_DOCDIR})
diff --git a/NEWS b/NEWS
index 3373189..958af15 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,9 @@
+Unreleased
+
+ * Added an sdn-edit script analogous to sdn-view, bound it to F4,
+ and moved the original key binding to F14.
+
+
1.1.0 (2026-01-10)
* Added selection functionality, and adjusted key bindings:
diff --git a/sdn-edit b/sdn-edit
new file mode 100755
index 0000000..2245ba3
--- /dev/null
+++ b/sdn-edit
@@ -0,0 +1,48 @@
+#!/bin/sh -e
+# sdn-edit: an editor for sdn that makes use of Midnight Commander configuration
+# to make more kinds of files directly editable
+
+if [ "$#" -ne 1 ]
+then
+ echo "Usage: $0 FILE" >&2
+ exit 2
+fi
+
+# This handles both MC_DATADIR and odd installation locations.
+datadir=
+if command -v mc >/dev/null
+then datadir=$(mc --datadir | sed 's/ (.*)$//')
+fi
+
+config=
+for dir in "$HOME"/.config/mc "$datadir" /etc/mc
+do
+ if [ -n "$dir" -a -f "$dir/mc.ext.ini" ]
+ then
+ config=$dir/mc.ext.ini
+ break
+ fi
+done
+
+# This is often used in %env{} expansion, so let's be on the same page.
+export PAGER=${PAGER:-less}
+
+export MC_EXT_FILENAME=$(realpath "$1")
+export MC_EXT_BASENAME=$(basename "$1")
+export MC_EXT_CURRENTDIR=$(dirname "$MC_EXT_FILENAME")
+output=$(sdn-mc-ext <"$config" "$(file -Lbz "$1")" \
+ "$MC_EXT_FILENAME" "$MC_EXT_BASENAME" "$MC_EXT_CURRENTDIR" Edit || :)
+kind=$(echo "$output" | sed -n 1p)
+command=$(echo "$output" | sed -n 2p)
+
+case "$kind" in
+'')
+ if [ -n "$command" ]
+ then eval "$command"
+ else "${VISUAL:-${EDITOR:-vi}}" -- "$MC_EXT_FILENAME"
+ fi
+ ;;
+*)
+ echo "Unsupported: $kind" >&2
+ exit 1
+esac
diff --git a/sdn-edit.1 b/sdn-edit.1
new file mode 100644
index 0000000..ad37a4f
--- /dev/null
+++ b/sdn-edit.1
@@ -0,0 +1,24 @@
+.Dd January 27, 2026
+.Dt SDN-EDIT 1
+.Os
+.Sh NAME
+.Nm sdn-edit
+.Nd run Midnight Commander edit configuration externally
+.Sh SYNOPSIS
+.Nm sdn-edit
+.Ar path
+.Sh DESCRIPTION
+.Nm
+invokes
+.Ev VISUAL ,
+.Ev EDITOR
+or a fallback editor on the passed filename.
+.Pp
+If it succeeds in finding a
+.Xr mc 1
+.Pa mc.ext.ini
+file, it will first process it, and run the respective command.
+.Sh REPORTING BUGS
+Use
+.Lk https://git.janouch.name/p/sdn
+to report bugs, request features, or submit pull requests.
diff --git a/sdn.cpp b/sdn.cpp
index d43911e..df36f88 100644
--- a/sdn.cpp
+++ b/sdn.cpp
@@ -440,7 +440,7 @@ enum { ALT = 1 << 24, SYM = 1 << 25 }; // Outside the range of Unicode
#define ACTIONS(XX) XX(NONE) XX(HELP) XX(QUIT) XX(QUIT_NO_CHDIR) \
XX(ENTER) XX(OPEN) XX(CHOOSE) XX(CHOOSE_FULL) \
- XX(VIEW_RAW) XX(VIEW) XX(EDIT) XX(SORT_LEFT) XX(SORT_RIGHT) \
+ XX(VIEW_RAW) XX(VIEW) XX(EDIT) XX(EDIT_RAW) XX(SORT_LEFT) XX(SORT_RIGHT) \
XX(SELECT) XX(DESELECT) XX(SELECT_TOGGLE) XX(SELECT_ABORT) \
XX(UP) XX(DOWN) XX(TOP) XX(BOTTOM) XX(HIGH) XX(MIDDLE) XX(LOW) \
XX(PAGE_PREVIOUS) XX(PAGE_NEXT) XX(SCROLL_UP) XX(SCROLL_DOWN) XX(CENTER) \
@@ -466,7 +466,7 @@ static map