2

I'm using use-package and I want my fill-column to be set to 100 for files edited with js2-mode.

I tried to do so in the :config part, like:

(use-package js2-mode
  :config
  (setq fill-column 100))

(among other configuration) but it didn't work, fill-column was still 70 after loading a JS file (which activated js2-mode).

The way I made it work was by setting fill-column inside a hook like:

(use-package js2-mode
  :preface
  (defun me/js2-hook ()
    (setq fill-column 100))
  :config
  (add-hook 'js2-mode-hook #'me/js2-hook))

So, my question is, what was wrong with setting fill-column straight into :config? Why is the hook required?

Thanks!

1 Answer 1

2

fill-column immediately becomes buffer-local when set. So, when your config is evaluated, that buffer's fill-column is set... but then nothing else happens. If you set it with a hook, then fill-column will be set any time that hook is fired -- that is, every time a new buffer is created in js2-mode, and then fill-column will be set for that buffer.

You can, if you want, change the global default value of fill-column from 70 (which is silly) to another number, outside of use-package, like so:

(setq-default fill-column 79)

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.