Skip to content

Commit

Permalink
Add languages, fix up verbatim output, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
rdipardo committed Aug 16, 2020
1 parent 30f346c commit f30ac8a
Show file tree
Hide file tree
Showing 20 changed files with 388 additions and 142 deletions.
Binary file removed .github/img/nvim_043_ver_020.gif
Binary file not shown.
Binary file added .github/img/nvim_043_ver_021.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ addons:
apt:
update: true

cache: pip

install:
- pip install -r test/requirements.txt
- git clone https://github.com/junegunn/vader.vim.git
Expand All @@ -27,4 +29,4 @@ script:
- pytest -v
- nvim --startuptime nvim_bench.log -ENsu test/vimrc -c '+Vader! test/vader/*' > /dev/null
- VIM= vim --startuptime vim_bench.log -ENsu test/vimrc -c '+Vader! test/vader/*' > /dev/null
- awk '/.*plugin\/cpywrite\.vim.*$/' nvim_bench.log vim_bench.log
- awk '/.*\/cpywrite\.vim.*$/{print $2 " " $3 " " $5}' *.log | sort
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
### 0.2.1

- add support for these file types:
- Ada
- Assembler
- Coffescript
- Elixir
- Elm
- Erlang
- Kotlin
- Lua
- Objective-C
- Pascal

- recognize `.vimrc` as VimL
- prevent copyright notice for appearing on public domain (i.e. copyright-free) licenses, in both modes
- fix regex that was inserting authorship at random places in full license text
- leave one blank line after header
- improve load time of `autoload/cpywrite.vim`

### 0.2.0

- extract feature tests and core functions to `autoload` directory to [improve startup time][pr2]
Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

Generate copyright headers for any open source license

<img src=".github/img/nvim_043_ver_020.gif" alt="nvim-043-linux-demo" width="800"/>
<img src=".github/img/nvim_043_ver_021.gif" alt="nvim-043-linux-demo" width="800"/>

## Description

