Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add external_edit_file_suffix to config #253

Merged
merged 8 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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 config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
3 changes: 3 additions & 0 deletions docs/iamb.5
Original file line number Diff line number Diff line change
Expand Up @@ -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 file names when using the :editor command.

.It Sy default_room
The room to show by default instead of the
.Sy :welcome
Expand Down
6 changes: 6 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ pub struct TunableValues {
pub notifications: Notifications,
pub image_preview: Option<ImagePreviewValues>,
pub user_gutter_width: usize,
pub external_edit_file_suffix: Option<String>,
}

#[derive(Clone, Default, Deserialize)]
Expand All @@ -530,6 +531,7 @@ pub struct Tunables {
pub notifications: Option<Notifications>,
pub image_preview: Option<ImagePreview>,
pub user_gutter_width: Option<usize>,
pub external_edit_file_suffix: Option<String>,
}

impl Tunables {
Expand Down Expand Up @@ -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),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be fine with an .unwrap_or_else(|| ".md".into()) here. iamb interprets the text as markdown, so that's probably the most useful default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, PR updated.

}
}

Expand All @@ -580,6 +585,7 @@ 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,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ pub fn mock_tunables() -> TunableValues {
.into_iter()
.collect::<HashMap<_, _>>(),
open_command: None,
external_edit_file_suffix: None,
username_display: UserDisplayStyle::Username,
message_user_color: false,
notifications: Notifications {
Expand Down
12 changes: 10 additions & 2 deletions src/windows/room/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -481,7 +482,14 @@ 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_deref()
.unwrap_or_default();
external_edit(msg.trim_end().to_string(), Builder::new().suffix(suffix))?
} else if msg.is_blank() {
return Ok(None);
} else {
Expand Down
Loading