However that causes a File mode specification error: (error Lisp nesting exceeds ‘max-lisp-eval-depth’) when I open a pascal file. Any ideas on how I could do it better?
I looked at the macro expansion of the form you wrote and it looks like gibberish, so I don't think the :hook keyword allows expressions to be used as hooks, you need to define a function and use the function name:
Also, the weird single quote character you used probably doesn't work in Emacs (but maybe you have normal single quotes in your file and it's just lemmy's markdown messing things up).