Mostly written in CPython, this (neo)vim plugin fetches the license of your choice directly from the [SPDX License List](https://github.com/spdx/license-list-xml). If the XML response contains a standard header, it's inserted at the top of the current buffer with your copyright info.

When no standard header is provided, you can either insert a brief license acknowledgement, or the full license text. (See the `g:cpywrite_verbatim_mode` option [below](#quick-reference).)
When no standard header is provided, you can either insert a brief license acknowledgement, or the full license text. (See the `g:cpywrite_verbatim_mode` option [below](#options).)

This plugin learns your name and email by invoking `git`. If that fails, the copyright line will contain your OS user and host names.

Expand Down Expand Up @@ -41,7 +41,7 @@ This plugin learns your name and email by invoking `git`. If that fails, the cop
| | |
|:--|:--|
|`g:cpywrite_default_license`|The SPDX identifier of the license to be fetched by the `:CPYwrite` command.|
|`g:cpywrite_verbatim_mode`|When set to 1, the full license text will be requested -- only choose this when the license is no longer than 3-4 paragraphs (e.g. Unlicense, MIT, BSD 1- 2- 3-Clause, etc.)|
|`g:cpywrite_verbatim_mode`|When set to a non-zero value, the full license text will be requested -- only choose this when the license is no longer than 3-4 paragraphs (e.g. Unlicense, MIT, BSD 1- 2- 3-Clause, etc.)|


## Requirements
Expand Down Expand Up @@ -120,8 +120,9 @@ call vundle#end()

## TODO

- Provide a batch mode for licensing all tracked files in a working tree
- Expand the list of [supported programming languages][lang-list]
- [ ] Provide a batch mode for licensing all tracked files in a working tree
- [ ] Provide the option to set user-defined authorship details
- [x] Expand the list of [supported programming languages][lang-list]


## Improve this README
Expand All @@ -143,7 +144,7 @@ Distributed under the terms of the MIT license
[licl]: https://www.vim.org/scripts/script.php?script_id=4064
[vim-8-pkg-docs]: https://github.com/vim/vim/blob/03c3bd9fd094c1aede2e8fe3ad8fd25b9f033053/runtime/doc/repeat.txt#L515
[vim-pack-man]: https://shapeshed.com/vim-packages/#how-it-works
[lang-list]: rplugin/pythonx/cpywrite/generator.py#L255
[lang-list]: rplugin/pythonx/cpywrite/generator.py#L273
[travis-badge]: https://travis-ci.com/rdipardo/vim-cpywrite.svg?token=yCqYFpeQtymaztY4Spav&branch=master
[travis-builds]: https://travis-ci.com/rdipardo/vim-cpywrite

Expand Down
7 changes: 0 additions & 7 deletions autoload/cpywrite.vim
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@ if has('python3') || has('python')
if empty(get(s:, 'cpywrite_python_cmd', ''))
let s:cpywrite_python_cmd = (has('python3') ? 'py3' : 'py') . 'file'
endif

if empty(get(g:, 'cpywrite_version', ''))
exe s:cpywrite_python_cmd
\ fnamemodify(
\ globpath(&rtp, 'plugin/cpywrite/version.py', 0, 1)[0],
\ ':p')
endif
endif

func! cpywrite#PrependHeader(...) abort
Expand Down
22 changes: 16 additions & 6 deletions doc/cpywrite.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
*cpywrite.txt* Generate copyright headers for any open source license
Generate copyright headers for any open source license *cpywrite.txt*

Maintainer: Robert Di Pardo <[email protected]>
URL: https://github.com/rdipardo/vim-cpywrite
License: MIT

==============================================================================
CONTENTS *cpywrite-contents*

Introduction ................................... |cpywrite-introduction|
Requirements ................................... |cpywrite-requirements|
Attributes ....................................... |cpywrite-attributes|
Options ............................................. |cpywrite-options|
Commands ........................................... |cpywrite-commands|
Mappings ............................................ |cpywrite-keymaps|

=============================================================================
INTRODUCTION *cpywrite-introduction*

Expand Down Expand Up @@ -37,7 +47,7 @@ REQUIREMENTS *cpywrite-requirements*
ATTRIBUTES *cpywrite-attributes*

*g:cpywrite_version*
`string` (set at runtime by the autoload script)
`string`

The current version number of this plugin.

Expand All @@ -53,9 +63,10 @@ the |:CPYwriteDefaultLicense| or |:CPYwrite| command for suggestions.
*g:cpywrite_verbatim_mode*
`number` (default: 0)

When set to 1, the full license text will be requested, whether or not a
standard header exists. You should only choose this when the license is no
longer than 3-4 paragraphs (e.g. Unlicense, MIT, BSD 1- 2- 3-Clause, etc.)
When set to a non-zero value, the full license text will be requested, whether
or not a standard header exists. You should only choose this when the license
is no longer than 3-4 paragraphs (e.g. Unlicense, MIT, BSD 1- 2- 3-Clause,
etc.)

When set to 0, only standard headers are requested. Licenses with no standard
header will be briefly mentioned below your copyright line.
Expand Down Expand Up @@ -89,7 +100,6 @@ description of the updated state:
0 == "standard header/brief"
1 == "verbatim"
<

*<Plug>(cpywrite)*
Quick action command for fetching the default license assigned to
|g:cpywrite_default_license|.
Expand Down
1 change: 1 addition & 0 deletions doc/tags
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
LH cpywrite.txt /*LH*
cpywrite-attributes cpywrite.txt /*cpywrite-attributes*
cpywrite-commands cpywrite.txt /*cpywrite-commands*
cpywrite-contents cpywrite.txt /*cpywrite-contents*
cpywrite-introduction cpywrite.txt /*cpywrite-introduction*
cpywrite-keymaps cpywrite.txt /*cpywrite-keymaps*
cpywrite-options cpywrite.txt /*cpywrite-options*
Expand Down
2 changes: 2 additions & 0 deletions plugin/cpywrite.vim
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
if get(g:, 'loaded_cpywrite') | finish | endif
let g:loaded_cpywrite = 1

let g:cpywrite_version = '0.2.1'

if empty(get(g:, 'cpywrite_default_license', ''))
let g:cpywrite_default_license = 'GPL-3.0-or-later'
endif
Expand Down
4 changes: 2 additions & 2 deletions plugin/cpywrite/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def _write_header(writer, curr_buffer):
try:
use_text_as_header = bool(int(use_text_as_header, 10))
except ValueError:
print("'g:cpywrite_verbatim_mode' should be set to 1 or 0!",
print("'g:cpywrite_verbatim_mode' should be set to a number!",
file=sys.stderr)
vim.command('let g:cpywrite_verbatim_mode=0')
use_text_as_header = False
Expand All @@ -54,7 +54,7 @@ def _write_header(writer, curr_buffer):
if to_trim > 0:
del curr_buffer[0:to_trim]

curr_buffer[0:0] = header.split('\n')[:-1]
curr_buffer[0:0] = header.split('\n')

except (ValueError, vim.error) as exc:
print(str(exc))
Expand Down
23 changes: 0 additions & 23 deletions plugin/cpywrite/version.py

This file was deleted.

2 changes: 1 addition & 1 deletion rplugin/pythonx/cpywrite/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
~~~~~~~~~
"""

__version__ = '0.2.0'
__version__ = '0.2.1'
__authors__ = ['Robert Di Pardo']
__url__ = 'https://github.com/rdipardo/vim-cpywrite'
__license__ = 'MIT'
Expand Down
Loading

0 comments on commit f30ac8a

Please sign in to comment.