conf: add editor_cmd setting

Set the editor to launch in configuration. If it's missing, check for
$EDITOR
embed
Manos Pitsidianakis 2019-09-27 12:48:48 +03:00
parent 9d69a06807
commit 713c4f73b9
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
6 changed files with 74 additions and 29 deletions

36
meli.1
View File

@ -77,6 +77,42 @@ The view into each folder has 4 modes: plain, threaded, conversations and compac
^^ (`-=-=-=-=-`)
`-=-=-=-=-` ^^
.Ed
.Sh COMPOSING
To send mail, press
.Cm m
while viewing the appropriate account to open a new composing tab. To reply to a mail, press
.Cm R Ns
\&. You can edit some of the header fields from within the view, by selecting with the arrow keys and pressing
.Cm enter
to enter
.Ar INSERT
mode. At any time you can press
.Cm e
to launch your editor (see
.Xr meli.conf 5
.Em COMPOSING
for how to select which editor to launch). Attachments can be handled with the
.Em add-attachment Ns
,
.Em remove-attachment
commands (see below). Finally, pressing
.Ar s
will send your message by piping it into a binary of your choosing (see
.Xr meli.conf 5
.Em COMPOSING Ns
, setting
.Em mailer_cmd Ns
). To save your draft without sending it, issue command
.Cm close
and select 'save as draft'.
.Pp
If there is no Draft or Sent folder, meli tries first saving mail in your INBOX and then at any other folder. On complete failure to save your draft or sent message it will be saved in your
.Em tmp
directory instead and you will be notified of its location.
.Pp
To open a draft for editing later, select your draft in the mail listing and press
.Cm e Ns
\&.
.Sh EXECUTE mode
Commands are issued in EXECUTE mode, by default started with the space character and exited with Escape key.
.Pp

View File

@ -41,7 +41,7 @@ Newline means LF (0x0A) or CRLF (0x0D 0x0A).
.Pp
Refer to TOML documentation for valid TOML syntax.
.Sh SECTIONS
The top level sections of the config are accounts, shortcuts, notifications, pager, mailer, pgp.
The top level sections of the config are accounts, shortcuts, notifications, pager, composing, pgp.
.Pp
.Sy example configuration
.Bd -literal
@ -74,9 +74,10 @@ filter = "/usr/bin/pygmentize"
[notifications]
script = "notify-send"
[mailer]
[composing]
# required for sending e-mail
mailer_cmd = 'msmtp --read-recipients --read-envelope-from'
editor_cmd = 'vim +/^$'
[shortcuts]
scroll_up = 'k'
@ -172,7 +173,7 @@ example:
otherwise usage is inferred from the folder title.
.It Cm conf_override Ar boolean
(optional) override global settings for this folder. available sections to override are
.Em pager, notifications, shortcuts, mailer
.Em pager, notifications, shortcuts, composing
and the account options
.Em identity and index_style Ns
\&. example:
@ -183,10 +184,12 @@ and the account options
filter = ""
.Ed
.El
.Sh MAILER
.Sh COMPOSING
.Bl -tag -width "danger_accept_invalid_certs boolean" -offset -indent
.It Cm mailer_cmd Ar String
command to pipe new mail to, exit code must be 0 for success.
.It Cm editor_cmd Ar String
command to launch editor. Can have arguments. Draft filename is given as the last argument. If it's missing, the environment variable $EDITOR is looked up.
.El
.Sh SHORTCUTS
Shortcuts can take the following values:

View File

@ -54,6 +54,7 @@
#page_up = PageUp,
#page_down = PageDown,
#[mailer]
#[composing]
# required for sending e-mail
#mailer_cmd = 'msmtp --read-recipients --read-envelope-from'
#editor_cmd = 'vim +/^$' # optional, by default $EDITOR is used.

View File

