0

I'm new to Emacs so I ended up following along with a tutorial by System Crafters. In the video he notes that he is not loading his primary configuration for the tutorial, so he loads an Emacs template with this command emacs -q -l init.el straight from the folder he created.

I setup all my settings in the init.el file, but now, they only load if I open Emacs while in the ~/.config/emacs directory (I am using Kubuntu Linux). The init.el file also only loads if I run Emacs the same way as in the template: emacs -q -l init.el. This is really annoying if I want to open Emacs from any directory. It works, but it's a workaround that I'd like to avoid if possible.

This is what's in my init.el file:

;; Emacs Configurations

(setq inhibit-startup-message t) ; don't show splash screen at startup
(add-to-list 'default-frame-alist '(fullscreen, .fullboth)) ; full screen at startup

(scroll-bar-mode -1) ; disable scrollbar

(add-to-list 'custom-theme-load-path "~/.config/emacs/themes") ; add theme path
(load-theme 'dracula t) ; load dracula theme


;; Org-Mode Configurations

(add-to-list 'load-path "~/src/org-mode/lisp") ; load org-mode

(global-set-key (kbd "C-c l") #'org-store-link) ; org store key bind
(global-set-key (kbd "C-c a") #'org-agenda) ; org agenda key bind
(global-set-key (kbd "C-c c") #'org-capture) ; org capture key bind

(setq org-adapt-indentation t
      org-hide-leading-stars t
      org-odd-levels-only t) ; set adapt indentation w/ clean stars

(setq org-agenda-files '("~/Org/test.org")) ; add test.org to agenda view

I tried going to my ~/Org directory and run Emacs using emacs and emacs -q -l init.el and both gave the same error stating the No such file or directory 'init.el'.

1

2 Answers 2

0

Well, obviously if you specify just the filename init.el then Emacs can only look in the current directory for the file. If you want it to load the file from a specific directory, simply specify the specific directory. It’s as easy as emacs -q -l ~/.config/emacs/init.el.

2
  • Okay this definitely works. I may have to make a bash alias for that though because it a bit tedious to type out every time. Thank you! Commented Sep 7, 2023 at 17:40
  • The real question is why are you bothering to specify any path at all? Especially when ~/.config/emacs is one of the default locations that Emacs looks when you don’t use the -l option…
    – db48x
    Commented Sep 7, 2023 at 22:27
0

See the Emacs manual, node Action Arguments.

That tells you how to use command-line option -l to load a library:

-l FILE’
--load=FILE

Load a Lisp library named FILE with the function load. If FILE is not an absolute file name, Emacs first looks for it in the current directory, then in the directories listed in load-path (*note Lisp Libraries::).

Warning: If previous command-line arguments have visited files, the current directory is the directory of the last file visited.

So if you don't want to specify the absolute file name for your init.el file, you can just add the directory where you put it to the value of variable load-path:

(add-to-list 'load-path "/directory/where/you/store/your/init-file/")
2
  • I tried adding the load-path as the directory, but it would still only open the exact same way. Is it possible there is conflict with my org-mode load-path? Commented Sep 7, 2023 at 17:39
  • Sorry; I don't know what you mean. You have only one load-path. It's a list of directories. If you have a separate question please post that separately.
    – Drew
    Commented Sep 8, 2023 at 2:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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