Where can I add my own autocompletion snippets in the atom editor?

自古美人都是妖i 提交于 2021-02-08 07:54:44

问题


I am using atom as my main editor for .tex documents. A feature which the bracket-matcher package gives that I really like is that it automatically inserts a closing }, any time I enter an opening {. I would like to add a similar feature for $, as I often end up using mathmode in latex. Where would I be able to add this? I do not want to add it in a snippet, where I would have to press tab for another $ to appear. I would simply like for a second closing $ to be automatically added (after my cursor) whenever I do open one. If this can be done with a setting that makes it enabled only on .tex files, that would be great.


回答1:


Since a standard snippet won't trigger on a single key-press, you will have to solve this programmatically. You will have to edit the following two files.

i. Init Script (init.coffee or init.js):

atom.commands.add 'atom-text-editor', 'custom:insert-dollar-pair', ->
  snippetBody = '\$ $1 \$$0'
  atom.packages.activePackages.snippets?.mainModule?.insert snippetBody

ii. Keymap (keymap.cson or keymap.json):

'atom-text-editor[data-grammar="text tex latex"]':
  '\$': 'unset!'
  '\$': 'custom:insert-dollar-pair'

PS: I think you don't even have to escape the dollar-sign, but it makes for good visual separation.



来源:https://stackoverflow.com/questions/39515721/where-can-i-add-my-own-autocompletion-snippets-in-the-atom-editor

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