Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have system for having machine or profile-specific configurations #3520

Closed
travisbhartwell opened this issue Oct 23, 2015 · 2 comments
Closed
Labels
Core Discussion Enhancement ☺ stale marked as a stale issue/pr (usually by a bot)

Comments

@travisbhartwell
Copy link
Contributor

I would like to have something within Spacemacs to enable me to have a common base configuration and then a machine or profile specific configurations that can be loaded as well. I have something that accomplishes this for machine specific configurations in my ~/.spacemacs.d/init.el that loads an Elisp file corresponding to the host name it is running on. This way, I can have a standard, common configuration. And then on my work machine, I can load the configuration for the different layers that apply only to work. Or I can set things that are private to work, as far as directories to look for git repos, etc.

Currently, I have the following in my ~/.spacemacs.d/init.el:

;; Load system specific config, if it exists
(let ((tbh-system-specific-config
       (expand-file-name
        (concat tbh-hostname ".el") tbh-spacemacs-d-dir)))
  (if (file-readable-p tbh-system-specific-config)
      (load-file tbh-system-specific-config)))

Where tbh are my initials, and tbh-hostname and tbh-spacemacs-d-dir are constants set above this, but elided for brevity.

Then, here's the outline of the rest of my ~/.spacemacs.d/init.el:

(defun dotspacemacs/layers ()
   ;; Standard dotspacemacs/layers function elided for example brevity
   ;; ...
   ;; If a system-specific layers configuration function exist, call it
   (if (fboundp 'tbh/dotspacemacs/layers)
       (tbh/dotspacemacs/layers))

(defun dotspacemacs/init ()
   ;; Standard dotspacemacs/init function elided for example brevity
   ;; ...
   ;; If a system-specific init function exist, call it
   (if (fboundp 'tbh/dotspacemacs/init)
       (tbh/dotspacemacs/init))
)

(defun dotspacemacs/user-init ()
   ;; Standard dotspacemacs/user-init function elided for example brevity
   ;; ...
   ;; If a system-specific user-init function exist, call it
   (if (fboundp 'tbh/dotspacemacs/user-init)
       (tbh/dotspacemacs/user-init))
)

(defun dotspacemacs/user-config ()
  ;; Standard dotspacemacs/user-config function elided for example brevity
  ;; ...
  ;; If a system specific user-config function exists, call it
  (if (fboundp 'tbh/dotspacemacs/user-config)
      (tbh/dotspacemacs/user-config))
)

Then, for example in an abbreviated version, on my desktop, named shedemei, I have ~/.spacemacs.d/shedemei.el:

;; Local configuration only for shedemei.
(defun tbh/dotspacemacs/layers ()
  "Local configuration layers declaration"
  (let ((local-configuration-layers
         '(
           (c-c++ :variables
                  c-c++-enable-clang-support t)
           erlang
           )))
    (dolist (layer local-configuration-layers)
      (add-to-list 'dotspacemacs-configuration-layers layer)))

  (let ((local-additional-packages '(visual-fill-column w3m)))
    (dolist (package local-additional-packages)
      (add-to-list 'dotspacemacs-additional-packages package))))

(defun tbh/dotspacemacs/user-config ()
  "Local configuration function.
This function is called at the very end of Spacemacs initialization after
layers configuration, after the general dotspacemacs/user-config."
  (add-hook 'visual-line-mode-hook 'visual-fill-column-mode))

I'd love for a similar mechanism to be built into Spacemacs so I don't have to modify the functions in my ~/.spacemacs.d/init.el that shouldn't be modified. I've also wanted to have profile specific configurations -- like if I have multiple Emacs processes, have processes dedicated to gnus, so it wouldn't need all of the other layers other than my basic layers installed.

I'm not sure how to integrate this sort of thing into Spacemacs, but I can see how it would be useful. I'm certainly not the only one who uses the same configuration on multiple machines and don't need the same configuration on each. How to best do this?

@syl20bnr
Copy link
Owner

My first proposal is something that is an application of what you are doing:

  • define a list of profile symbols
  • for each declared profile, spacemacs will load the default function as well as the profile functions in the order of profile declaration.

Default functions are the functions we have currently in the dotfile.
Profile functions are constructed like this (to match the construct for user specific functions):

dotspacemacs/<profile-symbol>-<default function suffix>

Examples:
1)

  • default -> dotspacemacs/layers
  • profile my-profile -> dotspacemacs/my-profile-layers
  • default -> dotspacemacs/user-config
  • profile my-profile -> dotspacemacs/my-profile-user-config

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!

@github-actions github-actions bot added the stale marked as a stale issue/pr (usually by a bot) label Feb 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core Discussion Enhancement ☺ stale marked as a stale issue/pr (usually by a bot)
Projects
None yet
Development

No branches or pull requests

2 participants