You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 3, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Mar 3, 2023. It is now read-only.
Provide a simpler way to act on files by extension #2593
A very common question in IRC is "How can I make files with some extension set a certain behavior / use a certain grammar". As far as I know the state of the art is to put something like this in user.coffee:
Perhaps we could provide some syntactic sugar nicer than iterating over every EditorView, like say an object of path matchers and functions that get the current editor added to their context and run when initializing a new editor?
This is what I have in my init.coffee for this kind of thing:
# Settings to assign based on grammar name.grammarSettings='GitHub Markdown':showInvisibles:falsesoftWrap:truetabLength:4Java:tabLength:4Python:tabLength:4# Apply the settings to the editor session.## editorView - EditorView to which to apply the settings.# settings - The settings to apply.applySettingsForGrammar= (editorView, settings) ->editor=editorView.getEditor()
for key, value of settings
switch key
when'showInvisibles'theneditorView.setShowInvisibles(value)
when'softWrap'theneditor.setSoftWrap(value)
when'tabLength'theneditor.setTabLength(value)
# Apply grammar-specific settings.## editorView - EditorView to which to apply the grammar-specific settings.applySettings= (editorView) ->settings= grammarSettings[editorView.getEditor().getGrammar().name]
returnunless settings?applySettingsForGrammar(editorView, settings)
# Executes for each and every EditorView, past and future.atom.workspaceView.eachEditorView (editorView) ->applySettings(editorView)
editorView.getEditor().on'grammar-changed', ->applySettings(editorView)
Some things to note:
I key off of the grammar name because that way if the grammar is updated with new extensions, I get that update for free. It also makes the settings structure prettier.
I also set things on grammar-changed because sometimes I open a new file and it isn't recognized as X grammar and I have to set it after open
It should execute pretty fast because if there aren't any settings for that grammar, then it's a no-op, rather than matching the path to an ever increasing list of regular expressions
The one thing that I want to do is offer a way in the user's configuration of saying that the glob *.foo matches the Foo grammar. That way if I have a new type of Ruby file that uses an rbw extension, I can add it without having to patch the grammar.
This issue has been automatically locked since there has not been any recent activity after it was closed. If you can still reproduce this issue in Safe Mode then please open a new issue and fill out the entire issue template to ensure that we have enough information to address your issue. Thanks!
Activity
lee-dohm commentedon Jun 13, 2014
This is what I have in my
init.coffeefor this kind of thing:Some things to note:
grammar-changedbecause sometimes I open a new file and it isn't recognized as X grammar and I have to set it after openThe one thing that I want to do is offer a way in the user's configuration of saying that the glob
*.foomatches the Foo grammar. That way if I have a new type of Ruby file that uses anrbwextension, I can add it without having to patch the grammar.mehcode commentedon Aug 5, 2014
I use https://github.com/sindresorhus/atom-editorconfig for this purpose.
benogle commentedon Dec 5, 2014
This was fixed in #3718
lock commentedon Jan 24, 2019
This issue has been automatically locked since there has not been any recent activity after it was closed. If you can still reproduce this issue in Safe Mode then please open a new issue and fill out the entire issue template to ensure that we have enough information to address your issue. Thanks!