Fermat618's Blog

Happy coding

Fortran 中根据语义的补全

Fermat618 posted @ 2013年12月14日 14:48 in 未分类 with tags vim python fortran ftplugin , 1783 阅读

Fortran 中的 if 结构,函数声明等,都有不少的信息冗余。如

if (3 > 2) then
    !...
endif

real function add(a, b)  
...
end function

后面的 endif, end function 等,长度都不少。这样虽然提高了可读性,但手动敲下未免还是太麻烦。把时间花在敲入一个很长还必定会有的东西上面,很不划算。如果用 snippet 之类的方案,需要记住一个 key, 然后每次按 tab 展开,除了语言本身,又多了一个记忆 key 的负担。

于是,我想到了一个更为自动化的补全方案,就是让程序根据已经输入的内容,在敲入回车键换行时,自己判定这是不是一个未完成的 if 结构,然后自动在后面补全 endif.

因为这个功能绑定到了一个很重要的按键上,所以功能要尽量的不添乱 。所以,我想到把当前行按照程序语义给解析出来。如果能成功的解析,就补全后面的内容;如果不行,就执行普通的Enter.

解析程序的语义,还可以带来另外的好处。一个是自动加空白,如

do i=1,n

给自动化成为

do i = 1, n

有了空格之后更加的好读。另一个功能是把一些冗余的东西省掉,如

if (a > 3) then

有用的信息只有

if a > 3

因此,只需要敲下上面的文字,再回车,就可以补全成符合 Fortran 语法规范的形式。

代码在此 https://github.com/fermat618/fortran-construct-complete

 

professional cleanin 说:
2022年4月22日 18:21

If you're trying to locate a maid within Dubai who focuses on kitchen cleansing then we will be your ultimate answer. All in our housemaids tend to be kitchen cleansing specialists. They will look after every moment detail inside your kitchen. Beginning with scrubbing the actual floors and countertops and getting rid of the oil and dirt in the kitchen wall space, maids will help you. They will even clean the actual appliances as well as ensure to keep the hygiene degree of your kitchen area.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter