How to add a comment style to an emacs mode

倖福魔咒の 提交于 2019-12-12 04:19:58

问题


I am looking to add an additional single line style of comments !* to the Fortran mode on emacs, I'd add this to my init.el file.

From what I can see this should be doable using the modify-syntax-entry command, but I am struggling to succeed and there doesn't seem to be a fortran-mode-syntax-table so I can't see how I'd hook it to the mode.

My current effort (which causes an error).

(modify-syntax-entry ?\!\* "< \n")
(modify-syntax-entry ?\n "< \!\*")

The error reads An error occurred while loading 'init.el': Invalid read syntax: ?


回答1:


I finally figured out how to do this, and it's worth mentioning that with a normal Fortran setup ! causes comments, but not in mine.

So what I add to my init.el is

(add-hook 'fortran-mode-hook   
(lambda () 
(modify-syntax-entry ?\! ". 1")
(modify-syntax-entry ?\* ". 2")
(modify-syntax-entry ?\n ">") ))

The first two modify-syntax-entry use the numeric syntax flags for a two character comment start sequence !* and > is the syntax class for comment ended, for which I have used \n to end the comment with a newline.

See https://www.gnu.org/software/emacs/manual/html_node/elisp/Syntax-Flags.html and https://www.gnu.org/software/emacs/manual/html_node/elisp/Syntax-Class-Table.html#Syntax-Class-Table for more details



来源:https://stackoverflow.com/questions/41123697/how-to-add-a-comment-style-to-an-emacs-mode

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