Is it possible to use the font of tuareg in caml-mode under Emacs?

别等时光非礼了梦想. 提交于 2019-12-24 12:06:05

问题


For Indentation of “if”, i have to use caml-mode under Emacs.

But I find the font of tuareg is more colorful than caml-font, so my question is whether it is possible to use the font of tuareg in caml-mode.

Also, with the current .emacs which requires caml-font, when I open a .ml file, some lines (especially in the beginning of the file) are not highlighted. If I go to those lines, modify them, they will change their color. Could anyone tell me how to fix that problem?

Also, do you have some better fonts for ocaml programs to suggest, besides the one of tuareg and caml-font?

Thank you very much!


回答1:


Do you mean that you like the colors better or that their are more colors?

If the latter, it's probably difficult to use tuareg font-locking with caml-mode, though I only looked at the two a little bit.

If it's the former, you can simply customize the faces used by caml-mode to use better faces (by which I mean typeface or "color"). With a sufficiently new emacs, put your cursor on the face that you want to change and type M-x customize-face RET. It will suggest the name of the face that you are on, so hit return again. Then you can change the face in any way you want. As a first step you might keep tuareg.el open and check what faces are there, for example

(defface tuareg-font-lock-governing-face
  '((((background light)) (:foreground "blue" :bold t))
    (t (:foreground "orange" :bold t)))
  "Face description for governing/leading keywords."
  :group 'tuareg-faces)

is the definition of the face used for let, so you would just put your cursor on let, M-x customize-face RET RET, then change the foreground to blue and turn on bold (assuming you have a light background). Don't forget to save it.

Alternately, you can edit caml-font.el and change the caml-font-lock-keywords section to use the fonts you like (which could be from tuareg). If you want to add to your .emacs instead then you should change it to (setq caml-font-lock-keywords ...).

(defconst caml-font-lock-keywords
  (list
   ...
;definition
   (cons (concat
          "\\<\\(a\\(nd\\|s\\)\\|c\\(onstraint\\|lass\\)"
          "\\|ex\\(ception\\|ternal\\)\\|fun\\(ct\\(ion\\|or\\)\\)?"
          "\\|in\\(herit\\|itializer\\)?\\|let"
          "\\|m\\(ethod\\|utable\\|odule\\)"
          "\\|of\\|p\\(arser\\|rivate\\)\\|rec\\|type"
          "\\|v\\(al\\(ue\\)?\\|irtual\\)\\)\\>")
         ;; 'font-lock-type-face)
         'tuareg-font-lock-governing-face)
   ...
   ))


来源:https://stackoverflow.com/questions/6763001/is-it-possible-to-use-the-font-of-tuareg-in-caml-mode-under-emacs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!