2

I am a vim user trying to covert to emacs/spacemacs, but I'm having a horribly difficult time configuring things that seem like a breeze others.

I want to limit the fill to 80 (mainly for .txt files and .org mode.. I thought the default was 80 anyway? Is this only for certain file extensions?), and I found this question which gives this line:

(setq-default fill-column 80)

but where do I put this?. I have tried putting it in init.el, the dotspacemacs/user-config section of my .spacemacs, and the dotspacemacs/user-init section of my .spacemacs. The keyboard combos C-u 80 C-x f work for setting the fill to 80 while I'm in the buffer, and M-q adjusts the fill if lines are overfilled.

Am I missing something here? From what I can see, this (dated) blog of a spacemacs contributor suggests placing such lines in dotspacemacs/user-config and not in init.el. Meanwhile, Eivind Fonn, another spacemacs contributor who has publicized his dotfiles on github, has everything in an init.el and no .spacemacs.

I should add that other statements such as (gobal-hl-line-mode) and (setq-default evil-escape-key-sequence "jk") work as expected for me. Do I have a big misunderstanding of how to configure spacemacs as my own or am I just mistaken on the intricacies of this specific function?

EDIT

I was mistaken on the command that I needed. I actually want auto-fill-mode instead of the default fill value. I tried putting

(auto-fill-mode 1)

in dotspacemacs/user-config and in dotspacemacs/user-init but neither work. If I simply execute it as a command, it works fine.

I decided to scrap spacemacs and start learning emacs with evil-mode from the ground up. If I put the (auto-fill-mode 1) into my ~/.emacs.d/init.el, it works fine. I even made a function that auto-enables this only in org-mode. Learning emacs from scratch has given me a much better understanding of how emacs works, but now that I am manually installing packages and configuring things on my own, I want all the pre-configured-ness of spacemacs back! So now my question is where do I put (auto-fill-mode 1) in my .spacemacs?

Version info:

OS: Ubuntu 14.04
Emacs: 24.4.2
Spacemacs: Develop Branch (Release 0.105.x)

  • 1
    How did you determine that putting (setq-default fill-column 80) in dotspacemacs/user-config doesn't work? – bmag Jul 15 '16 at 13:13
  • @bmag I updated my question - I had a misunderstanding of which command I needed. – haff Jul 18 '16 at 4:13
  • I updated the answer with a section about activating auto-fill-column – bmag Jul 18 '16 at 18:37
6

setting default value for auto-fill-column

Normally, you'd put such configuration in dotspacemacs/user-config, which is a function in your dotfile (~/.spacemacs).

It's possible to use a ~/.spacemacs.d/init.el as your dotfile instead of ~/.spacemacs, which I assume is what Eivind Fond does.

The original default value for fill-column is 70. In current develop branch, Spacemacs configures fill-column to a default of 80, so you probably don't need to do it yourself.

As Kevin wrote in the comment, keep in mind that we only set the default value for fill-column, and the value can be different in buffers or modes that set their own value for fill-column. When the value is changed for a certain major-mode, it is usually done in the mode-hook. So if, for example, you want Org buffers to have a fill column of 72, you'd add something like this to dotpsacemacs/user-config:

(add-hook 'org-mode-hook (lambda () (setq fill-column 72)))

I've used a lambda, but I recommend using named functions instead of lambdas when you want to add them to hooks, since it makes it easier to use remove-hook later if necessary.

You might want to read the sections about buffer-local variables and hooks in the manual.

enabling auto-fill-mode

auto-fill-mode is a local mode, so when you add (auto-fill-mode 1) to your user-config, it activates auto-fill-mode only for the buffer that is current when that line is evaluated. Instead, you want to add auto-fill-mode to the hook of any major-mode where you want to activate auto-fill-mode. For example, if you want to activate auto-fill-mode in Org buffers, you need to add it the org-mode-hook:

(add-hook 'org-mode-hook #'auto-fill-mode)

If you want to activate auto-fill-mode everywhere, you'd probably want to hook it into text-mode-hook and prog-mode-hook. This way auto-fill-mode will be enabled in every major mode that derives from text-mode or from prog-mode, so basically that covers (almost?) every buffer where it's logical to have auto-fill-mode turned on:

(add-hook 'prog-mode-hook #'auto-fill-mode)
(add-hook 'text-mode-hook #'auto-fill-mode)

These lines should be placed in dotspacemacs/user-config as well.

  • 1
    And don't forget that setq-default only sets the default value, which is only visible if buffers and modes don't have their own value for the variable. From the doc: The default value of a variable is seen in buffers that do not have their own values for the variable. So you might have the statement in the right place, but still not be able to see the effect of it in org mode or whatever. – Kevin Jul 17 '16 at 14:47
  • @Kevin That's good to know. Is there a way to get around this with hooks or something? (I updated my question with the statement that I actually want). – haff Jul 18 '16 at 15:57
  • Kevin, thanks I've added a paragraph about local values overriding the default value – bmag Jul 18 '16 at 18:36
  • 1
    @bmag is right in pointing out that hooks are the way to go to set up customizations on buffers with particular modes. Nice comprehensive answer on the topic. I can't think of anything else to add. Good luck with your new life of configuring and customizing emacs (hopefully not endlessly)! – Kevin Jul 18 '16 at 21:21
  • Great. That did the trick. Thanks a ton. Just to be sure I'm understanding correctly, when you say that auto-fill-mode is a "local mode", is that synonymous with "minor mode"? – haff Jul 18 '16 at 23:00

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.