5

I'm running into an order of initialization issue with hooks.

  • prog-mode-hook enables fci-mode
  • rust-mode-hook sets the fci-rule-column to 99.
  • on initial display the fill column shows at 80 (it's original value), moving the cursor redraws at 99.

This is not really a question about fci-mode, the solution is to set fci-rule-column before starting fci-mode (after or at the end of the rust-mode-hook).

To avoid needing to add generic code into all my programming mode hooks:

Is there a way to run a generic prog-mode-hook after more specialized hooks run?

phils
  • 48,657
  • 3
  • 76
  • 115
ideasman42
  • 8,375
  • 1
  • 28
  • 105

2 Answers2

6

You can use after-change-major-mode-hook:

(add-hook 'after-change-major-mode-hook 'my-after-change-major-mode-prog-mode)
(defun my-after-change-major-mode-prog-mode ()
  "Custom `after-change-major-mode-hook' behaviours."
  (when (derived-mode-p 'prog-mode)
    ...))

Refer to https://stackoverflow.com/a/19295380 for more details on the sequence of events when derived modes run.

phils
  • 48,657
  • 3
  • 76
  • 115
2

Here's another option:

(defun my-prog-mode-hook ()
  (when (derived-mode-p 'rust-mode)
    (setq fci-rule-column 99))
  (fci-mode 1))
(add-hook 'prog-mode-hook #'my-prog-mode-hook)
Stefan
  • 26,154
  • 3
  • 46
  • 84
  • This works too, I just wanted to keep all my rust options in one place instead of scattered all over the file. – ideasman42 Feb 25 '18 at 22:29
  • Indeed, the best choice depends on whether you prefer to keep all your Rust settings in one place or if you prefer to keep all your fci settings in one place. – Stefan Feb 26 '18 at 01:45