2

I am having a very weird issue with my init.el file. At startup, some of the commands in it run fine (so I know Emacs is able to pick the correct file), but others only run when I manually load the file using M-x load-file RET ~/.emacs.d/init.el RET (so I know those commands are syntactically correct as well). Here is a working example:

(setq package-enable-at-startup nil)
(setq doc-view-continuous t)
(package-initialize)


(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package))

(eval-when-compile
  (require 'use-package))
(use-package yasnippet
  :config
  (yas-reload-all)
  (yas-minor-mode 1)
  :ensure t)
(use-package auto-complete
  :ensure t
  :config
  (auto-complete-mode 1)
  )

; The following command is not run at startup. But runs when I load the file manually.
(setq line-spacing 0.3)

(yas-minor-mode 1)

(global-display-line-numbers-mode)
;If I remove the next command, startup line numbers are no longer relative, but they are with it.
(setq display-line-numbers-type 'relative) 

I tried removing the top commands (all upto to line-spacing), but on removing them even the line numbers were no longer working on startup.

I am using Mac OS X Mojave. M-x emacs-version RET gives the following: GNU Emacs 26.3 (build 1, x86_64-apple-darwin18.2.0, NS appkit-1671.20 Version 10.14.3 (Build 18D109)) of 2019-09-02. I had installed it along with AucTex.

I am fairly new with Emacs and Lisp, so please let me know if I should provide some more information.

3

All of your code is running. The trouble is, line-spacing is a buffer-local variable. From the help for this variable (which I found by C-h v line-spacing):

Automatically becomes buffer-local when set.

That means changing the value of the variable only effects line spacing in the current buffer, not all buffers.

In order to change the default value of line-spacing, you need to change it using the Customization interface: M-x customize-variable lines-spacing.

| improve this answer | |
  • 1
    I see! That makes a lot of sense! Can you elaborate on how to identify buffer-local commands. It turns out even the commands on autocomplete-mode and yas-minor-mode are only running locally, and I want to run them globally – cauthon14 Oct 15 at 0:53
  • I don't know of an easy way to get a list of all buffer-local variables. It's something that comes up case by case, whenever an individual developer wants to limit a feature to a single buffer at a time. This is common for things that only make sense for particular file types. Once you're aware of it, you'll know to pay attention to this detail when reading documentation. – Tyler Oct 15 at 1:33
  • 3
    You don't always need to use Customize to set default values for buffer-local variables. Often (usually?) you can do (setq-default local-variable value) to set the global default of <variable> to <value>. – Tyler Oct 15 at 1:34

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.