I have a buffer with name *fsharp info* which I want to change (programmatically) the mode from help-mode to my custom mode.

I created a simple major mode fsharp-info-mode to highlight fsharp documentation using markdown's font-lock.

(define-derived-mode fsharp-info-mode help-mode "fsharp-info-mode"
  "major mode for fsharp info."
  (setq font-lock-defaults '(markdown-mode-font-lock-keywords)))

With no success, I tried to enable it to the buffer with name *fsharp info* using

(add-to-list 'auto-mode-alist '("\\*fsharp info\\*" . fsharp-info-mode))

Looking in fsharp-mode, I discovered that the use with-help-window to create *fsharp info*. In the documentation, it says that help-mode is activate in the buffer (maybe that is why I can't change?)


I solved my problem temporarily advising fsharp-ac/show-info-window which is the function called by fsharp-mode to display the documentation.

(defadvice fsharp-ac/show-info-window (after fsharp-ac/show-info-window-after activate)
    (switch-to-buffer "*fsharp info*")

You don't describe or provide a link to information about fsharp-mode. But if that mode (what buffer(s) is it used in?) creates a buffer *fsharp-info* and puts it in help-mode then presumably that's the mode it should be in, no?

You can add a function to help-mode-hook that changes the major mode, if you like. The function would check that the buffer name is, say, *fsharp-info*, and if so then it would invoke your fsharp-info-mode instead of help-mode.

I'm guessing that's not a great idea, and there is likely a good reason fsharp-mode puts the buffer in help-mode.

Another possibility is to define a minor mode, and have a help-mode-hook function turn that on in buffer *fsharp-info*. In that case the major mode would still be help-mode, but your fsharp-info-mode would be a minor mode, active at the same time.

  • I liked the idea of creating a minor mode for that. I've never done but and it sounds as a good opportunity. Jun 2 '19 at 2:43

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.