Atom 配置

lightup37

2020-11-12 19:23:21

Personal

来看的读者可以提点建议 /kel 笔者希望这篇文章可以上日报 /kel 无奖竞猜: 本文右上角所有播放的歌曲. **在本文中, 笔者默认读者都已经安装好了 Atom**. **[Atom 入门指南](https://80358.blog.luogu.org/atom-qwq)**. ## 插件 ### 一些笔者推荐的插件 ### simplified-chinese-menu 汉化包. ### default-language 这个插件将在您打开一个新的文件时使用某种语言的高亮. ### editor-background 这个插件将让您可以使用图片作为背景. ### bracket-complete (在安装 Atom 后已经存在) 这个插件是括号补全, 建议将其关闭. 以上插件开启与不开启的效果如下: ![](https://cdn.luogu.com.cn/upload/image_hosting/akmuh583.png) ![](https://cdn.luogu.com.cn/upload/image_hosting/tcfxpw5s.png) * auto close 问题 : 打开时才会补全, 笔者在此表示抱歉. ## Atom 用户启动脚本浅探 —— 实现缺省源 笔者在配置 Atom 时经常遇到无法配置缺省源的问题. 笔者一开始采用用户代码片段来解决这个问题, 即定义代码片段 ``source`` 为缺省源, 但是笔者在使用一段时间后认为这种解决方法是一种非常丑陋的实现 ~~*其实就是想搞事*~~, 于是在网上寻求解决方案 ~~*(您们搜到的那个提供了解决方案的帖子可能就是笔者回复的)*~~, 未果后发现了 Atom 有一个选项 : 用户启动脚本. 在打开后笔者发现这个脚本会在每次打开新的操作面板是启动. 笔者于是非常快的给出了一种实现: ``` atom.workspace.observeTextEditors (editor) -> editor.onDidOpen -> editor.insert "Saved! #{editor.getPath()}" ``` 然而这段代码是错误的, 它甚至过不了编译. 笔者在查询 [Atom 的 api](https://flight-manual.atom.io/api/) 后解决了此问题. ``` atom.workspace.observeTextEditors (editor) -> editor.insertText('/*CODE*/') ``` 这样可以通过编译, 但是笔者发现这将会在打开任意文件后插入``/*CODE*/`` 这段代码. 本着求真的精神, 笔者研究了脚本的语言——[Coffee Script](http://coffee-script.org/). 在这里笔者不会详细介绍这门语言. *(如果你和我一样是星际玩家)注意当你使用 ``something if X ?`` 时, 这个语句被等价为 ``if (typeof X !== "undefined" && X !== null) something``.* ![](https://cdn.luogu.com.cn/upload/image_hosting/g20a1rus.png) ![](https://cdn.luogu.com.cn/upload/image_hosting/x9n27bx2.png) 但是这样不能够移动你的光标的初始位置. 我们使用 Atom 提供的移动编辑器中光标的函数 (``editor.moveUp()`` 和其它 3 个) 将光标移动到想要的位置. 这里放上暂时的最终成果 (用 Atom 的可以直接拿去用): ``` atom.workspace.observeTextEditors (editor) -> isEmpty = editor.isEmpty() editor.insertText('#include<bits/stdc++.h>\n#define f(i,x,y) for(int i=x, i##end=y; i<=i##end; ++i)\n#define d(i,x,y) for(int i=y, i##end=x; i>=i##end; --i)\n#define ll long long\nchar ch;\nint rd() {\n int f=1, x=0; ch=getchar();\n while(!isdigit(ch)) { f=((ch==\'-\')?-1:f); ch=getchar(); }\n while(isdigit(ch)) { x=x*10+ch-\'0\'; ch=getchar(); }\n return x*f;\n}\nvoid rd(int& x) { x=rd(); }\nusing namespace std;\nint main() {\n \n return 0;\n}') if isEmpty == true? editor.moveUp(2) if isEmpty == true? editor.moveRight(2) if isEmpty == true? ``` 效果: ![](https://cdn.luogu.com.cn/upload/image_hosting/cutlibvo.png) ### 用户启动脚本的更多应用 笔者暂时没有发现.