0

I am trying to create a github repo of my .emacs.d/ for a group of students. Basically, I have two choices: A) simply take a "git snapshot" of my entire ~/.emacs.d/ including all the packages in elpa/, or, B) figure out how to just have an init.el in .emacs.d/ that, upon the first Emacs start, will go out and get all the packages . . . and the next time know not to because they're already there. How can this be done?

closed as unclear what you're asking by Drew, DoMiNeLa10 Mar 17 at 23:07

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • I would certainly vote for B) and use the package use-package to do what you want. – andrej Mar 17 at 20:11
  • So true: A) is the fall-back when you can't figure out B). – 147pm Mar 17 at 20:59
  • to figure out B) see github.com/jwiegley/use-package I think the documentation is really good. – andrej Mar 17 at 22:16
  • Is the question "Which is better, A or B?"? (Is that opinion-based?) Or is the question "How to do B?"? (In which case why even mention A?) The question is unclear. So far, we have an answer to "A or B?" (saying nothing about how to do B), and we have another answer for "how to do B?" (and saying something about how to do A). Please clarify the question, or it might be deleted because unclear. – Drew Mar 17 at 22:36
3

I'll always argue in favour of option (A) -- tracking the entire1 config. It gives you a config with all packages in a known and working state; a config which you can confidently reproduce in that same working state on other machines almost instantly by cloning a single repository, without any concerns about the upstream status of anything.

Relying on upstream sources means you are risking a broken configuration, so if that risk is unacceptable, then don't create those dependencies.


1 You'll likely want to .gitignore certain files and directories at the top level of ~/.emacs.d rather than committing literally everything (for example you wouldn't commit thumbs which contains cached image thumbnails for the local filesystem), but it's easy enough to inspect all the top-level items and decide whether or not you should add them to the repository.

  • This is a good point, and although I now better understand the whole package and use-package environment, I think I'll go with A). However, I'll have to separate out all personal ancillary cruft like personal file references. – 147pm Mar 18 at 1:15
  • @147pm Maybe you are better of with a whitelist: # Ignore everything /* # except those !.gitignore !/elpa – clemera Mar 18 at 11:36
0

You would do that with the package, use-package, which will, if ensure is set to t, do exactly what you're wanting it to do; look for the package on your system and install it if it's not on your system. If the package is already on your system, it will know not to go searching for it.

Your question here covers that bit: Melpa packages aren't being added

Here is the github repo for the use-package package: https://github.com/jwiegley/use-package
The README contains detailed information about how to use use-package


Regarding setting up a repository that will keep your configuration files .emacs.d/ directory without all the extras such as auto-save, the elpa/ directory, etc., you would want to set up a .gitignore file that sets your repo to only track your config files themselves.

This is a snippet from my .gitignore file for my emacs folder in my dotfiles repository:

# Ignore EVERYTHING in .emacs.d, then whitelist specific files/directories

emacs/.emacs.d/*
!emacs/.emacs.d/init.el

If your .emacs.d/ folder is the entire repository, you might only need something like this in your .gitignore file:

*
!init.el
  • The * says to ignore EVERYTHING, meaning don't track anything with git
  • The ![file] says to specifically track that file (effectively negating the effect of ignoring everything in the previous line, but just for that one file)

If you ultimately opt for OptionA - including your packages in your repository - you'll likely still want to use a .gitignore file as I've mentioned above (ignoring everything, then whitelisting specific files/directories). That .gitignore file might look something like this:

*
!init.el
!elpa/

...which means ignore everything EXCEPT init.el and the entire elpa/ directory.

  • It would help immensely to see some actual code of the use-package and ensure in action in your answer. This apparently is not connected to the ` package-selected-packages`, which is frustrating me greatly. From my other post you mentioned, I simply wasn't getting anything to work. I would also accept a link to some github that has what I'm talking about. – 147pm Mar 17 at 21:05
  • I actually just edited my answer to your other question with some sample code for use-package. I'm sorry, I forgot that you aren't notified of edits, only comments. (I'm still new to Stack Exchange). Almost all of my code is based on Harry Schwartz's files, found here: github.com/hrs/dotfiles/tree/master/emacs/.emacs.d – DerpKat Mar 17 at 21:24
  • Here's a link to the use-package repo, which has detailed info about how to use it: github.com/jwiegley/use-package Note: I've also included it in my Answer (below the link to your other question) in case this comment is deleted. – DerpKat Mar 17 at 21:42
  • I very much appreciate your efforts DerpKat, and I believe I understand my problem. I've been under the illusion that the package-selected-packages list was somehow involved in installing a packages if they weren't present. Actually, as you've been saying, it's the use-package ... :ensure that goes and get a package if it's not there -- and the accounting information is kept in elpa/ somewhere (another post question). Still, I'd like to know if package-selected-packages gets used by anything, or if it's just FYI. – 147pm Mar 18 at 1:22
  • Emacs has its own built-in way of handling the installation and upkeep of packages. package-install-selected-packages, as of Emacs 25.1, is part of that. The package, use-package, in part, is to make that process easier. Here is some reading about what package-install-selected-packages does and why package-selected-packages exists: endlessparentheses.com/… – DerpKat Mar 18 at 1:33

Not the answer you're looking for? Browse other questions tagged or ask your own question.