diff --git a/config.example.toml b/config.example.toml index 598b0ff..c4ebd65 100644 --- a/config.example.toml +++ b/config.example.toml @@ -6,6 +6,7 @@ url = "https://matrix.org" [settings] default_room = "#iamb-users:0x.badd.cafe" +external_edit_file_suffix = ".md" log_level = "warn" message_shortcode_display = false open_command = ["my-open", "--file"] diff --git a/docs/iamb.5 b/docs/iamb.5 index 48c5412..90d86de 100644 --- a/docs/iamb.5 +++ b/docs/iamb.5 @@ -125,6 +125,9 @@ key and can be overridden as described in .Sx PROFILES . .Bl -tag -width Ds +.It Sy external_edit_file_suffix +Suffix to append to temporary file names when using the :editor command. Defaults to .md. + .It Sy default_room The room to show by default instead of the .Sy :welcome diff --git a/src/config.rs b/src/config.rs index 6d7dd0e..4d31fff 100644 --- a/src/config.rs +++ b/src/config.rs @@ -507,6 +507,7 @@ pub struct TunableValues { pub notifications: Notifications, pub image_preview: Option, pub user_gutter_width: usize, + pub external_edit_file_suffix: String, } #[derive(Clone, Default, Deserialize)] @@ -530,6 +531,7 @@ pub struct Tunables { pub notifications: Option, pub image_preview: Option, pub user_gutter_width: Option, + pub external_edit_file_suffix: Option, } impl Tunables { @@ -557,6 +559,9 @@ impl Tunables { notifications: self.notifications.or(other.notifications), image_preview: self.image_preview.or(other.image_preview), user_gutter_width: self.user_gutter_width.or(other.user_gutter_width), + external_edit_file_suffix: self + .external_edit_file_suffix + .or(other.external_edit_file_suffix), } } @@ -580,6 +585,9 @@ impl Tunables { notifications: self.notifications.unwrap_or_default(), image_preview: self.image_preview.map(ImagePreview::values), user_gutter_width: self.user_gutter_width.unwrap_or(30), + external_edit_file_suffix: self + .external_edit_file_suffix + .unwrap_or_else(|| ".md".to_string()), } } } diff --git a/src/tests.rs b/src/tests.rs index 4d4de21..b385992 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -186,6 +186,7 @@ pub fn mock_tunables() -> TunableValues { .into_iter() .collect::>(), open_command: None, + external_edit_file_suffix: String::from(".md"), username_display: UserDisplayStyle::Username, message_user_color: false, notifications: Notifications { diff --git a/src/windows/room/chat.rs b/src/windows/room/chat.rs index 8f42d72..3a74e93 100644 --- a/src/windows/room/chat.rs +++ b/src/windows/room/chat.rs @@ -5,7 +5,8 @@ use std::fs; use std::ops::Deref; use std::path::{Path, PathBuf}; -use edit::edit as external_edit; +use edit::edit_with_builder as external_edit; +use edit::Builder; use modalkit::editing::store::RegisterError; use std::process::Command; use tokio; @@ -481,7 +482,9 @@ impl ChatState { let msg = self.tbox.get(); let msg = if let SendAction::SubmitFromEditor = act { - external_edit(msg.trim_end().to_string())? + let suffix = + store.application.settings.tunables.external_edit_file_suffix.as_str(); + external_edit(msg.trim_end().to_string(), Builder::new().suffix(suffix))? } else if msg.is_blank() { return Ok(None); } else {