Have two emacs. Want to use spacemacs with one and leave the other intact

2 min read 07-10-2024
Have two emacs. Want to use spacemacs with one and leave the other intact


Keeping Your Emacses Happy: Using Spacemacs with One Emacs Instance

Have you fallen in love with the productivity and customization of Spacemacs, but also rely on your vanilla Emacs for specific tasks? You're not alone! Many Emacs users find themselves in this situation, wanting to reap the benefits of Spacemacs without sacrificing their existing Emacs configuration. This article will guide you through the process of setting up Spacemacs alongside your existing Emacs, keeping both installations separate and functional.

The Scenario: Two Emacses, One Spacemacs

Let's imagine you have a perfectly configured Emacs installation that you've carefully crafted over time. You've customized key bindings, installed packages, and tweaked settings to fit your workflow perfectly. Now, you're intrigued by Spacemacs's vibrant community, powerful features, and streamlined development experience. You want to explore Spacemacs without disrupting your existing Emacs environment.

Original Code (for demonstration purposes):

;; This is a basic example of a '.emacs' file.
(setq inhibit-startup-screen t)
(package-initialize)
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(package-refresh-contents)
(package-install 'yasnippet)

The Solution: Separate Installations and Environment Variables

The most straightforward approach is to maintain separate Emacs installations. Here's how you can achieve this:

  1. Install Spacemacs: Follow the Spacemacs installation instructions on their website. https://spacemacs.org/
  2. Create Separate Configuration Files: Keep the original .emacs file for your vanilla Emacs and create a new .spacemacs file for Spacemacs.
  3. Environment Variables: Use environment variables to distinguish between the two Emacs installations. For instance, you can set:
    • EMACS_USER_CONFIG_DIR: This variable points to the directory containing your custom Emacs configurations (e.g., .emacs, .emacs.d, or similar). You can set different values for your vanilla Emacs and Spacemacs.
    • EMACS_USER_PATH: This variable can be used to define additional directories for packages, themes, and other customizations.

Example of environment variable setup (for Bash):

# For vanilla Emacs
export EMACS_USER_CONFIG_DIR="$HOME/.emacs.d"

# For Spacemacs
export EMACS_USER_CONFIG_DIR="$HOME/.spacemacs.d"

Benefits of Separate Installations

This approach offers several advantages:

  • Clarity and Control: You have distinct configurations for both Emacs environments, preventing conflicts and ensuring that your vanilla Emacs remains untouched.
  • Independent Customization: You can customize each Emacs installation independently, allowing you to tailor them to your specific needs.
  • Ease of Switching: By using different environment variables, you can seamlessly switch between the two Emacs instances based on your requirements.

Conclusion

Maintaining two separate Emacs installations allows you to experience the benefits of both vanilla Emacs and Spacemacs without compromising either. By leveraging environment variables and distinct configuration files, you can keep your Emacs workflow flexible and cater to your diverse coding needs. Remember, the key is to stay organized, leverage environment variables effectively, and enjoy the versatility of having two powerful Emacs instances at your disposal.