Better Emacs handling in Windows (fix #112)
This commit is contained in:
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()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user