I wanna add some hooks to web-mode and js2-mode, but it doesn't go well.

Here is what I am doing. I wanna to add header line for web-mode and js2-mode cuz they are derived from fundamental-mode. And I have to manually add these modes.

;; when editing js file, this feature is very useful
;; (setq-default header-line-format
;;               '((which-func-mode ("" which-func-format " "))))

(defun set-header-line ()
  (setq header-line-format
        '((which-func-mode ("" which-func-format " ")))))
(add-hook 'prog-mode-hook 'set-header-line)
(add-hook 'text-mode-hook 'set-header-line)
(add-hook 'js2-mode-hook 'set-header-line)
(add-hook 'web-mode-hook 'set-header-line)

The reason why the header-line disappear is due to the ranger. It shows up when I open the file with dired or treemacs, but not for ranger.

Here is the header-line-format value opened with dired and ranger.



I tried adding hooks to ranger-mode-load-hook and set ranger-modify-header to nil. Not working.

Does anyone have some ideas what's going on here?

  • My bad. I should use (defun web-hook-test () (message "web-mode test!")) (add-hook 'web-mode-hook 'web-hook-test) . My problem is not which-func-mode, it's the header-line-format not enabled in web-mode and js2-mode.
    – ztlevi
    Oct 29, 2017 at 4:04
  • Please make sure the code you quote actually causes the problem you're seeing.
    – Stefan
    Oct 29, 2017 at 18:13
  • I'm sure it's not working on my machine...ws2.sinaimg.cn/large/006tNc79gy1fkzrbg4ajbj31400m0tj6.jpg
    – ztlevi
    Oct 29, 2017 at 20:07
  • I add (message "NOOOOOOOO") in the set-header-line function. And it turns out I am not getting the message when I open the file but I get the message when init the web-mode and the header-line shows for the first opened file sometimes but doesn't for followings. ws1.sinaimg.cn/large/006tNc79gy1fkzroza0qaj30mi09fq7a.jpg
    – ztlevi
    Oct 29, 2017 at 20:21

1 Answer 1


I found the problem. The reason why the header-line disappear is due to the ranger. It shows up when I open the file with dired or treemacs, but not for ranger...

  • Does M-x customize-option RET ranger-modify-header RET deal with that?
    – phils
    Oct 29, 2017 at 23:54
  • @phils tried nil. No...
    – ztlevi
    Oct 29, 2017 at 23:59
  • I see that ranger-mode calls ranger-setup which remembers header-line-format (as ranger-pre-header-format), and ranger-revert-appearance then does (setq header-line-format ranger-pre-header-format). As ranger-setup is running in the mode body, that happens before the mode hooks run, so (if this is the issue) it's remembering and restoring the header line as it was before you modified it.
    – phils
    Oct 30, 2017 at 0:07
  • That behaviour should possibly be conditional upon ranger-modify-header.
    – phils
    Oct 30, 2017 at 0:09
  • n.b. I might be talking complete nonsense here -- I know next to nothing about ranger, so the code I'm looking at might not be relevant.
    – phils
    Oct 30, 2017 at 0:15

Your Answer

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

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