Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs: Define a function which loads the file where the function itself is defined

Tags:

emacs

I'm refactoring a bit in my Emacs set up and have come to the conclusion that I want to use a different init file than the default one. So basically, in my ~/.emacs file, I have this:

(load "/some/directory/init.el")

Up until now, that's been working just fine. However, now I want to redefine an old command that I've used for ages, which opens my init file:

(defun conf ()
  "Open a buffer with the user init file."
  (interactive)
  (find-file user-init-file))

As you can see, this will open ~/.emacs no matter what I do. I want it to open /some/directory/init.el, or wherever the conf command itself is defined.

How would I do that?

like image 803
damd Avatar asked Mar 30 '12 16:03

damd


1 Answers

You can use find-function for this:

(defun conf ()
  "Open a buffer with the user init file."
  (interactive)
  (find-function this-command))
like image 186
Trey Jackson Avatar answered Nov 15 '22 05:11

Trey Jackson