├── .gitignore ├── CONTRIBUTING ├── LICENSE ├── README.md ├── autoload └── cue.vim ├── cue-screenshot.png ├── doc └── vim-cue.txt ├── ftdetect └── cue.vim ├── ftplugin └── cue.vim ├── indent ├── VIM_LICENSE └── cue.vim ├── plugin └── cue.vim ├── syntax └── cue.vim └── syntax_checkers └── cue └── cue.vim /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | .*.swp 3 | -------------------------------------------------------------------------------- /CONTRIBUTING: -------------------------------------------------------------------------------- 1 | This is a community derived work from https://github.com/google/jsonnet, 2 | CLA of the original project FYI: 3 | 4 | Before we can merge your pull request, we need you to sign either the Google individual or corporate 5 | contributor license agreement (CLA), unless you are a Google employee, intern, or contractor. 6 | 7 | Please see http://google.github.io/jsonnet/doc/contributing.html for more information. 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vim-cue 2 | 3 | This plugin is heavily derived from https://github.com/google/vim-jsonnet, 4 | very much WIP as of Aug/2019. 5 | 6 | [Cue][cue] filetype plugin for Vim. 7 | 8 | [cue]: https://github.com/cuelang 9 | 10 | ![A screenshot of Cue syntax highlighting](https://raw.githubusercontent.com/jjo/vim-cue/master/cue-screenshot.png) 11 | 12 | # Install 13 | 14 | To install via Vim plugin managers: 15 | 16 | ### Vundle 17 | 18 | ```viml 19 | Plugin 'jjo/vim-cue' 20 | ``` 21 | 22 | ### vim-plug 23 | 24 | ```viml 25 | Plug 'jjo/vim-cue' 26 | ``` 27 | 28 | ### Pathogen 29 | 30 | ```sh 31 | git clone https://github.com/jjo/vim-cue ~/.vim/bundle/vim-cue 32 | ``` 33 | 34 | ## More Info 35 | 36 | For more info on Cue: 37 | * Cue Website: https://cuelang.org 38 | * Cue Repository: https://github.com/cuelang/cue 39 | -------------------------------------------------------------------------------- /autoload/cue.vim: -------------------------------------------------------------------------------- 1 | " Options. 2 | 3 | if !exists("g:cue_command") 4 | let g:cue_command = "cue" 5 | endif 6 | 7 | if !exists("g:cue_fmt_command") 8 | let g:cue_fmt_command = "fmt" 9 | endif 10 | 11 | if !exists('g:cue_fmt_options') 12 | let g:cue_fmt_options = '' 13 | endif 14 | 15 | 16 | " Format calls `cue fmt ... ` on the file and replaces the file with the auto 17 | " formatted version. 18 | function! cue#Format() abort 19 | " Save the view. 20 | let curw = winsaveview() 21 | 22 | " Make a fake change so that the undo point is right. 23 | normal! ix 24 | normal! "_x 25 | 26 | " Execute `terraform fmt`, redirecting stderr to a temporary file. 27 | let tmpfile = tempname() 28 | let shellredir_save = &shellredir 29 | let &shellredir = '>%s 2>'.tmpfile 30 | silent execute '%!' . g:cue_command . " " . g:cue_fmt_command . " " . g:cue_fmt_options . " -" 31 | let &shellredir = shellredir_save 32 | 33 | " If there was an error, undo any changes and show stderr. 34 | if v:shell_error != 0 35 | silent undo 36 | let output = readfile(tmpfile) 37 | echo join(output, "\n") 38 | endif 39 | 40 | " Delete the temporary file, and restore the view. 41 | call delete(tmpfile) 42 | call winrestview(curw) 43 | endfunction 44 | -------------------------------------------------------------------------------- /cue-screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jjo/vim-cue/bd1a62303d096aa24fe4160a475645087f8770b3/cue-screenshot.png -------------------------------------------------------------------------------- /doc/vim-cue.txt: -------------------------------------------------------------------------------- 1 | *vim-cue.txt* Cue development plugin 2 | *vim-cue* 3 | 4 | CONTENTS *cue-contents* 5 | 6 | 1. Intro........................................|cue-intro| 7 | 2. Install......................................|cue-install| 8 | 3. Commands.....................................|cue-commands| 9 | 4. Mappings.....................................|cue-mappings| 10 | 6. Functions....................................|cue-functions| 11 | 7. Settings.....................................|cue-settings| 12 | 8. Troubleshooting..............................|cue-troubleshooting| 13 | 9. Credits......................................|cue-credits| 14 | 15 | ============================================================================== 16 | INTRO *cue-intro* 17 | 18 | ============================================================================== 19 | INSTALL *cue-install* 20 | 21 | ============================================================================== 22 | COMMANDS *cue-commands* 23 | 24 | *:CueFmt* 25 | :CueFmt 26 | 27 | Filter the current Cue buffer through `cue fmt`. It tries to 28 | preserve cursor position and avoids replacing the buffer with stderr 29 | output. 30 | 31 | ============================================================================== 32 | MAPPINGS *cue-mappings* 33 | 34 | ============================================================================== 35 | FUNCTIONS *cue-functions* 36 | 37 | *cue#Format()* 38 | 39 | Filter the current Cue buffer through `cue fmt`. It tries to 40 | preserve cursor position and avoids replacing the buffer with stderr 41 | output. 42 | 43 | ============================================================================== 44 | SETTINGS *cue-settings* 45 | 46 | *'g:cue_fmt_on_save'* 47 | 48 | Use this option to auto |:CueFmt| on save. By default it's enabled > 49 | 50 | let g:cue_fmt_on_save = 1 51 | < 52 | *'g:cue_command'* 53 | 54 | Use this option to define which tool is used to fotmat. By default `cue` is 55 | used > 56 | 57 | let g:cue_command = "cue" 58 | < 59 | *'g:cue_fmt_command'* 60 | 61 | Use this option to define which parameter is used with *g:cue_command* tool. 62 | By default `fmt` is used > 63 | 64 | let g:cue_fmt_command = "fmt" 65 | < 66 | *'g:cue_fmt_options'* 67 | 68 | Use this option to add additional options to the 69 | |'g:cue_command'| + |'g:cue_fmt_command'|. Default is empty. > 70 | 71 | let g:cue_fmt_options = '' 72 | < 73 | *'g:cue_fmt_fail_silently'* 74 | 75 | Use this option to enable processing of 76 | |'g:cue_command'| + |'g:cue_fmt_command'| command if it fails. By default 77 | it is turned off. By default the error output from the 78 | |'g:cue_command'| + |'g:cue_fmt_command'| command is ignored. 79 | FixMe: The processing of the |'g:cue_command'| + |'g:cue_fmt_command'| 80 | is not implemented yet. So clearing this option would not do anything at this time. > 81 | 82 | let g:cue_fmt_fail_silently = 1 83 | < 84 | 85 | ============================================================================== 86 | TROUBLESHOOTING *cue-troubleshooting* 87 | 88 | ============================================================================== 89 | CREDITS *cue-credits* 90 | 91 | 92 | -------------------------------------------------------------------------------- /ftdetect/cue.vim: -------------------------------------------------------------------------------- 1 | " Copyright 2014 Google Inc. All rights reserved. 2 | " 3 | " Licensed under the Apache License, Version 2.0 (the "License"); 4 | " you may not use this file except in compliance with the License. 5 | " You may obtain a copy of the License at 6 | " 7 | " http://www.apache.org/licenses/LICENSE-2.0 8 | " 9 | " Unless required by applicable law or agreed to in writing, software 10 | " distributed under the License is distributed on an "AS IS" BASIS, 11 | " WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | " See the License for the specific language governing permissions and 13 | " limitations under the License. 14 | 15 | autocmd BufNewFile,BufRead *.cue setf cue 16 | -------------------------------------------------------------------------------- /ftplugin/cue.vim: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | " -- fmt 5 | command! -nargs=0 CueFmt call cue#Format() 6 | 7 | setlocal commentstring=//\ %s 8 | 9 | 10 | -------------------------------------------------------------------------------- /indent/VIM_LICENSE: -------------------------------------------------------------------------------- 1 | VIM LICENSE 2 | 3 | I) There are no restrictions on distributing unmodified copies of Vim except 4 | that they must include this license text. You can also distribute 5 | unmodified parts of Vim, likewise unrestricted except that they must 6 | include this license text. You are also allowed to include executables 7 | that you made from the unmodified Vim sources, plus your own usage 8 | examples and Vim scripts. 9 | 10 | II) It is allowed to distribute a modified (or extended) version of Vim, 11 | including executables and/or source code, when the following four 12 | conditions are met: 13 | 1) This license text must be included unmodified. 14 | 2) The modified Vim must be distributed in one of the following five ways: 15 | a) If you make changes to Vim yourself, you must clearly describe in 16 | the distribution how to contact you. When the maintainer asks you 17 | (in any way) for a copy of the modified Vim you distributed, you 18 | must make your changes, including source code, available to the 19 | maintainer without fee. The maintainer reserves the right to 20 | include your changes in the official version of Vim. What the 21 | maintainer will do with your changes and under what license they 22 | will be distributed is negotiable. If there has been no negotiation 23 | then this license, or a later version, also applies to your changes. 24 | The current maintainer is Bram Moolenaar . If this 25 | changes it will be announced in appropriate places (most likely 26 | vim.sf.net, www.vim.org and/or comp.editors). When it is completely 27 | impossible to contact the maintainer, the obligation to send him 28 | your changes ceases. Once the maintainer has confirmed that he has 29 | received your changes they will not have to be sent again. 30 | b) If you have received a modified Vim that was distributed as 31 | mentioned under a) you are allowed to further distribute it 32 | unmodified, as mentioned at I). If you make additional changes the 33 | text under a) applies to those changes. 34 | c) Provide all the changes, including source code, with every copy of 35 | the modified Vim you distribute. This may be done in the form of a 36 | context diff. You can choose what license to use for new code you 37 | add. The changes and their license must not restrict others from 38 | making their own changes to the official version of Vim. 39 | d) When you have a modified Vim which includes changes as mentioned 40 | under c), you can distribute it without the source code for the 41 | changes if the following three conditions are met: 42 | - The license that applies to the changes permits you to distribute 43 | the changes to the Vim maintainer without fee or restriction, and 44 | permits the Vim maintainer to include the changes in the official 45 | version of Vim without fee or restriction. 46 | - You keep the changes for at least three years after last 47 | distributing the corresponding modified Vim. When the maintainer 48 | or someone who you distributed the modified Vim to asks you (in 49 | any way) for the changes within this period, you must make them 50 | available to him. 51 | - You clearly describe in the distribution how to contact you. This 52 | contact information must remain valid for at least three years 53 | after last distributing the corresponding modified Vim, or as long 54 | as possible. 55 | e) When the GNU General Public License (GPL) applies to the changes, 56 | you can distribute the modified Vim under the GNU GPL version 2 or 57 | any later version. 58 | 3) A message must be added, at least in the output of the ":version" 59 | command and in the intro screen, such that the user of the modified Vim 60 | is able to see that it was modified. When distributing as mentioned 61 | under 2)e) adding the message is only required for as far as this does 62 | not conflict with the license used for the changes. 63 | 4) The contact information as required under 2)a) and 2)d) must not be 64 | removed or changed, except that the person himself can make 65 | corrections. 66 | 67 | III) If you distribute a modified version of Vim, you are encouraged to use 68 | the Vim license for your changes and make them available to the 69 | maintainer, including the source code. The preferred way to do this is 70 | by e-mail or by uploading the files to a server and e-mailing the URL. 71 | If the number of changes is small (e.g., a modified Makefile) e-mailing a 72 | context diff will do. The e-mail address to be used is 73 | 74 | 75 | IV) It is not allowed to remove this license from the distribution of the Vim 76 | sources, parts of it or from a modified version. You may use this 77 | license for previous Vim releases instead of the license that they came 78 | with, at your option. 79 | -------------------------------------------------------------------------------- /indent/cue.vim: -------------------------------------------------------------------------------- 1 | " Vim indent file 2 | " Language: CUE (copy of Vim-distributed JSON indent file) 3 | " 4 | " We include copy a copy of the Vim license in this directory, and leave the 5 | " header of the original JSON indent file intact in the remainder of this 6 | " comment. 7 | " 8 | " Mantainer: Eli Parra https://github.com/elzr/vim-json 9 | " Last Change: 2017 Jun 13 10 | " https://github.com/jakar/vim-json/commit/20b650e22aa750c4ab6a66aa646bdd95d7cd548a#diff-e81fc111b2052e306d126bd9989f7b7c 11 | " Original Author: Rogerz Zhang http://github.com/rogerz/vim-json 12 | " Acknowledgement: Based off of vim-javascript maintained by Darrick Wiebe 13 | " http://www.vim.org/scripts/script.php?script_id=2765 14 | 15 | " 0. Initialization {{{1 16 | " ================= 17 | 18 | " Only load this indent file when no other was loaded. 19 | if exists("b:did_indent") 20 | finish 21 | endif 22 | let b:did_indent = 1 23 | 24 | setlocal nosmartindent 25 | 26 | " Now, set up our indentation expression and keys that trigger it. 27 | setlocal indentexpr=GetJSONIndent() 28 | setlocal indentkeys=0{,0},0),0[,0],!^F,o,O,e 29 | 30 | " Only define the function once. 31 | if exists("*GetJSONIndent") 32 | finish 33 | endif 34 | 35 | let s:cpo_save = &cpo 36 | set cpo&vim 37 | 38 | " 1. Variables {{{1 39 | " ============ 40 | 41 | let s:line_term = '\s*\%(\%(\/\/\).*\)\=$' 42 | " Regex that defines blocks. 43 | let s:block_regex = '\%({\)\s*\%(|\%([*@]\=\h\w*,\=\s*\)\%(,\s*[*@]\=\h\w*\)*|\)\=' . s:line_term 44 | 45 | " 2. Auxiliary Functions {{{1 46 | " ====================== 47 | 48 | " Check if the character at lnum:col is inside a string. 49 | function s:IsInString(lnum, col) 50 | return synIDattr(synID(a:lnum, a:col, 1), 'name') == 'jsonString' 51 | endfunction 52 | 53 | " Find line above 'lnum' that isn't empty, or in a string. 54 | function s:PrevNonBlankNonString(lnum) 55 | let lnum = prevnonblank(a:lnum) 56 | while lnum > 0 57 | " If the line isn't empty or in a string, end search. 58 | let line = getline(lnum) 59 | if !(s:IsInString(lnum, 1) && s:IsInString(lnum, strlen(line))) 60 | break 61 | endif 62 | let lnum = prevnonblank(lnum - 1) 63 | endwhile 64 | return lnum 65 | endfunction 66 | 67 | " Check if line 'lnum' has more opening brackets than closing ones. 68 | function s:LineHasOpeningBrackets(lnum) 69 | let open_0 = 0 70 | let open_2 = 0 71 | let open_4 = 0 72 | let line = getline(a:lnum) 73 | let pos = match(line, '[][(){}]', 0) 74 | while pos != -1 75 | let idx = stridx('(){}[]', line[pos]) 76 | if idx % 2 == 0 77 | let open_{idx} = open_{idx} + 1 78 | else 79 | let open_{idx - 1} = open_{idx - 1} - 1 80 | endif 81 | let pos = match(line, '[][(){}]', pos + 1) 82 | endwhile 83 | return (open_0 > 0) . (open_2 > 0) . (open_4 > 0) 84 | endfunction 85 | 86 | function s:Match(lnum, regex) 87 | let col = match(getline(a:lnum), a:regex) + 1 88 | return col > 0 && !s:IsInString(a:lnum, col) ? col : 0 89 | endfunction 90 | 91 | " 3. GetJSONIndent Function {{{1 92 | " ========================= 93 | 94 | function GetJSONIndent() 95 | " 3.1. Setup {{{2 96 | " ---------- 97 | 98 | " Set up variables for restoring position in file. Could use v:lnum here. 99 | let vcol = col('.') 100 | 101 | " 3.2. Work on the current line {{{2 102 | " ----------------------------- 103 | 104 | " Get the current line. 105 | let line = getline(v:lnum) 106 | let ind = -1 107 | 108 | " If we got a closing bracket on an empty line, find its match and indent 109 | " according to it. 110 | let col = matchend(line, '^\s*[]}]') 111 | 112 | if col > 0 && !s:IsInString(v:lnum, col) 113 | call cursor(v:lnum, col) 114 | let bs = strpart('{}[]', stridx('}]', line[col - 1]) * 2, 2) 115 | 116 | let pairstart = escape(bs[0], '[') 117 | let pairend = escape(bs[1], ']') 118 | let pairline = searchpair(pairstart, '', pairend, 'bW') 119 | 120 | if pairline > 0 121 | let ind = indent(pairline) 122 | else 123 | let ind = virtcol('.') - 1 124 | endif 125 | 126 | return ind 127 | endif 128 | 129 | " If we are in a multi-line string, don't do anything to it. 130 | if s:IsInString(v:lnum, matchend(line, '^\s*') + 1) 131 | return indent('.') 132 | endif 133 | 134 | " 3.3. Work on the previous line. {{{2 135 | " ------------------------------- 136 | 137 | let lnum = prevnonblank(v:lnum - 1) 138 | 139 | if lnum == 0 140 | return 0 141 | endif 142 | 143 | " Set up variables for current line. 144 | let line = getline(lnum) 145 | let ind = indent(lnum) 146 | 147 | " If the previous line ended with a block opening, add a level of indent. 148 | " if s:Match(lnum, s:block_regex) 149 | " return indent(lnum) + shiftwidth() 150 | " endif 151 | 152 | " If the previous line contained an opening bracket, and we are still in it, 153 | " add indent depending on the bracket type. 154 | if line =~ '[[({]' 155 | let counts = s:LineHasOpeningBrackets(lnum) 156 | if counts[0] == '1' || counts[1] == '1' || counts[2] == '1' 157 | return ind + shiftwidth() 158 | else 159 | call cursor(v:lnum, vcol) 160 | end 161 | endif 162 | 163 | " }}}2 164 | 165 | return ind 166 | endfunction 167 | 168 | " }}}1 169 | 170 | let &cpo = s:cpo_save 171 | unlet s:cpo_save 172 | 173 | " vim:set sw=2 sts=2 ts=8 noet: 174 | -------------------------------------------------------------------------------- /plugin/cue.vim: -------------------------------------------------------------------------------- 1 | 2 | 3 | " A plugin for cue files. 4 | " Install useful tools for *.cue files 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | function! s:fmtAutosave() 13 | " Cue code formatting on save 14 | if get(g:, "cue_fmt_on_save", 1) 15 | call cue#Format() 16 | endif 17 | endfunction 18 | 19 | 20 | " auto group and clear inside prevents multiple registration of the same 21 | " auto commands 22 | augroup vim-cue 23 | autocmd! 24 | autocmd BufReadPre *.cue setlocal foldmethod=syntax 25 | autocmd BufReadPre *.cue setlocal foldlevel=100 26 | autocmd BufWritePre *.cue call s:fmtAutosave() 27 | augroup END 28 | 29 | -------------------------------------------------------------------------------- /syntax/cue.vim: -------------------------------------------------------------------------------- 1 | " Copyright 2014 Google Inc. All rights reserved. 2 | " 3 | " Licensed under the Apache License, Version 2.0 (the "License"); 4 | " you may not use this file except in compliance with the License. 5 | " You may obtain a copy of the License at 6 | " 7 | " http://www.apache.org/licenses/LICENSE-2.0 8 | " 9 | " Unless required by applicable law or agreed to in writing, software 10 | " distributed under the License is distributed on an "AS IS" BASIS, 11 | " WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | " See the License for the specific language governing permissions and 13 | " limitations under the License. 14 | 15 | syntax match Number "\<\d*\([Ee][+-]\?\d\+\)\?\>" 16 | syntax match Number "\<\d\+[.]\d*\([Ee][+-]\?\d\+\)\?\>" 17 | syntax match Number "\<[.]\d\+\([Ee][+-]\?\d\+\)\?\>" 18 | 19 | syn match Type "\$" 20 | 21 | syn match Keyword "\<[a-zA-Z_][a-z0-9A-Z_"()\\ ]*\s*?\?::\?" 22 | 23 | syn region Object start="{" end="}" fold transparent 24 | 25 | syntax keyword Include import 26 | syntax keyword Statement for in len if let and or div mod quo rem close 27 | syntax match Statement "+\|-\|/\|\*\|&&\?\|||\|==\|!=\|=\~\|!\~\|!\|<=\?\|>=\?\|:\|=\|<-\|;\|@\|##\?" 28 | syntax keyword Special package command task 29 | syntax keyword Constant true false null 30 | syntax keyword Underlined error 31 | 32 | " NOTE(jjo): block comments removed as of cue 0.11 33 | "syn region Comment start="/[*]" end="[*]/" 34 | syn region Comment start="//" end="$" 35 | syn match Comment "//.*$" 36 | 37 | syn match Type "<[^>]*>\||" 38 | syn match Type "\<\(nulll\|bool\|double\|float\(32\|64\)\?\|s\?u\?int\(8\|16\|32\|64\|128\)\?\|string\|number\|bytes\|\.\.\.\|[*]\)\>" 39 | syn match Keyword "\<_[a-zA-Z0-9_]*" 40 | 41 | " String literals. 42 | syn region String start=+\z(#*\)\z('\|"\)+ skip="\\\z2" end="\z2\z1" 43 | " Multiline string literals. 44 | syn region String start=+\z(#*\)\z('''\|"""\)+ end="\z2\z1" 45 | " Interpolation 46 | " TODO: handle modified escape delimeters. 47 | syn region Special start="\\(" end=")" 48 | syn match Special "\\\(([^)]\+)\)" contained containedin=String 49 | 50 | " builtins 51 | " From https://godoc.org/cuelang.org/go/pkg 52 | syn match Constant "base64.Decode" 53 | syn match Constant "base64.DecodedLen" 54 | syn match Constant "base64.Encode" 55 | syn match Constant "base64.EncodedLen" 56 | syn match Constant "bits.And" 57 | syn match Constant "bits.At" 58 | syn match Constant "bits.Clear" 59 | syn match Constant "bits.Len" 60 | syn match Constant "bits.Lsh" 61 | syn match Constant "bits.OnesCount" 62 | syn match Constant "bits.Or" 63 | syn match Constant "bits.Rsh" 64 | syn match Constant "bits.Set" 65 | syn match Constant "bits.Xor" 66 | syn match Constant "cli.Print" 67 | syn match Constant "csv.Decode" 68 | syn match Constant "csv.Encode" 69 | syn match Constant "exec.Run" 70 | syn match Constant "file.Append" 71 | syn match Constant "file.Create" 72 | syn match Constant "file.Glob" 73 | syn match Constant "file.Read" 74 | syn match Constant "hex.Decode" 75 | syn match Constant "hex.DecodedLen" 76 | syn match Constant "hex.Dump" 77 | syn match Constant "hex.Encode" 78 | syn match Constant "hex.EncodedLen" 79 | syn match Constant "hmac.MD5" 80 | syn match Constant "hmac.SHA1" 81 | syn match Constant "hmac.SHA224" 82 | syn match Constant "hmac.SHA256" 83 | syn match Constant "hmac.SHA384" 84 | syn match Constant "hmac.SHA512" 85 | syn match Constant "hmac.SHA512_224" 86 | syn match Constant "hmac.SHA512_256" 87 | syn match Constant "hmac.Sign" 88 | syn match Constant "html.Escape" 89 | syn match Constant "html.Unescape" 90 | syn match Constant "http.Delete" 91 | syn match Constant "http.Get" 92 | syn match Constant "http.Post" 93 | syn match Constant "http.Put" 94 | syn match Constant "http.Serve" 95 | syn match Constant "json.Compact" 96 | syn match Constant "json.HTMLEscape" 97 | syn match Constant "json.Indent" 98 | syn match Constant "json.Marshal" 99 | syn match Constant "json.MarshalStream" 100 | syn match Constant "json.Unmarshal" 101 | syn match Constant "json.Valid" 102 | syn match Constant "json.Validate" 103 | syn match Constant "list.Avg" 104 | syn match Constant "list.Concat" 105 | syn match Constant "list.Contains" 106 | syn match Constant "list.Drop" 107 | syn match Constant "list.FlattenN" 108 | syn match Constant "list.IsSorted" 109 | syn match Constant "list.IsSortedStrings" 110 | syn match Constant "list.Max" 111 | syn match Constant "list.MaxItems" 112 | syn match Constant "list.Min" 113 | syn match Constant "list.MinItems" 114 | syn match Constant "list.Product" 115 | syn match Constant "list.Range" 116 | syn match Constant "list.Repeat" 117 | syn match Constant "list.Slice" 118 | syn match Constant "list.Sort" 119 | syn match Constant "list.SortStable" 120 | syn match Constant "list.SortStrings" 121 | syn match Constant "list.Sum" 122 | syn match Constant "list.Take" 123 | syn match Constant "list.UniqueItems" 124 | syn match Constant "math.Above" 125 | syn match Constant "math.Abs" 126 | syn match Constant "math.Acos" 127 | syn match Constant "math.Acosh" 128 | syn match Constant "math.Asin" 129 | syn match Constant "math.Asinh" 130 | syn match Constant "math.Atan" 131 | syn match Constant "math.Atan2" 132 | syn match Constant "math.Atanh" 133 | syn match Constant "math.AwayFromZero" 134 | syn match Constant "math.Below" 135 | syn match Constant "math.Cbrt" 136 | syn match Constant "math.Ceil" 137 | syn match Constant "math.Copysign" 138 | syn match Constant "math.Cos" 139 | syn match Constant "math.Cosh" 140 | syn match Constant "math.Dim" 141 | syn match Constant "math.E" 142 | syn match Constant "math.Erf" 143 | syn match Constant "math.Erfc" 144 | syn match Constant "math.Erfcinv" 145 | syn match Constant "math.Erfinv" 146 | syn match Constant "math.Exact" 147 | syn match Constant "math.Exp" 148 | syn match Constant "math.Exp2" 149 | syn match Constant "math.Expm1" 150 | syn match Constant "math.Floor" 151 | syn match Constant "math.Gamma" 152 | syn match Constant "math.Hypot" 153 | syn match Constant "math.Ilogb" 154 | syn match Constant "math.J0" 155 | syn match Constant "math.J1" 156 | syn match Constant "math.Jacobi" 157 | syn match Constant "math.Jn" 158 | syn match Constant "math.Ldexp" 159 | syn match Constant "math.Ln10" 160 | syn match Constant "math.Ln2" 161 | syn match Constant "math.Log" 162 | syn match Constant "math.Log10" 163 | syn match Constant "math.Log10E" 164 | syn match Constant "math.Log1p" 165 | syn match Constant "math.Log2" 166 | syn match Constant "math.Log2E" 167 | syn match Constant "math.Logb" 168 | syn match Constant "math.MaxBase" 169 | syn match Constant "math.MaxExp" 170 | syn match Constant "math.MaxPrec" 171 | syn match Constant "math.MinExp" 172 | syn match Constant "math.Mod" 173 | syn match Constant "math.MultipleOf" 174 | syn match Constant "math.Phi" 175 | syn match Constant "math.Pi" 176 | syn match Constant "math.Pow" 177 | syn match Constant "math.Pow10" 178 | syn match Constant "math.Remainder" 179 | syn match Constant "math.Round" 180 | syn match Constant "math.RoundToEven" 181 | syn match Constant "math.Signbit" 182 | syn match Constant "math.Sin" 183 | syn match Constant "math.Sinh" 184 | syn match Constant "math.Sqrt" 185 | syn match Constant "math.Sqrt2" 186 | syn match Constant "math.SqrtE" 187 | syn match Constant "math.SqrtPhi" 188 | syn match Constant "math.SqrtPi" 189 | syn match Constant "math.Tan" 190 | syn match Constant "math.Tanh" 191 | syn match Constant "math.ToNearestAway" 192 | syn match Constant "math.ToNearestEven" 193 | syn match Constant "math.ToNegativeInf" 194 | syn match Constant "math.ToPositiveInf" 195 | syn match Constant "math.ToZero" 196 | syn match Constant "math.Trunc" 197 | syn match Constant "math.Y0" 198 | syn match Constant "math.Y1" 199 | syn match Constant "math.Yn" 200 | syn match Constant "md5.BlockSize" 201 | syn match Constant "md5.Size" 202 | syn match Constant "md5.Sum" 203 | syn match Constant "net.FQDN" 204 | syn match Constant "net.GlobalUnicastIP" 205 | syn match Constant "net.InterfaceLocalMulticastIP" 206 | syn match Constant "net.IP" 207 | syn match Constant "net.IPString" 208 | syn match Constant "net.IPv4" 209 | syn match Constant "net.IPv4len" 210 | syn match Constant "net.IPv6len" 211 | syn match Constant "net.JoinHostPort" 212 | syn match Constant "net.LinkLocalMulticastIP" 213 | syn match Constant "net.LinkLocalUnicastIP" 214 | syn match Constant "net.LoopbackIP" 215 | syn match Constant "net.MulticastIP" 216 | syn match Constant "net.ParseIP" 217 | syn match Constant "net.SplitHostPort" 218 | syn match Constant "net.ToIP16" 219 | syn match Constant "net.ToIP4" 220 | syn match Constant "net.UnspecifiedIP" 221 | syn match Constant "path.Base" 222 | syn match Constant "path.Clean" 223 | syn match Constant "path.Dir" 224 | syn match Constant "path.Ext" 225 | syn match Constant "path.FromSlash" 226 | syn match Constant "path.IsAbs" 227 | syn match Constant "path.Join" 228 | syn match Constant "path.Match" 229 | syn match Constant "path.Rel" 230 | syn match Constant "path.Resolve" 231 | syn match Constant "path.Split" 232 | syn match Constant "path.SplitList" 233 | syn match Constant "path.ToSlash" 234 | syn match Constant "path.VolumeName" 235 | syn match Constant "regexp.Find" 236 | syn match Constant "regexp.FindAll" 237 | syn match Constant "regexp.FindAllNamedSubmatch" 238 | syn match Constant "regexp.FindAllSubmatch" 239 | syn match Constant "regexp.FindNamedSubmatch" 240 | syn match Constant "regexp.FindSubmatch" 241 | syn match Constant "regexp.Match" 242 | syn match Constant "regexp.QuoteMeta" 243 | syn match Constant "regexp.Valid" 244 | syn match Constant "sha1.BlockSize" 245 | syn match Constant "sha1.Size" 246 | syn match Constant "sha1.Sum" 247 | syn match Constant "sha256.BlockSize" 248 | syn match Constant "sha256.Size" 249 | syn match Constant "sha256.Size224" 250 | syn match Constant "sha256.Sum224" 251 | syn match Constant "sha256.Sum256" 252 | syn match Constant "sha512.BlockSize" 253 | syn match Constant "sha512.Size" 254 | syn match Constant "sha512.Size224" 255 | syn match Constant "sha512.Size256" 256 | syn match Constant "sha512.Size384" 257 | syn match Constant "sha512.Sum384" 258 | syn match Constant "sha512.Sum512" 259 | syn match Constant "sha512.Sum512_224" 260 | syn match Constant "sha512.Sum512_256" 261 | syn match Constant "strconv.Atoi" 262 | syn match Constant "strconv.FormatBool" 263 | syn match Constant "strconv.FormatFloat" 264 | syn match Constant "strconv.FormatInt" 265 | syn match Constant "strconv.FormatUint" 266 | syn match Constant "strconv.IntSize" 267 | syn match Constant "strconv.IsGraphic" 268 | syn match Constant "strconv.IsPrint" 269 | syn match Constant "strconv.ParseBool" 270 | syn match Constant "strconv.ParseFloat" 271 | syn match Constant "strconv.ParseInt" 272 | syn match Constant "strconv.ParseUint" 273 | syn match Constant "strconv.Quote" 274 | syn match Constant "strconv.QuoteRune" 275 | syn match Constant "strconv.QuoteRuneToASCII" 276 | syn match Constant "strconv.QuoteRuneToGraphic" 277 | syn match Constant "strconv.QuoteToASCII" 278 | syn match Constant "strconv.QuoteToGraphic" 279 | syn match Constant "strconv.Unquote" 280 | syn match Constant "strings.ByteAt" 281 | syn match Constant "strings.ByteSlice" 282 | syn match Constant "strings.Compare" 283 | syn match Constant "strings.Contains" 284 | syn match Constant "strings.ContainsAny" 285 | syn match Constant "strings.Count" 286 | syn match Constant "strings.Fields" 287 | syn match Constant "strings.HasPrefix" 288 | syn match Constant "strings.HasSuffix" 289 | syn match Constant "strings.Index" 290 | syn match Constant "strings.IndexAny" 291 | syn match Constant "strings.Join" 292 | syn match Constant "strings.LastIndex" 293 | syn match Constant "strings.LastIndexAny" 294 | syn match Constant "strings.MaxRunes" 295 | syn match Constant "strings.MinRunes" 296 | syn match Constant "strings.Repeat" 297 | syn match Constant "strings.Replace" 298 | syn match Constant "strings.Runes" 299 | syn match Constant "strings.SliceRunes" 300 | syn match Constant "strings.Split" 301 | syn match Constant "strings.SplitAfter" 302 | syn match Constant "strings.SplitAfterN" 303 | syn match Constant "strings.SplitN" 304 | syn match Constant "strings.ToCamel" 305 | syn match Constant "strings.ToLower" 306 | syn match Constant "strings.ToTitle" 307 | syn match Constant "strings.ToUpper" 308 | syn match Constant "strings.Trim" 309 | syn match Constant "strings.TrimLeft" 310 | syn match Constant "strings.TrimPrefix" 311 | syn match Constant "strings.TrimRight" 312 | syn match Constant "strings.TrimSpace" 313 | syn match Constant "strings.TrimSuffix" 314 | syn match Constant "struct.MaxFields" 315 | syn match Constant "struct.MinFields" 316 | syn match Constant "tabwriter.Write" 317 | syn match Constant "template.Execute" 318 | syn match Constant "template.HTMLEscape" 319 | syn match Constant "template.JSEscape" 320 | syn match Constant "time.ANSIC" 321 | syn match Constant "time.April" 322 | syn match Constant "time.August" 323 | syn match Constant "time.December" 324 | syn match Constant "time.Duration" 325 | syn match Constant "time.February" 326 | syn match Constant "time.Format" 327 | syn match Constant "time.Friday" 328 | syn match Constant "time.Hour" 329 | syn match Constant "time.January" 330 | syn match Constant "time.July" 331 | syn match Constant "time.June" 332 | syn match Constant "time.Kitchen" 333 | syn match Constant "time.Kitchen24" 334 | syn match Constant "time.March" 335 | syn match Constant "time.May" 336 | syn match Constant "time.Microsecond" 337 | syn match Constant "time.Millisecond" 338 | syn match Constant "time.Minute" 339 | syn match Constant "time.Monday" 340 | syn match Constant "time.Nanosecond" 341 | syn match Constant "time.November" 342 | syn match Constant "time.October" 343 | syn match Constant "time.Parse" 344 | syn match Constant "time.ParseDuration" 345 | syn match Constant "time.RFC1123" 346 | syn match Constant "time.RFC1123Z" 347 | syn match Constant "time.RFC3339" 348 | syn match Constant "time.RFC3339Date" 349 | syn match Constant "time.RFC3339Nano" 350 | syn match Constant "time.RFC822" 351 | syn match Constant "time.RFC822Z" 352 | syn match Constant "time.RFC850" 353 | syn match Constant "time.RubyDate" 354 | syn match Constant "time.Saturday" 355 | syn match Constant "time.Second" 356 | syn match Constant "time.September" 357 | syn match Constant "time.Sunday" 358 | syn match Constant "time.Thursday" 359 | syn match Constant "time.Time" 360 | syn match Constant "time.Tuesday" 361 | syn match Constant "time.Unix" 362 | syn match Constant "time.UnixDate" 363 | syn match Constant "time.Wednesday" 364 | syn match Constant "uuid.FromInt" 365 | syn match Constant "uuid.MD5" 366 | syn match Constant "uuid.Parse" 367 | syn match Constant "uuid.SHA1" 368 | syn match Constant "uuid.ToInt" 369 | syn match Constant "uuid.ToString" 370 | syn match Constant "uuid.URN" 371 | syn match Constant "uuid.Valid" 372 | syn match Constant "uuid.Variant" 373 | syn match Constant "uuid.Version" 374 | syn match Constant "yaml.Marshal" 375 | syn match Constant "yaml.MarshalStream" 376 | syn match Constant "yaml.Unmarshal" 377 | syn match Constant "yaml.Validate" 378 | syn match Constant "yaml.ValidatePartial" 379 | -------------------------------------------------------------------------------- /syntax_checkers/cue/cue.vim: -------------------------------------------------------------------------------- 1 | " Vim syntastic plugin 2 | " Language: cue 3 | " Author: JuanJo Ciarlante 4 | " 5 | " For details on how to add an external Syntastic checker: 6 | " https://github.com/scrooloose/syntastic/wiki/Syntax-Checker-Guide#external 7 | 8 | if exists("g:loaded_syntastic_cue_cue_checker") 9 | finish 10 | endif 11 | let g:loaded_syntastic_cue_cue_checker = 1 12 | 13 | let s:save_cpo = &cpo 14 | set cpo&vim 15 | 16 | function! SyntaxCheckers_cue_cue_IsAvailable() dict 17 | return executable(self.getExec()) 18 | endfunction 19 | 20 | function! SyntaxCheckers_cue_cue_GetLocList() dict 21 | 22 | let errorformat = 23 | \ 'Error: parse: %m,' . 24 | \ 'expected %m,' . 25 | \ '\ \ \ \ %f:%l:%c,' . 26 | \ '' 27 | 28 | return SyntasticMake({ 29 | \ 'makeprg': self.makeprgBuild({}), 30 | \ 'errorformat': errorformat }) 31 | endfunction 32 | 33 | call g:SyntasticRegistry.CreateAndRegisterChecker({ 34 | \ 'filetype': 'cue', 35 | \ 'name': 'cue'}) 36 | 37 | " Register for syntastic tab completion: 38 | if exists('g:syntastic_extra_filetypes') 39 | call add(g:syntastic_extra_filetypes, 'cue') 40 | else 41 | let g:syntastic_extra_filetypes = ['cue'] 42 | endif 43 | 44 | let &cpo = s:save_cpo 45 | unlet s:save_cpo 46 | --------------------------------------------------------------------------------