From 5ff4a850b760ec68cdf10315f29a933386f434d8 Mon Sep 17 00:00:00 2001 From: Ethan Reynolds Date: Tue, 9 Apr 2024 20:27:21 -0400 Subject: [PATCH 1/8] add the external_edit_file_suffix config option --- src/config.rs | 10 ++++++++++ src/tests.rs | 1 + src/windows/room/chat.rs | 9 +++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/config.rs b/src/config.rs index 6d7dd0e..ad98610 100644 --- a/src/config.rs +++ b/src/config.rs @@ -54,6 +54,9 @@ const DEFAULT_ROOM_SORT: [SortColumn; 4] = [ const DEFAULT_REQ_TIMEOUT: u64 = 120; +//const DEFAULT_EXT_EDIT_FILE_SUFFIX: Option = Some(".txt".to_string()); +//const DEFAULT_EXT_EDIT_FILE_SUFFIX: String = ".txt".to_string(); + const COLORS: [Color; 13] = [ Color::Blue, Color::Cyan, @@ -507,6 +510,7 @@ pub struct TunableValues { pub notifications: Notifications, pub image_preview: Option, pub user_gutter_width: usize, + pub external_edit_file_suffix: Option, } #[derive(Clone, Default, Deserialize)] @@ -530,6 +534,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 +562,8 @@ 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 +587,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(DEFAULT_EXT_EDIT_FILE_SUFFIX), + //external_edit_file_suffix: self.external_edit_file_suffix.unwrap_or_else(|| DEFAULT_EXT_EDIT_FILE_SUFFIX.unwrap()), + external_edit_file_suffix: self.external_edit_file_suffix, } } } diff --git a/src/tests.rs b/src/tests.rs index 4d4de21..1565d1b 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: None, 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..0b07d1d 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,11 @@ 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_ref().map(|s| s.as_str()).unwrap_or_default(); + //external_edit(msg.trim_end().to_string(), Builder::new().suffix(""))? + external_edit(msg.trim_end().to_string(), Builder::new().suffix(suffix))? + } else if msg.is_blank() { return Ok(None); } else { From c6cdb44901b66214f4abdc7f7a1f6b789778e8b3 Mon Sep 17 00:00:00 2001 From: Ethan Reynolds Date: Tue, 9 Apr 2024 20:54:38 -0400 Subject: [PATCH 2/8] cleanup and update docs --- config.example.toml | 1 + docs/iamb.5 | 3 +++ src/config.rs | 5 ----- src/windows/room/chat.rs | 1 - 4 files changed, 4 insertions(+), 6 deletions(-) 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..1b81772 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 +An optional suffix to append to temporary files when using the editor command. + .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 ad98610..1522677 100644 --- a/src/config.rs +++ b/src/config.rs @@ -54,9 +54,6 @@ const DEFAULT_ROOM_SORT: [SortColumn; 4] = [ const DEFAULT_REQ_TIMEOUT: u64 = 120; -//const DEFAULT_EXT_EDIT_FILE_SUFFIX: Option = Some(".txt".to_string()); -//const DEFAULT_EXT_EDIT_FILE_SUFFIX: String = ".txt".to_string(); - const COLORS: [Color; 13] = [ Color::Blue, Color::Cyan, @@ -587,8 +584,6 @@ 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(DEFAULT_EXT_EDIT_FILE_SUFFIX), - //external_edit_file_suffix: self.external_edit_file_suffix.unwrap_or_else(|| DEFAULT_EXT_EDIT_FILE_SUFFIX.unwrap()), external_edit_file_suffix: self.external_edit_file_suffix, } } diff --git a/src/windows/room/chat.rs b/src/windows/room/chat.rs index 0b07d1d..033b83a 100644 --- a/src/windows/room/chat.rs +++ b/src/windows/room/chat.rs @@ -484,7 +484,6 @@ impl ChatState { let msg = if let SendAction::SubmitFromEditor = act { let suffix = store.application.settings.tunables.external_edit_file_suffix.as_ref().map(|s| s.as_str()).unwrap_or_default(); - //external_edit(msg.trim_end().to_string(), Builder::new().suffix(""))? external_edit(msg.trim_end().to_string(), Builder::new().suffix(suffix))? } else if msg.is_blank() { From 4ca2aabbab38fc091f956868990b1c34279b4ca4 Mon Sep 17 00:00:00 2001 From: Ethan Reynolds Date: Tue, 9 Apr 2024 20:59:08 -0400 Subject: [PATCH 3/8] docs --- docs/iamb.5 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/iamb.5 b/docs/iamb.5 index 1b81772..cb150f3 100644 --- a/docs/iamb.5 +++ b/docs/iamb.5 @@ -126,7 +126,7 @@ key and can be overridden as described in .Bl -tag -width Ds .It Sy external_edit_file_suffix -An optional suffix to append to temporary files when using the editor command. +An optional suffix to append to temporary files when using the :editor command. .It Sy default_room The room to show by default instead of the From c74c53c6811b96e22275e0ef1167c8bbf2a3ad6c Mon Sep 17 00:00:00 2001 From: Ethan Reynolds Date: Tue, 9 Apr 2024 21:13:20 -0400 Subject: [PATCH 4/8] Simplify per clippy --- src/config.rs | 5 +++-- src/windows/room/chat.rs | 11 ++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/config.rs b/src/config.rs index 1522677..17e48b4 100644 --- a/src/config.rs +++ b/src/config.rs @@ -559,8 +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), - + external_edit_file_suffix: self + .external_edit_file_suffix + .or(other.external_edit_file_suffix), } } diff --git a/src/windows/room/chat.rs b/src/windows/room/chat.rs index 033b83a..9d08009 100644 --- a/src/windows/room/chat.rs +++ b/src/windows/room/chat.rs @@ -482,10 +482,15 @@ impl ChatState { let msg = self.tbox.get(); let msg = if let SendAction::SubmitFromEditor = act { - - let suffix = store.application.settings.tunables.external_edit_file_suffix.as_ref().map(|s| s.as_str()).unwrap_or_default(); + //let suffix = store.application.settings.tunables.external_edit_file_suffix.as_ref().map(|s| s.as_str()).unwrap_or_default(); + let suffix = store + .application + .settings + .tunables + .external_edit_file_suffix + .as_deref() + .unwrap_or_default(); external_edit(msg.trim_end().to_string(), Builder::new().suffix(suffix))? - } else if msg.is_blank() { return Ok(None); } else { From c5ee5d86f98ea0261f56897d4d5b8c5ef78366ec Mon Sep 17 00:00:00 2001 From: Ethan Reynolds Date: Tue, 9 Apr 2024 21:18:21 -0400 Subject: [PATCH 5/8] cleanup --- src/windows/room/chat.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/windows/room/chat.rs b/src/windows/room/chat.rs index 9d08009..92b87d3 100644 --- a/src/windows/room/chat.rs +++ b/src/windows/room/chat.rs @@ -482,7 +482,6 @@ impl ChatState { let msg = self.tbox.get(); let msg = if let SendAction::SubmitFromEditor = act { - //let suffix = store.application.settings.tunables.external_edit_file_suffix.as_ref().map(|s| s.as_str()).unwrap_or_default(); let suffix = store .application .settings From 180eeacf35ce66ced9dfaabb45515447141c4d5c Mon Sep 17 00:00:00 2001 From: Ethan Reynolds Date: Tue, 9 Apr 2024 21:22:08 -0400 Subject: [PATCH 6/8] make docs clearer --- docs/iamb.5 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/iamb.5 b/docs/iamb.5 index cb150f3..61286c7 100644 --- a/docs/iamb.5 +++ b/docs/iamb.5 @@ -126,7 +126,7 @@ key and can be overridden as described in .Bl -tag -width Ds .It Sy external_edit_file_suffix -An optional suffix to append to temporary files when using the :editor command. +An optional suffix to append to temporary file names when using the :editor command. .It Sy default_room The room to show by default instead of the From e8c484ab2fecabe71fbc8572dcb2158a8933f020 Mon Sep 17 00:00:00 2001 From: Ethan Reynolds Date: Wed, 10 Apr 2024 11:36:50 -0400 Subject: [PATCH 7/8] default to .md and update docs --- docs/iamb.5 | 2 +- src/config.rs | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/iamb.5 b/docs/iamb.5 index 61286c7..90d86de 100644 --- a/docs/iamb.5 +++ b/docs/iamb.5 @@ -126,7 +126,7 @@ key and can be overridden as described in .Bl -tag -width Ds .It Sy external_edit_file_suffix -An optional suffix to append to temporary file names when using the :editor command. +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 diff --git a/src/config.rs b/src/config.rs index 17e48b4..f3c5a70 100644 --- a/src/config.rs +++ b/src/config.rs @@ -559,9 +559,11 @@ 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), + external_edit_file_suffix: Some( + self.external_edit_file_suffix + .or(other.external_edit_file_suffix) + .unwrap_or_else(|| ".md".to_string()), + ), } } From 06fbc0084cc828a4e48cea45bdaa1bd6cc133212 Mon Sep 17 00:00:00 2001 From: Ulyssa Date: Thu, 11 Apr 2024 20:30:20 -0700 Subject: [PATCH 8/8] Make external_edit_file_suffix just a String --- src/config.rs | 14 +++++++------- src/tests.rs | 2 +- src/windows/room/chat.rs | 9 ++------- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/config.rs b/src/config.rs index f3c5a70..4d31fff 100644 --- a/src/config.rs +++ b/src/config.rs @@ -507,7 +507,7 @@ pub struct TunableValues { pub notifications: Notifications, pub image_preview: Option, pub user_gutter_width: usize, - pub external_edit_file_suffix: Option, + pub external_edit_file_suffix: String, } #[derive(Clone, Default, Deserialize)] @@ -559,11 +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: Some( - self.external_edit_file_suffix - .or(other.external_edit_file_suffix) - .unwrap_or_else(|| ".md".to_string()), - ), + external_edit_file_suffix: self + .external_edit_file_suffix + .or(other.external_edit_file_suffix), } } @@ -587,7 +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, + 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 1565d1b..b385992 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -186,7 +186,7 @@ pub fn mock_tunables() -> TunableValues { .into_iter() .collect::>(), open_command: None, - external_edit_file_suffix: 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 92b87d3..3a74e93 100644 --- a/src/windows/room/chat.rs +++ b/src/windows/room/chat.rs @@ -482,13 +482,8 @@ impl ChatState { let msg = self.tbox.get(); let msg = if let SendAction::SubmitFromEditor = act { - let suffix = store - .application - .settings - .tunables - .external_edit_file_suffix - .as_deref() - .unwrap_or_default(); + 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);