Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Ability to import multiple snippets.cson files #124

Open
izuzak opened this issue Mar 30, 2015 · 32 comments
Open

Ability to import multiple snippets.cson files #124

izuzak opened this issue Mar 30, 2015 · 32 comments

Comments

@izuzak
Copy link
Contributor

izuzak commented Mar 30, 2015

From @morseldesign on March 29, 2015 19:51

Feature

Ability to do an @import or require() syntax for breaking up snippets into multiple files. For example @import "/snippets/documentation-snippets.cson" or require('snippets/javascript-snippets.cson').

Why

After awhile, snippet files can become pretty overwhelming to manage. Having multiple files would not only help with organization, but make it a little easier to manage changes to certain snippets.

Example

Given a file called snippets/javascript-snippets.cson with contents like:

###
  JavaScript Snippets
###
'.source.js':
  'Console log':
    'prefix': 'log'
    'body': "console.log($1);"

We could import it lnto ~/.atom/snippets.cson like:

# Your snippets
#
# Atom snippets allow you to enter a simple prefix in the editor and hit tab to
# expand the prefix into a larger code block with templated values.
#
# You can create a new snippet in this file by typing "snip" and then hitting
# tab.
#
# An example CoffeeScript snippet to expand log to console.log:
#
# '.source.coffee':
#   'Console log':
#     'prefix': 'log'
#     'body': "console.log $1'"
#

# Syntax #1
@import "snippets/javascript-snippets.cson";

# Syntax #2
require('snippets/javascript-snippets.cson');

Copied from original issue: atom/atom#6155

@thomasjo
Copy link

I say we cannot implement the suggestions; CSON is nothing more than JSON. Why not simply support what was previously (or still is?) documented regarding a snippets folder, e.g. ~/atom/snippets, and simply load every all CSON files in that directory? Simple and requires no unnecessary "ceremony".

Should be pretty trivial to implement as well, so might be candidate for good-first label.

@morseldesign
Copy link

