EMACS Warning (package): Unnecessary call to ‘package-initialize’ in init file - emacs

I am new to coding started just a month ago. I am preparing ahead for my bootcamp with EMACS. I followed a tutorial and was told to initialize package. The code I used was:
(package-initialize)
(require 'package)
(add-to-list 'package-archives ' ("melpa" . "http://melpa.org/packages/"))
(package-initialize)
I keep getting warning (package): Unnecessary call to ‘package-initialize’ in init file and I don't know what to do next or how to solve it.

According to the emacs changelog 1, you can get rid of the call to package-initialize if you use emacs >= 27:
Installed packages are now activated before loading the init file.
As a result of this change, it is no longer necessary to call
'package-initialize' in your init file.
Also,
if you want to ensure that your init file is still compatible with earlier versions of Emacs, change it to:
(when (< emacs-major-version 27)
(package-initialize))

Related

How to stop a package from initializing with package-initialize on emacs (slime)

I've been trying to get slime+sbcl working on my emacs (26.3) for a while. I first installed slime via melpa and that didn't work. I finally got slime able to work on a clean emacs (emacs -q) using quicklisp and the following code:
(load "~/quicklisp/slime-helper.el")
(setq inferior-lisp-program "sbcl")
However, when I put it into my actual init file and run it, it doesn't work. I figured that if I put package-enable-at-startup to nil and commented out package-initialize, that slime works. My guess is that the installed slime through melpa is "overriding" the slime initialization using slime-helper. I can't uninstall slime via melpa because of package dependencies and am worried I might mess something up. But I also need all of my packages to initialize except slime. So I was wondering if there was anyway to initialize all my packages, but suppress the slime package.
I think the easiest method would be to disable the loading of "elpa slime" with package-load-list. See its documentation with C-hv package-load-list Return. In short you'd put something like this in your init file.
(require 'package)
(setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3")
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/")
'("gnu" . "https://elpa.gnu.org/packages/"))
(setq package-load-list '((slime nil))) ;; don't load slime
(package-initialize)
(load (expand-file-name "~/quicklisp/slime-helper.el"))
(setq inferior-lisp-program "sbcl")
package-initialize will skip loading slime (and manipulating your load-path), allowing the "quicklisp slime" to appear first on your load-path. This may or may not break dependencies loaded by the package system. If they do break, I'd see if quicklisp can manage them and deal with them that way, or I would manually manage them.

How to debug connections to melpa with emacs

I'm trying to add packages via melpa in my init file. It was working, but today it stopped. To debug, I started with "emacs -q" and typed the following into my scratch buffer:
(require 'package)
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/"))
(package-initialize)
The first two lines seem to work. The third line gives me an error and stack trace:
(wrong-type-argument arrayp nil)
package--add-to-archive-contents(nil "melpa")
package-read-archive-contents()
Is the error with my setup? Do I have the wrong url for melpa? I'm using GNU Emacs 24.5.1.
Although I'm not very familiar with it, I took a quick look at the package.el code.
My guess is that your ~/.emacs.d/elpa/archives/melpa/archive-contents file is "corrupted". As a result, package--add-to-archive-contents is not finding an array for an element it would expect to get from that file.
I believe the archive-contents file is only a local cache. If you delete it, it will get rebuilt, and you should be all set.

adding package-repositories to emacs

I need to add various packages to my emacs installation. It comes with tromey as the only repository. The variable package-archives is not defined (!). I am running GNU Emacs version 24.3.1 on Linux. I set up the following code in my .emacs file:
(when (>= emacs-major-version 24)
(require 'package)
(setq package-enable-at-startup nil)
(setq package-archives '())
(package-initialize)
(add-to-list 'package-archives
'("melpa" . "http://melpa.milkbox.net/packages/") t)
(add-to-list 'package-archives
'("gnu" . "http://elpa.gnu.org/packages/"))
(add-to-list 'package-archives
'("marmalade" . "https://marmalade-repo.org/packages/"))
(add-to-list 'package-archives
'("org" . "http://orgmode.org/elpa/") t)
(add-to-list 'package-archives
'("tromey" . "http://tromey.com/elpa/") t)
)
By default, without this code, the variable package-archives isn't defined. After running this code, it is, and contains the right values, but doesn't seem to have any effect. I verified that this variable is not customized anywhere.
The problem is that I don't get to see any packages from the various archives I added; Only from tromey. Obviously I'm doing something wrong, but this code is supposed to work from emacs version 24 and higher.
Can someone suggest how to set up my repositories properly?
Everything worked well! What does that mean? That something in my .emacs file is conflicting with elpa?
That's exactly what it means.
Comment out half of your configuration (comment-dwim, bound to C-; by default, might be helpful here) and see if that fixes it. That will tell you which have contains the ELPA conflict. Repeat with the half that shows the problem to find which quarter is problematic, then again to find the eighth…
Pretty soon you'll find the cause, which might be a single sexp. Remove or adjust that, uncomment the rest of your config, and enjoy the plethora of packages that await.

cannot open load file: /yasnippet

I receive this message every time I start emacs
Emacs 24.2
Win7 64 and Ubuntu 12.10
yasnippet 0.8.0 installed with package-list
If there is a way to fix it ?
yasnippet doesn't get initialised automatically when installed with elpa, which I find unconventional. You still need to add the yasnippet directory into your load-path.
Here is my set up in my .emacs
;; yasnippet
(add-to-list 'load-path "~/.emacs.d/elpa/yasnippet-0.8.0")
(require 'yasnippet)
(setq yas-snippet-dirs '("~/.emacs.d/elpa/yasnippet-0.8.0/snippets" "~/Dropbox/Applications/Customise/emacs/myyassnipets"))
(yas-global-mode 1)
This is the sort of message I would expect to see if you're calling load or load-file in your init.el with a bad path. Look for any uses of those functions and correct the path if you can.
If this is in code you control, you probably want to call (require 'yasnippet) instead of directly loading the file.

Slime mode error

I was following the guide and information from A gentle tutorial to Emacs/Swank/Paredit for Clojure
However after opening elpa and installing clojure-mode, slime and paredit. I restarted emacs and then attempted to use M-x slime however it continually says no match . What am I doing wrong?
I then tried to install clojure-mode from marmalade http://marmalade-repo.org/packages I byte-compiled package el and then added
(add-to-list 'package-archives '("marmalade" . "http://marmalade-repo.org/packages/")) to my.emacs. However marmalade errors with
Symbol's value as variable is void: package-archives .
Unsure exactly what I am doing wrong I am on windows7 using emacs 23.3. I have clojure installed to c:/clojure.
Any help appreciated.
My init.el has both (require 'package) and (package-initialize). It's not very big, it looks like this:
(require 'package)
;; Add the original Emacs Lisp Package Archive
(add-to-list 'package-archives
'("elpa" . "http://tromey.com/elpa/"))
;; Add the user-contributed repository
(add-to-list 'package-archives
'("marmalade" . "http://marmalade-repo.org/packages/"))
(package-initialize)
I'm on emacs 24 (a development build) on Windows 7. I had trouble getting emacs 23 to work with packages too, it was easier for me to just upgrade.
By the way, I noticed that if I set a HOME environment variable, emacs looks there for the .emacs.d directory (instead of in %USER_PROFILE%\AppData\Roaming).
Download package.el (don't follow the instructions on the ELPA site, just download the package.el provided on marmalade's site).
Put package.el in your .emacs.d directory (~/.emacs.d/).
Add the following to your .emacs file (~/.emacs):
;;Load path to my packages
(add-to-list 'load-path "~/.emacs.d/")
;;Load ELPA (the package.el you downloaded from marmalade)
(require 'package)
;;Load Marmalade (the code found on marmalade's welcome page)
(add-to-list 'package-archives '("marmalade" . "http://marmalade-repo.org/packages/"))
That's it! I really hope this helps.
EDIT: Sorry, I forgot to mention that you need to add (package-initialize) at the end of the code I provided. If you don't add this line, the packages will install, but won't load.
I think, that you need to put
(require 'package)
before 'add-to-list'
P.S. and add following call after 'add-to-list'
(package-initialize)
this command will load installed packages and activate them
P.P.S. '(require 'package)' maybe not needed, but I'm personally not using 'package.el'
It seems to me you're missing either (require 'package) or (package-initialize). You can check out my setup here - I'm using both marmalade and clojure-mode on Windows 7 and it works like a charm.
Do not know it is same problem, I faced when I were trying to use quicklisp's swank/slime
Finally I found that few /contrib/*.el packages were dependent on each other
if A's dependency package is B, if B is not byte-compiled than A will not compile
when you do
(require 'A)
it will throw
Symbol's variable value is void: A
So ensure you compile each package than try require.