I can't load an .el package on emacs - emacs

So I downloaded an .el file, I put it on the ~/.emacs.d/elpa/ folder, but it won't appear on the M-x list-packages. How do I make it appear there or how can I install this file/package?

There are two ways of installing an Emacs package: either type M-x list-packages and install it from the list, letting Emacs download it for you, or download the package yourself and install it with M-x package-install-file.
Installing from a package archive
In the first case, note that there are several different package archives. The default value for the variable package-archives only contains GNU ELPA, but most people want to add MELPA to that list since it has more packages. To do that, you need to add the following to your .emacs file (copied from the MELPA web page):
(require 'package) ;; You might already have this line
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/"))
(when (< emacs-major-version 24)
;; For important compatibility libraries like cl-lib
(add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/")))
(package-initialize) ;; You might already have this line
After that, typing M-x list-packages should list more packages than you'll ever need :)
Installing from a downloaded file
There are two types of packages: single-file packages and multi-file packages. The former can be downloaded as a single .el file, while the latter are distributed as tarballs (.tar). Both types can be installed with M-x package-install-file.
Note that not every .el file can be installed as a package. The comments at the beginning of the file need to follow a certain convention, documented in the Simple packages node of the Emacs Lisp reference manual.
That leaves the possibility that the .el file you've downloaded is not installable as a package. In that case, you should put it in some other directory (~/.emacs.d/elpa is meant for installed packages only), add that directory to the load-path variable, and require the package. If you have foo.el and put it in ~/path/to/foo, it would look something like this:
(add-to-list 'load-path "~/path/to/foo")
(require 'foo)

An .el file is not a package. Installing it via ELPA is probably vastly preferrable to manually downloading a static .el file; perhaps the maintainer has a home page with ELPA (or Marmalade, etc) instructions.
In particular, a package will receive updates as they are made available, so you will not be forever stuck on an increasingly obsolete, unmanaged version (though quiet, fully automatic updates are not yet available or feasible, AFAICT).
But if you have to get by with just the file you already downloaded, you can put it pretty much anywhere you like, as long as that directory is included in the load-path. Manually mucking with the elpa directory is a bad idea, though; put it somewhere else.
Look for comments near the top of the file for any additional instructions; any autoloads, for example, will probably have to be configured separately, and usually completely manually.
This used to be how you always did things in older versions of Emacs, so you should find that the Internet is still practically bulging with guides and tutorials which explain the finer details of this mechanism, if this answer alone isn't sufficient.

Related

Installing emacs packages (elpa) and also adding loading code to .emacs?

I've installed a few packages from elpa and melpa. Some packages don't really require that I edit my .emacs file to add any hooks or include a (require 'fn) line. On the other hand some packages provide instructions that explain editing the .emacs file is part of the installation. I recently installed ace-jump-mode and the packaging system created a directory for the package in .emacs.d something like: ace-jump-mode-20130719.2053/ and the instructions for installation call for adding a few lines to my .emacs file.
So there are 2 parts to this question.
when is editing .emacs file required after installing a package?
Adding that path to ace-jump seems like it will break if ever I need to update the package, is there a better way of including the path in my .emacs file?
Different packages handle key bindings and loading differently. Sometimes you'll have to modify your configuration, and sometimes you won't. The best bet is to read the documentation for each thing you install, which you appear to already be doing.
You shouldn't have to explicitly specify the path to your ace-jump package. ELPA / package.el will take care of updating your load-path. The following snippet should work, without specifying that path manually:
;; No (add-to-list 'load-path ...)
(require 'ace-jump-mode)
;; Optional
(define-key global-map (kbd "C-c SPC") 'ace-jump-mode)

Emacs 24.3 dired+ won't load

I installed dired+ through list-packages (the folder was put in the elpa folder), and put '(add-to-list 'load-path "~/.emacs.d/elpa/")' in my init file (which I created myself), and '(require 'dired+) under. When I open emacs, I get an error telling me there's an error in my init file. If I remove the '(require 'dired+) line, the error stops, but again dired+ doesn't work when I call dired mode. The actual folder that was downloaded when I installed it is 'dired+-20130206.1702'. So I tried '(require dired+-20130206.1702), which again gave me an error on startup.
I'm at my wits end. I've tried everything I can think of, gone through the GNU emacs docs, googled the problem, looked at the answers here at Stack, and no luck. Does anyone have any suggestions? I'm using Windows XP.
It's impossible to say for certain without seeing all the code, but you appear to be quoting your forms for no reason.
i.e., these:
'(add-to-list 'load-path "~/.emacs.d/elpa/")
'(require 'dired+)
should be:
(add-to-list 'load-path "~/.emacs.d/elpa/")
(require 'dired+)
However that should just make them ineffectual, rather than causing errors directly.
Show us the code and the error message.
Edit:
Adding the /dired+/ to the end seemed to fix it ... Although I have no idea why. Any thoughts?
load-path holds a list of directories in which Emacs will look for libraries. It does not automatically descend into sub-directories, so you need to specify all relevant directories for your libraries. Your dired+ library is clearly in the ~/.emacs.d/elpa/dired+/ directory.
For menubarplus, you will similarly need to check to see which directory the library is in.
To be honest, I had thought that the package management in Emacs 24 would take care of this automatically; but as I've not been using it, I'm not certain.
Edit 2:
Yes, I suspect you have some other problem here. I just experimented with installing a library via the package manager (albeit from the default package repository, which doesn't include a dired+ package), and after restarting Emacs load-path contained the path for the new library without any intervention on my part.
I think Phils answered your question wrt loading Dired+ (specify the right directory, the one where you put dired+.el).
Wrt Menu-bar+, the feature name is menu-bar+, not menubarplus and not menu-barplus. So change your (require 'menubarplus) to (require 'menu-bar+).

How do I automatically (re)compile ELPA packages?

I'm now installing as much as I can through MELPA and Marmalade, and I manage my ~/.emacs.d using git. However, I have git ignore *.elc files.
This means that when I install a package on one system and then start using another system, git pull only gives me the *.el files. Using these files is often slower than using *.elc.
I tried adding the following to ~/.emacs.d/init.el:
;; load the packages we've installed. Note that package-install
;; byte-compiles the packages, but .elc is ignored by git so we force recompilation here
(byte-recompile-directory (expand-file-name "~/.emacs.d/elpa") 0)
(package-initialize)
Unfortunately, this isn't equivalent to the compilation done by package.el. For example, if I install emacs-eclim, package.el doesn't compile emacs-eclim/company-emacs-eclim.el, and I get the following error:
Leaving directory `/home/wilfred/.emacs.d/elpa'
Compiling file /home/wilfred/.emacs.d/elpa/emacs-eclim-20130310.1237/company-emacs-eclim.el at Mon Mar 11 15:40:01 2013
Entering directory `/home/wilfred/.emacs.d/elpa/emacs-eclim-20130310.1237/'
company-emacs-eclim.el:35:1:Error: Cannot open load file: eclim
Warning: reference to free variable `multiple-cursors-mode'
Warning: reference to free variable `mc--read-char'
Warning: assignment to free variable `mc--read-char'
Warning: reference to free variable `multiple-cursors-mode'
Warning: reference to free variable `mc--read-quoted-char'
Warning: assignment to free variable `mc--read-quoted-char'
Warning: reference to free variable `rectangular-region-mode'
Warning: reference to free variable `rectangular-region-mode'
How do I make Emacs byte-compile only the same files as package.el would?
package.el actually uses exactly the same method, it's just recompiling on startup makes the errors more noticable.
The function used is package--make-autoloads-and-compile, which calls:
(byte-recompile-directory pkg-dir 0 t)
So the original code in the question is correct. However, to recompile a directory that isn't yet compiled, you can do the following:
(require 'dash)
(require 'f)
(defun was-compiled-p (path)
"Does the directory at PATH contain any .elc files?"
(--any-p (f-ext? it "elc") (f-files path)))
(defun ensure-packages-compiled ()
"If any packages installed with package.el aren't compiled yet, compile them."
(--each (f-directories package-user-dir)
(unless (was-compiled-p it)
(byte-recompile-directory it 0))))
(ensure-packages-compiled)
I recommend not keeping the packages in version control (you wouldn't put .o files under revision control, would you?). Here is the code I use to keep my packages in sync:
(setq jpk-packages
'(
ac-dabbrev
...
yasnippet
))
(package-initialize)
(add-to-list 'package-archives
'("melpa" . "http://melpa.milkbox.net/packages/"))
(add-to-list 'package-archives
'("org" . "http://orgmode.org/elpa/"))
(when (not package-archive-contents)
(package-refresh-contents))
(dolist (pkg jpk-packages)
(when (and (not (package-installed-p pkg))
(assoc pkg package-archive-contents))
(package-install pkg)))
(defun package-list-unaccounted-packages ()
"Like `package-list-packages', but shows only the packages that
are installed and are not in `jpk-packages'. Useful for
cleaning out unwanted packages."
(interactive)
(package-show-package-list
(remove-if-not (lambda (x) (and (not (memq x jpk-packages))
(not (package-built-in-p x))
(package-installed-p x)))
(mapcar 'car package-archive-contents))))
I put the above in init.el (which of course is under version control), and it installs any packages that don't exist yet when emacs starts up. Updating is done from the buffer package-list-packages creates. package-list-unaccounted-packages shows all the packages that are installed but not in my jpk-packages list, and makes it easy to remove the ones that I took out of the list.
To answer your specific question, I'd just delete the elpa directory and reinstall everything (using the above code).
The solution I like to the more general question of "How do I automatically re-compile any outdated .elc file" is to use https://github.com/tarsius/auto-compile
I used to have a handful of custom solutions which covered most situations I ran into, but this library covers everything I was doing and more besides. Just initialise it before loading anything else, and you're sorted.
As to the original question of not compiling files which were not originally compiled, that's what the 0 argument to byte-recompile-directory does, so you're explicitly asking for that behaviour. The default behaviour is to only recompile existing outdated .elc files, so you should simply remove that 0.
I do not know the answer to your specific issue about byte-compiling packages exactly the same way package.el would.
However, for your more general problem about maintaining your emacs configuration directory in git while installing extensions through Melpa or marmalade, I suggest you give a look to pallet, which has been designed to solve this very problem.
(byte-compile-file) worked for me when I need to manually recompile packages I have previously installed using elpa.
Particularly for this situation: https://github.com/yjwen/org-reveal/issues/76t
The problem you have is simply that you byte-compile files before initializing your packages. If you switch the two lines, your problem should disappear. The error you get (Cannot open load file: eclim) is because ~/.emacs.d/elpa/emacs-eclim-20130310.1237/ is not yet in your load-path, and package-initialize will add it to your load-path (along with a few other things).

Customize the list of packages that emacs-prelude provides

I see at this link how emacs prelude ensures that a set of packages is installed when emacs starts. I was wondering if I could somehow extend the variable prelude-packages to add some other packages, without changing the prelude-packages.el file?
Barring that I was wondering how I could define a list of packages that are installed at start-up if they aren't currently installed.
You can place a .el file in personal/ directory in Prelude. Prelude loads any .el file it finds there in an alphabetical order. Below is the content of my personal/00-packages.el file.:
(require 'package)
(add-to-list 'package-archives
'("marmalade" .
"http://marmalade-repo.org/packages/"))
(package-initialize)
;; My packages
(setq prelude-packages (append '(
drupal-mode
nginx-mode
) prelude-packages))
;; Install my packages
(prelude-install-packages)
"00" is added to the file name to ensure that the file is loaded before all personal customizations. Add any new package you need to the list being appended to prelude-packages.
Also, if you want to use any mode that is not available in MELPA or Marmalade, you can simply drop the mode's file in personal folder and Prelude will pick it up while loading. If there are any customizations to that mode, simply create another .el file and add the Emacs Lisp code there.
Prelude recommends to use
(prelude-require-packages '(some-package some-other-package))
if you have several package. Or in case you want to add just one package:
(prelude-require-package 'some-package)
If you want you can still maintain your package list in a variable:
(setq my-packages '(drupal-mode nginx-mode toto-mode)
(prelude-require-package my-packages)
In your .emacs file you could add code like this (very similar to the code in the link you sent) to check if each package is installed and install it if is not:
(dolist (package '(eredis anything erlang elnode))
(unless (package-installed-p package)
(package-install package)))
In answer to your question there's no reason you can't do this after the prelude code has run.

How to install a Emacs plugin (many times it's a .el file) on Windows platform?

I'm new to Emacs. I found many emacs plugins are released as an .el file. I'm not sure how to install them. Can I just put them in my emacs installation directory?
After placing it, say myplugin.el to your ~/.emacs.d/ directory, add the following in your .emacs file:
(add-to-list 'load-path "~/.emacs.d/")
(load "myplugin.el")
Also, in many cases you would need the following instead of the second line:
(require 'myplugin)
In any case, you should consult the documentation of the package you are trying to install on which one you should use.
If you are unsure where your ~ directory is, you may see it by typing C-x d ~/ and pressing Enter.
As already stated, you'll need the location of the file to be in Emacs' load path.
Read the comments at the top of the file to see if it has any particular installation or usage instructions. Authors often provide this information, and there isn't one single correct way to do it, so it's sensible to look.
Failing that, if the file contains a (provide 'some-name) line (typically at the end of the file), then you would be expected to use (require 'some-name) to load it.
You may also wish to byte-compile the library for speed (but that's a different question).
Many times, an emacs plugin will consist of a directory of elisp files that need to be accessible from the load path. A simple way to ensure that all individual elisp files as well as subdirectories of elisp files are included in the load path and accessible is to do something similar to the following:
Create a directory called ~/.emacs.d/site-lisp.
Install any single elisp files in the ~/.emacs.d/site-lisp directory.
Install any packages that consist of multiple elisp files in a subdirectory under your ~/.emacs.d/site-lisp directory.
Add the following code to your ~/.emacs file to ensure that Emacs "sees" all the elisp files that you have installed:
(add-to-list 'load-path "~/.emacs.d/site-lisp")
(progn (cd "~/.emacs.d/site-lisp")
(normal-top-level-add-subdirs-to-load-path))
This will ensure that all elisp files that are located either in either the ~/.emacs.d/site-lisp directory or in a subdirectory under that directory are accessible.
Some supplementary information:
MATLAB.el comes from http://matlab-emacs.sourceforge.net/
On windows, use the load path that looks like this:
(add-to-list 'load-path' "C:\\Dropbox\\Portable\\emacs\\matlab-emacs")
If you want FULL MATLAB functionality you should use:
;;MATLAB Mode:
(add-to-list 'load-path' "C:\\Dropbox\\Portable\\emacs\\matlab-emacs")
(require 'matlab-load)
if you just want to edit text files:
;;MATLAB Mode:
(add-to-list 'load-path' "C:\\Dropbox\\Portable\\emacs\\matlab-emacs")
(autoload 'matlab-mode "matlab" "Enter MATLAB mode." t)
(setq auto-mode-alist (cons '("\\.m\\'" . matlab-mode) auto-mode-alist))
(autoload 'matlab-shell "matlab" "Interactive MATLAB mode." t)