@ -589,22 +589,24 @@ impl Component for Composer {
}
return true;
}
UIEvent::Input(Key::Char('e')) if self.cursor == Cursor::Body => {
UIEvent::Input(Key::Char('e')) => {
/* Edit draft in $EDITOR */
use std::process::{Command, Stdio};
let editor = match std::env::var("EDITOR") {
Err(e) => {
context.replies.push_back(UIEvent::Notification(
Some(
"$EDITOR is not set. You can change an envvar's value with setenv"
.to_string(),
),
e.to_string(),
let settings = &context.settings;
let editor = if let Some(editor_cmd) = settings.composing.editor_cmd.as_ref() {
editor_cmd.to_string()
} else {
match std::env::var("EDITOR") {
Err(e) => {
context.replies.push_back(UIEvent::Notification(
Some(e.to_string()),
"$EDITOR is not set. You can change an envvar's value with setenv or set composing.editor_cmd setting in your configuration.".to_string(),
Some(NotificationType::ERROR),
));
return true;
return true;
}
Ok(v) => v,
}
Ok(v) => v,
};
/* Kill input thread so that spawned command can be sole receiver of stdin */
{
@ -619,9 +621,10 @@ impl Component for Composer {
true,
);
// TODO: check exit status
if let Err(e) = Command::new(&editor)
.arg("+/^$")
let parts = split_command!(editor);
let (cmd, args) = (parts[0], &parts[1..]);
if let Err(e) = Command::new(cmd)
.args(args)
.arg(&f.path())
.stdin(Stdio::inherit())
.stdout(Stdio::inherit())
@ -760,7 +763,7 @@ pub fn send_draft(context: &mut Context, account_cursor: usize, draft: Draft) ->
use std::process::{Command, Stdio};
let mut failure = true;
let settings = &context.settings;
let parts = split_command!(settings.mailer.mailer_cmd);
let parts = split_command!(settings.composing.mailer_cmd);
let (cmd, args) = (parts[0], &parts[1..]);
let mut msmtp = Command::new(cmd)
.args(args)

View File

@ -24,7 +24,7 @@ extern crate serde;
extern crate toml;
extern crate xdg;
pub mod mailer;
pub mod composing;
pub mod notifications;
pub mod pager;
pub mod pgp;
@ -32,7 +32,7 @@ pub mod shortcuts;
pub mod accounts;
pub use self::accounts::Account;
pub use self::mailer::*;
pub use self::composing::*;
pub use self::pgp::*;
pub use self::shortcuts::*;
@ -96,7 +96,7 @@ pub struct MailUIConf {
pub pager: Option<PagerSettings>,
pub notifications: Option<NotificationsSettings>,
pub shortcuts: Option<Shortcuts>,
pub mailer: Option<MailerSettings>,
pub composing: Option<ComposingSettings>,
pub identity: Option<String>,
pub index_style: Option<IndexStyle>,
}
@ -273,7 +273,7 @@ struct FileSettings {
notifications: NotificationsSettings,
#[serde(default)]
shortcuts: Shortcuts,
mailer: MailerSettings,
composing: ComposingSettings,
#[serde(default)]
pgp: PGPSettings,
}
@ -303,7 +303,7 @@ pub struct Settings {
pub pager: PagerSettings,
pub notifications: NotificationsSettings,
pub shortcuts: Shortcuts,
pub mailer: MailerSettings,
pub composing: ComposingSettings,
pub pgp: PGPSettings,
}
@ -391,7 +391,7 @@ impl Settings {
pager: fs.pager,
notifications: fs.notifications,
shortcuts: fs.shortcuts,
mailer: fs.mailer,
composing: fs.composing,
pgp: fs.pgp,
}
}

View File

@ -1,5 +1,5 @@
/*
* meli - notifications conf module
* meli - conf module
*
* Copyright 2019 Manos Pitsidianakis
*
@ -19,10 +19,12 @@
* along with meli. If not, see <http://www.gnu.org/licenses/>.
*/
/// Settings for the mailer function.
/// Settings for writing and sending new e-mail
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct MailerSettings {
pub struct ComposingSettings {
/// A command to pipe new emails to
/// Required
pub mailer_cmd: String,
/// Command to launch editor. Can have arguments. Draft filename is given as the last argument. If it's missing, the environment variable $EDITOR is looked up.
pub editor_cmd: Option<String>,
}