Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trigger of the Snippets #119

Open
clsmt opened this issue Feb 19, 2017 · 7 comments
Open

Trigger of the Snippets #119

clsmt opened this issue Feb 19, 2017 · 7 comments
Labels

Comments

@clsmt
Copy link

clsmt commented Feb 19, 2017

I have been using this package for a while now. And I am bothered by this issue more and more.

I would strongly recommend using \begin as trigger as opposed to just begin.

We are very used to type \begin{equation} to start an equation. It would make sense that now we just have to type \be... and \begin pops up as an option. Now an enter produce the full equation commands.

But as of now, when I type \begin, \begin{equation} pops up, and an enter would produce something like \\begin. I have to go back and erase the first \.

Sure, if you are used to just begin giving you \begin, it saves you a character, but experienced latex writers would have to change their habit. If god forbidden they later on have to use other editors (for example writing something online) for latex, they have to change their habit again. What a pain.

@gnat79
Copy link

gnat79 commented May 19, 2017

I agree completely - I spend a lot of energy deciding whether to type "begin" or "\begin" depending on whether I want matching or not. I could save a lot of time by always typing "\begin".

@Aerijo
Copy link
Collaborator

Aerijo commented Jul 22, 2017

Not to mention that latex is all about typing English. The word "begin" (and other snippet starters) could come up a lot, and it is annoying to see the snippet suggestion every time. Restricting it to when the backslash character is used will prevent this, and be more consistent with author's habits.

@Aerijo
Copy link
Collaborator

Aerijo commented Aug 5, 2017

@clsmt I now realise why they are this way: the autocomplete-snippets package does not support punctuation in snippet prefixs. If you want a workaround for this issue, do the following

  • Run the command git clone https://github.com/atom/autocomplete-snippets
  • Make a link to this folder in the .atom/packages folder (one is probably automatically made in .atom/dev/packages. This one will only activate in dev mode). This step will allow your local copy of the package to take priority.
  • Now, on your local copy, navigate to autocomplete-snippets/lib/snippets-provider.coffee.
  • Make the changes shown in the commit link here
  • In addition to this, change line 27 to regex = /[.]*[\w0-9_\-\\]+$/. This allows \ to start a snippet as well, which is what we want.
  • Reload Atom, and the changes should take effect. Now you can define your own snippets that begin with \.

I will try and get this behaviour working by default, but I don't know much about hacking Atom yet. The developers of the autocomplete-snippets package only want commits that work perfectly, and I guess our suffering isn't good enough for them ¯\_(ツ)_/¯

@yudai-nkt
Copy link
Collaborator

I DO agree with including backslashes to snippet trigger. However, as can be seen in atom/autocomplete-snippets#67, snippets starting with non-letter are not autocompleted (snippet itself should work). That's why we can't do that.

@Aerijo
Copy link
Collaborator

Aerijo commented Dec 18, 2017

This feature would be nice, but would have to be done by the autocomplete-snippets package, so I'm adding a wontfix label to this issue.

@Goysa2
Copy link

Goysa2 commented Feb 19, 2018

@Aerijo Hi! The autocomplete-snippet package has been update and the problem cannot be solved using the solution you provided. Any advice on how to fix it now?

@Aerijo
Copy link
Collaborator

Aerijo commented Feb 20, 2018

@Goysa2 Hey, are you perhaps referring to this change? atom/autocomplete-snippets#92

If so, that is unrelated to the current issue. If not, can you point me to the change, because I cannot reproduce it using the latest version of Atom.

EDIT: My bad, I thought you were saying the issue was resolved.

For the solution I provided, it seems I had a typo in it. Additionally, they have now converted to JavaScript (form CoffeeScript). A better set of steps would be:

  • Navigate in the command line to where you want to store the package. It does not need to be in any particular directory
  • Run the command git clone https://github.com/atom/autocomplete-snippets in the command line
  • Make a link to this folder in the .atom/packages folder. Do this by navigating to the downloaded package and running the command apm link
  • Now, in the downloaded package, navigate to autocomplete-snippets/lib/snippets-provider.js.
  • Delete the getSuggestions method and replace it with the following
  getSuggestions({scopeDescriptor, editor, bufferPosition}) {
    let prefix = this.getPrefix(editor, bufferPosition)
    if (!(prefix != null ? prefix.length : undefined)) { return }
    const scopeSnippets = this.snippetsSource.snippetsForScopes(scopeDescriptor)
    return this.findSuggestionsForPrefix(scopeSnippets, prefix)
  }

  getPrefix(editor, bufferPosition) {
    let regex = /[\w0-9\-\_\\]+$/
    let line = editor.getTextInRange([[bufferPosition.row, 0], bufferPosition])
    let match = line.match(regex)
    return match ? match[0] : ''
  }
  • Reload Atom. Now you can define your own snippets that begin with \.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants