EmilySeville7cfg · 2022-06-29 23:57
Hello! I am trying to follow [this](https://linuxhint.com/configuring_emacs_python/) tutorial to setup Python environment. Firstly I wanna to add custom theme to Emacs. My `.emacs` is:
```
(defun setup-ui ()
"Modifies user interface."
(global-linum-mode)
(set-face-attribute 'default nil :height 200)
(let ((packages '("apropospriate-theme")))
(mapc #'(lambda (package)
(unless (package-installed-p package) (package-install package)))
packages)
)
)
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(package-initialize)
(package-refresh-contents)
```
But when I start emacs theme installation fails with `Package ‘apropospriate-theme-’ is unavailable`. Why there is a trailing dash at the end? And why my init file fails?
HM0880 · 2022-06-30 01:48
I'd remove the `(let ((packages [...]` block (the middle block) and run `M-x package-install RET apropospriate-theme` to install the theme. Then run `M-x load-theme RET apr-theme` to load the theme.
Not sure why there's a trailing dash, but my instructions should help.
your_sweetpea · 2022-07-15 07:22
I strongly recommend using [use-package](https://github.com/jwiegley/use-package) for this, it's maintained by the emacs maintainer and the :ensure keyword would allow it to automatically fetch using package.el.
If you wish to do it this way though, I would write it as follows:
(let ((packages '(aproprospriate-theme)))
(dolist (package packages)
(unless (package-installed-p package)
(package-install package))))
You also likely want to make sure you call `(package-refresh-contents)` before this, or perhaps `(package-update-all)`, since it calls `(package-refresh-contents)` then updates all installed packages with new versions, which the above code (and your code) doesn't handle at all.
The notable difference is that `aproprospriate-theme` isn't a string in the code above, it's a symbol.
Using `dolist` over `mapc` is largely personal preference, although a preference that emerged because `dolist` has better performance. Calling an anonymous function also induces a performance penalty. You probably don't need to worry about that too much though, I've spent far too many years tweaking my config.