Devilius
Devilius

Reputation: 321

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

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.

Upvotes: 1

Views: 614

Answers (1)

idleberg
idleberg

Reputation: 12882

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.

Upvotes: 2

Related Questions