1

I have the following ~/.emacs:

;; Added by Package.el.  This must come before configurations of
;; installed packages.  Don't delete this line.  If you don't want it,
;; just comment it out by adding a semicolon to the start of the line.
;; You may delete these explanatory comments.
(package-initialize)

(require 'highlight-symbol)
(global-set-key [(control f3)] 'highlight-symbol)
(global-set-key [f3] 'highlight-symbol-next)
(global-set-key [(shift f3)] 'highlight-symbol-prev)
(global-set-key [(meta f3)] 'highlight-symbol-query-replace)

Then I added the file highlight-symbol.el to my ~/.emacs.d folder.

However when I start emacs I get:

Warning (initialization): An error occurred while loading ‘~/.emacs’:

File error: Cannot open load file, No such file or directory, highlight-symbol

I am new to emacs, what am I doing wrong?

5

Looking at the help from require (C-h f require)

(require FEATURE &optional FILENAME NOERROR)

If feature FEATURE is not loaded, load it from FILENAME. If FEATURE is not a member of the list 'features', then the feature is not loaded; so load the file FILENAME. If FILENAME is omitted, the printname of FEATURE is used as the file name, and 'load' will try to load this name appended with the suffix '.elc' or '.el', in that order.

So let's look at load help (either C-h f load or simply use TAB to navigate to the blue link then useRET):

This function searches the directories in `load-path'.

Again we can have a look at load-path help (either C-h v load-path, since it's a variable, or navigating to the link) and, probably, find that .emacs.d is not in the list.

This can be fixed by adding this to the init file:

(add-to-list 'load-path "~/.emacs.d")

For it to take effect immediately you can use C-x C-e (eval-last-sexp) with point at end of line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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