title: function using font lock functions requires restarting font lock mode
body: <p>I am confused about how font lock mode gets engaged. I do not have a statement that launches font lock mode in my <code>init.el</code>, but apparently it always runs as a minor mode. Furthermore I have the following function:</p>
  
  <pre><code>(defun testregexfunc ()
    (interactive)
    (make-variable-buffer-local 'font-lock-extra-managed-props)
    (add-to-list 'font-lock-extra-managed-props 'invisible)
    (font-lock-add-keywords nil
                            '(("\\(\\[\\)\\([a-zA-Z0-9_]+\\)\\(\\]\\)"
                               (1 '(face nil invisible t))
                               (3 '(face nil invisible t))))))
  </code></pre>
  
  <p>It uses font-lock specific things. But it only takes effect once I do <code>M-x testregexfunc</code> followed by <code>M-x font-lock-mode</code> twice. First time disables font lock mode second time starts it. But it is not running as a major mode now, as the buffer still displays whatever mode the buffer was in before. Okay, so I guess the function sets some values and only take effect once the mode restarts. I figured maybe I need to add a hook to font lock mode like this:</p>
  
  <pre><code>(add-hook
   'font-lock-mode
   'testregexfunc)
  </code></pre>
  
  <p>No... does not do anything. What do I need to do to not have to restart font lock mode for the function to work?</p>
  
  <p>I got that function from here and modified it some. I don't understand most of its definition and the documentation on font lock does not really help me much: </p>
  
  <p><a href="https://emacs.stackexchange.com/questions/28154/using-font-lock-regexp-groups">https://emacs.stackexchange.com/questions/28154/using-font-lock-regexp-groups</a></p>