diff --git a/core/internal/matugen/matugen.go b/core/internal/matugen/matugen.go index 206f92a4..d2996360 100644 --- a/core/internal/matugen/matugen.go +++ b/core/internal/matugen/matugen.go @@ -33,6 +33,7 @@ const ( TemplateKindTerminal TemplateKindGTK TemplateKindVSCode + TemplateKindEmacs ) type TemplateDef struct { @@ -65,7 +66,7 @@ var templateRegistry = []TemplateDef{ {ID: "dgop", Commands: []string{"dgop"}, ConfigFile: "dgop.toml"}, {ID: "kcolorscheme", ConfigFile: "kcolorscheme.toml", RunUnconditionally: true}, {ID: "vscode", Kind: TemplateKindVSCode}, - {ID: "emacs", Commands: []string{"emacs"}, ConfigFile: "emacs.toml"}, + {ID: "emacs", Commands: []string{"emacs"}, ConfigFile: "emacs.toml", Kind: TemplateKindEmacs}, } func (c *ColorMode) GTKTheme() string { @@ -334,6 +335,10 @@ output_path = '%s' appendVSCodeConfig(cfgFile, "cursor", filepath.Join(homeDir, ".cursor/extensions"), opts.ShellDir) appendVSCodeConfig(cfgFile, "windsurf", filepath.Join(homeDir, ".windsurf/extensions"), opts.ShellDir) appendVSCodeConfig(cfgFile, "vscode-insiders", filepath.Join(homeDir, ".vscode-insiders/extensions"), opts.ShellDir) + case TemplateKindEmacs: + if utils.EmacsConfigDir() != "" { + appendConfig(opts, cfgFile, tmpl.Commands, tmpl.Flatpaks, tmpl.ConfigFile) + } default: appendConfig(opts, cfgFile, tmpl.Commands, tmpl.Flatpaks, tmpl.ConfigFile) } @@ -491,6 +496,9 @@ func substituteVars(content, shellDir string) string { result = strings.ReplaceAll(result, "'CONFIG_DIR/", "'"+utils.XDGConfigHome()+"/") result = strings.ReplaceAll(result, "'DATA_DIR/", "'"+utils.XDGDataHome()+"/") result = strings.ReplaceAll(result, "'CACHE_DIR/", "'"+utils.XDGCacheHome()+"/") + if emacsDir := utils.EmacsConfigDir(); emacsDir != "" { + result = strings.ReplaceAll(result, "'EMACS_DIR/", "'"+emacsDir+"/") + } return result } @@ -819,6 +827,8 @@ func CheckTemplates(checker utils.AppChecker) []TemplateCheck { detected = true case tmpl.Kind == TemplateKindVSCode: detected = checkVSCodeExtension(homeDir) + case tmpl.Kind == TemplateKindEmacs: + detected = appExists(checker, tmpl.Commands, tmpl.Flatpaks) && utils.EmacsConfigDir() != "" default: detected = appExists(checker, tmpl.Commands, tmpl.Flatpaks) } diff --git a/core/internal/utils/paths.go b/core/internal/utils/paths.go index ddc94cf6..053097ee 100644 --- a/core/internal/utils/paths.go +++ b/core/internal/utils/paths.go @@ -38,6 +38,22 @@ func XDGConfigHome() string { return filepath.Join(home, ".config") } +func EmacsConfigDir() string { + home, _ := os.UserHomeDir() + + emacsD := filepath.Join(home, ".emacs.d") + if info, err := os.Stat(emacsD); err == nil && info.IsDir() { + return emacsD + } + + xdgEmacs := filepath.Join(XDGConfigHome(), "emacs") + if info, err := os.Stat(xdgEmacs); err == nil && info.IsDir() { + return xdgEmacs + } + + return "" +} + func ExpandPath(path string) (string, error) { expanded := os.ExpandEnv(path) expanded = filepath.Clean(expanded) diff --git a/quickshell/matugen/configs/emacs.toml b/quickshell/matugen/configs/emacs.toml index 5db4d4d1..aac56ab7 100644 --- a/quickshell/matugen/configs/emacs.toml +++ b/quickshell/matugen/configs/emacs.toml @@ -1,3 +1,3 @@ [templates.dmsemacs] input_path = 'SHELL_DIR/matugen/templates/dank-emacs.el' -output_path = "~/.emacs.d/themes/dank-emacs-theme.el" +output_path = 'EMACS_DIR/themes/dank-emacs-theme.el'