Can I just have multiple snippets.cson files within ~/atom/snippets as opposed to a single ~/atom/snippets.cson? If so (didn't realized that was the case), I would agree with @thomasjo!

@thomasjo
Copy link

Not currently available. It was incorrectly documented that way in the
flight guide. I think it's something we should implement though.
On Mar 31, 2015 6:43 PM, "Morsel" notifications@github.com wrote:

Can I just have multiple snippets.cson files within ~/atom/snippets as
opposed to a single ~/atom/snippets.cson? If so (didn't realized that was
the case), I would agree with @thomasjo https://github.com/thomasjo!


Reply to this email directly or view it on GitHub
#124 (comment).

@morseldesign
Copy link

Ah. Well in that case, I do prefer your version. Managing imports would be a pain. Auto importing all files from ~/atom/snippets makes a lot more sense.

@thibmaek
Copy link

+1 for auto importing but just having anything at all available to manage snippets in partials would be so much better

@castlefields
Copy link

+1 this is a real must as my .cson file is becoming unmanageable. A simple ./snippets folder would be an ideal solution...

@NelsonScott
Copy link

+1 it's getting difficult to manage all my snippets, especially for different languages.

@castlefields
Copy link

The solution, for now, I am using is my own package. Within the package there is a ./snippets folder and within this I am currently creating multiple .cson files. Not ideal as any additional snippets added while working only show after reloading Atom. Therefore I'm using the default snippet.cson while working and then, at then end of the day, pasting any new snippets into my package - ready for start up next day.

Hopefully this solution means that if a ./snippets folder is ever added, as discussed above, I can just copy my .cson files into this...

@thibmaek
Copy link

@castlefields Would be great if you published that package to APM so we can use that method for now. 😉

@thibmaek
Copy link

@castlefields I created a similar solution to yours because I really got tired of the long snippets file.
Published to apm: https://github.com/thibmaek/modular-snippets

Install with apm install modular-snippets

@pmcalabrese
Copy link

👍

@adammagana
Copy link

It would be awesome to have project-specific snippet files as well. That way teams/repositories could have version-tracked snippets.cson files. I usually keep my snippets.cson files in a gist but it would be super awesome to have them versioned in my repositories with specific snippets in each. This isn't entirely in the same vein as the proposed idea above but having distributed snippet files is the general idea here. 😄

@wmadden
Copy link

wmadden commented Jul 12, 2015

👍 to project-specific snippets, as @adammagana proposed. It's particularly annoying when working across projects (sometimes across organizations) with different conventions/linting rules.

@IrksomeZeus
Copy link

👍 Auto-importing would be awesome and so would project specific snippets

@rossmcf
Copy link

rossmcf commented Nov 3, 2015

+1

1 similar comment
@rpedroni
Copy link

rpedroni commented Dec 7, 2015

+1

@garralab
Copy link

+10 project-specific snippets, really a must have
+1 multiple file snippets, would be much better to manage, but not as essential

@HaykoKoryun
Copy link

+9001 for project-specific snippets
sometimes you have snippets that would only work for a given project, so it doesn't make sense to have them in memory when you are not working on that project.
it would be awesome if the package would look for a snippets.[cson|json] in the root of the project and load that last.

@danielbayley
Copy link

My modular-keymaps package does exactly this, but for keymaps. It automatically reloads them on any change too. I'd imagine the code would be very similar for snippets. I also had the idea of adding the option to synchronise your snippets/ folder as Gists. Local snippets is another interesting idea…

@ewnd9
Copy link

ewnd9 commented Jun 12, 2016

I think project-specific snippets could be accomplished with a simple linking

$ ln -s snippets.cson $HOME/.atom/snippets/$(basename $PWD).cson

Edit: didn't take into consideration that snippets shouldn't intersect

@danielbayley
Copy link

danielbayley commented Jun 16, 2016

Well it turned out the code wasn't too similar after all due to the lack of an equivalent API for snippets, but I managed to work around it and now I have a proper modular-snippets package working locally.

Project specific snippets are implemented too; they are live reloaded for each project (and exist only while that project is open), and take precedence over any global snippets in your new ATOM_HOME/snippets/ directory (this is relevant only in case of matching scope selectors). Maybe this should be the other way around?

Local project snippets are loaded from the first file found in your project root in the order: snippets.cson/.snippets.cson, a snippets: object inside package.json, or, finally a snippets: object inside project.cson (this ties in with project-manager/project-plus and another package I am working on project-config).

@thibmaek I sent you a PM on the Atom #Slack asking if you'd possibly like to remove your modular-snippets package to make way for this, unless you really don't in which case I can publish as modular-snippets-plus instead. But please do let me know, as this is now ready to go! 😃

Edit: I devised a way to add to existing scope selectors rather than override them, and even prefix each snippet name key with it's file name, so any clashes should be minimal, but in the rare case they do then the local snippet will take precedence.

@HaykoKoryun
Copy link

@danielbayley awesome!

@rpedroni
Copy link

@danielbayley awesome indeed! Thanks!

@phpgit
Copy link

phpgit commented Jun 23, 2016

any package that we can install it to get multi snippets files loaded from '.atom/snippets' folder?

@danielbayley
Copy link

@phpgit Yep, I'll be releasing my modular-snippets package very shortly… just ironing out a couple of last-minute bugs. I'll announce it here when it's up.

@danielbayley
Copy link

Well I wanted to get this out a little sooner but life kept getting in the way 😄
Anyway, finally published here. 🎉
apm install modular-snippets

@kaytrance
Copy link

modular snippets project seems to be dead

@thibmaek
Copy link

@kaytrance yup, too bad though. There's an issue filed in there and a PR submitted too I think but @danielbayley seems to have left this project.

I'll see if I can whip something up.

@danielbayley
Copy link

@kaytrance @thibmaek Hi, sorry no it's not dead… actually, I have a complete re-write of it running locally. It's just dependent a few other Atom packages I haven't published yet!

@Bogdan808
Copy link

Bogdan808 commented Nov 29, 2017

I have error 👎
` Installing “modular-snippets@0.1.3” failed.Hide output…

modular-snippets@0.1.3 preinstall C:\Users\Bogdan\AppData\Local\Temp\apm-install-dir-1171029-3708-129hiuv.3hl9za1yvi\node_modules.staging\modular-snippets-627558c1
mkdir -p "${ATOM_HOME:-$HOME/.atom}"/snippets

���⠪����᪠� �訡�� � ����� 䠩��, ����� ����� ��� ��⪥ ⮬�.
�訡�� �� �६� ��ࠡ�⪨: ${ATOM_HOME:-$HOME/.atom}/snippets.
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\Bogdan\AppData\Local\Temp\apm-install-dir-1171029-3708-129hiuv.3hl9za1yvi\package.json'
npm WARN apm-install-dir-1171029-3708-129hiuv.3hl9za1yvi No description
npm WARN apm-install-dir-1171029-3708-129hiuv.3hl9za1yvi No repository field.
npm WARN apm-install-dir-1171029-3708-129hiuv.3hl9za1yvi No README data
npm WARN apm-install-dir-1171029-3708-129hiuv.3hl9za1yvi No license field.
npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\Users\Bogdan\AppData\Local\atom\app-1.22.1\resources\app\apm\bin\node.exe" "C:\Users\Bogdan\AppData\Local\atom\app-1.22.1\resources\app\apm\node_modules\npm\bin\npm-cli.js" "--globalconfig" "C:\Users\Bogdan\.atom\.apm\.apmrc" "--userconfig" "C:\Users\Bogdan\.atom\.apmrc" "install" "C:\Users\Bogdan\AppData\Local\Temp\d-1171029-3708-pod1ee.qdbcfvfgvi\package.tgz" "--runtime=electron" "--target=1.6.15" "--arch=x64" "--global-style" "--msvs_version=2015"
npm ERR! node v6.9.5
npm ERR! npm v3.10.10
npm ERR! code ELIFECYCLE

npm ERR! modular-snippets@0.1.3 preinstall: 'mkdir -p "${ATOM_HOME:-$HOME/.atom}"/snippets'
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the modular-snippets@0.1.3 preinstall script 'mkdir -p "${ATOM_HOME:-$HOME/.atom}"/snippets'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the modular-snippets package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! mkdir -p "${ATOM_HOME:-$HOME/.atom}"/snippets
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs modular-snippets
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls modular-snippets
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR! C:\Users\Bogdan\AppData\Local\Temp\apm-install-dir-1171029-3708-129hiuv.3hl9za1yvi\npm-debug.log`

@thibmaek
Copy link

thibmaek commented Nov 29, 2017

@Bogdan808 see: danielbayley/atom-modular-snippets#1
But I suspect 'mkdir -p "${ATOM_HOME:-$HOME/.atom}"/snippets' will not be a valid command on Windows.

@wvenialbo
Copy link

I was able to install modular-snippets (and its requirements if not installed) by hand:

  1. Close any open instance of Atom,
  2. Download the package as a zip file from GitHub (https://github.com/danielbayley/atom-modular-snippets/archive/master.zip),
  3. Extract the content somewhere and rename the "atom-modular-snippets-master" folder to just "modular-snippets",
  4. Move the folder to the "packages" directory within your Atom installation,
  5. Reopen Atom and install by hand any not found dependency,
  6. Close and repeat from 4 until no more dependencies are required and your project-level snippets work.

In my case, it asked for two packages: "glob-all" (npm install --save glob-all), and "require-cson" (npm install --save require-cson).

Clear skies!

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

No branches or pull requests