Better Emacs handling in Windows (fix #112)
This commit is contained in:
21
src/main.rs
21
src/main.rs
@@ -20,8 +20,6 @@ use std::borrow::Cow;
|
||||
use std::env;
|
||||
use std::fmt::Debug;
|
||||
use std::io;
|
||||
#[cfg(windows)]
|
||||
use std::path::PathBuf;
|
||||
use std::process::exit;
|
||||
|
||||
fn execute<'a, F, M>(report: &mut Report<'a>, key: M, func: F, no_retry: bool) -> Result<(), Error>
|
||||
@@ -164,16 +162,10 @@ fn run() -> Result<(), Error> {
|
||||
#[cfg(unix)]
|
||||
execute(&mut report, "nix", || unix::run_nix(run_type), config.no_retry())?;
|
||||
|
||||
let emacs = emacs::Emacs::new(&base_dirs);
|
||||
if config.should_run(Step::Emacs) {
|
||||
#[cfg(unix)]
|
||||
git_repos.insert(base_dirs.home_dir().join(".emacs.d"));
|
||||
|
||||
#[cfg(windows)]
|
||||
{
|
||||
git_repos.insert(base_dirs.data_dir().join(".emacs.d"));
|
||||
if let Ok(home) = env::var("HOME") {
|
||||
git_repos.insert(PathBuf::from(home).join(".emacs.d"));
|
||||
}
|
||||
if let Some(directory) = emacs.directory() {
|
||||
git_repos.insert(directory);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -264,12 +256,7 @@ fn run() -> Result<(), Error> {
|
||||
)?;
|
||||
|
||||
if config.should_run(Step::Emacs) {
|
||||
execute(
|
||||
&mut report,
|
||||
"Emacs",
|
||||
|| generic::run_emacs(&base_dirs, run_type),
|
||||
config.no_retry(),
|
||||
)?;
|
||||
execute(&mut report, "Emacs", || emacs.upgrade(run_type), config.no_retry())?;
|
||||
}
|
||||
|
||||
execute(
|
||||
|
||||
49
src/steps/emacs.rs
Normal file
49
src/steps/emacs.rs
Normal file
@@ -0,0 +1,49 @@
|
||||
use crate::error::Error;
|
||||
use crate::executor::RunType;
|
||||
use crate::terminal::print_separator;
|
||||
use crate::utils::{require, require_option, PathExt};
|
||||
use directories::BaseDirs;
|
||||
#[cfg(windows)]
|
||||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
|
||||
const EMACS_UPGRADE: &str = include_str!("emacs.el");
|
||||
|
||||
pub struct Emacs {
|
||||
directory: Option<PathBuf>,
|
||||
}
|
||||
|
||||
impl Emacs {
|
||||
fn directory_path(base_dirs: &BaseDirs) -> Option<PathBuf> {
|
||||
#[cfg(unix)]
|
||||
return base_dirs.home_dir().join(".emacs.d").if_exists();
|
||||
|
||||
#[cfg(windows)]
|
||||
return env::var("HOME")
|
||||
.ok()
|
||||
.and_then(|home| PathBuf::from(home).join(".emacs.d").if_exists())
|
||||
.or_else(|| base_dirs.data_dir().join(".emacs.d").if_exists());
|
||||
}
|
||||
|
||||
pub fn new(base_dirs: &BaseDirs) -> Self {
|
||||
Self {
|
||||
directory: Emacs::directory_path(base_dirs),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn directory(&self) -> Option<&PathBuf> {
|
||||
self.directory.as_ref()
|
||||
}
|
||||
|
||||
pub fn upgrade(&self, run_type: RunType) -> Result<(), Error> {
|
||||
let emacs = require("emacs")?;
|
||||
let init_file = require_option(self.directory.as_ref())?.join("init.el").require()?;
|
||||
|
||||
print_separator("Emacs");
|
||||
|
||||
run_type
|
||||
.execute(&emacs)
|
||||
.args(&["--batch", "-l", init_file.to_str().unwrap(), "--eval", EMACS_UPGRADE])
|
||||
.check_run()
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,6 @@ use failure::ResultExt;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
const EMACS_UPGRADE: &str = include_str!("emacs.el");
|
||||
|
||||
pub fn run_cargo_update(run_type: RunType) -> Result<(), Error> {
|
||||
let cargo_update = utils::require("cargo-install-update")?;
|
||||
|
||||
@@ -29,18 +27,6 @@ pub fn run_gem(base_dirs: &BaseDirs, run_type: RunType) -> Result<(), Error> {
|
||||
run_type.execute(&gem).args(&["update", "--user-install"]).check_run()
|
||||
}
|
||||
|
||||
pub fn run_emacs(base_dirs: &BaseDirs, run_type: RunType) -> Result<(), Error> {
|
||||
let emacs = utils::require("emacs")?;
|
||||
let init_file = base_dirs.home_dir().join(".emacs.d/init.el").require()?;
|
||||
|
||||
print_separator("Emacs");
|
||||
|
||||
run_type
|
||||
.execute(&emacs)
|
||||
.args(&["--batch", "-l", init_file.to_str().unwrap(), "--eval", EMACS_UPGRADE])
|
||||
.check_run()
|
||||
}
|
||||
|
||||
#[cfg(not(any(
|
||||
target_os = "freebsd",
|
||||
target_os = "openbsd",
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
pub mod emacs;
|
||||
pub mod generic;
|
||||
pub mod git;
|
||||
pub mod node;
|
||||
|
||||
Reference in New Issue
Block a user