With some help from the blog post found here, I have managed to write a small code for a test package (a minor mode) named niranjan. It is as follows.

(define-minor-mode niranjan-mode
   "Hello world"
   :lighter " niranjan"
   :keymap (let ((map (make-sparse-keymap)))
             (define-key map (kbd "C-c i") 'insert-niranjan)
(add-hook 'text-mode-hook 'niranjan-mode)
(provide 'niranjan-mode)

I hope this is correct. I saved it in ~/.emacs.d/elpa/niranjan with the name niranjan.el. Now I expect niranjan-mode to be listed when I press M-x, but unfortunately it isn't. Note that I am opening a new session while pressing M-x to use my new mode. What should be done to make a package appear in the normal package/mode list? Is there something to be done to refresh the list of packages? Have I placed the .el file in a wrong location?


You are right in assuming that the location is wrong. Emacs does not know about your niranjan directory. You assume that ~/.emacs.d/elpa/ is a special location and that emacs automatically knows how to add packages installed in there.

If you look at the contents of the variable load-path, you'll see that is not the case. Every package that has been downloaded and installed there in its own directory, have been explicitly, one by one, added to this list variable by your package management programme.

Commonly, if you do things manually, you add one directory to your load-path and place bare lisp files in it, e.g.:

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

More details in https://www.emacswiki.org/emacs/LoadPath

  • Thanks for your answer, but do you mean I should place niranjan.el at ~/.emacs.d/lisp/ and add (add-to-list 'load-path "~/.emacs.d/lisp/") to my .emacs? Is that all? – Niranjan Dec 28 '20 at 13:39
  • That is to way to make it available. After that, you will still need to require it to load the code. – Heikki Dec 28 '20 at 17:41
  • ... and you should add a line at the end of niranjan.el saying (provide 'niranjan). This tells Emacs (and you, if you ask) that your package is loaded. More precisely, it tells Emacs that the feature 'niranjan has been provided. – Phil Hudson Dec 30 '20 at 1:17

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.