Skip to content

Commit 55508cf

Browse files
committed
Initial commit
0 parents  commit 55508cf

File tree

9 files changed

+357
-0
lines changed

9 files changed

+357
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
tags
2+
doc/tags
3+
Gemfile.lock

CODE_OF_CONDUCT.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to making participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, gender identity and expression, level of experience,
9+
nationality, personal appearance, race, religion, or sexual identity and
10+
orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
* Using welcoming and inclusive language
18+
* Being respectful of differing viewpoints and experiences
19+
* Gracefully accepting constructive criticism
20+
* Focusing on what is best for the community
21+
* Showing empathy towards other community members
22+
23+
Examples of unacceptable behavior by participants include:
24+
25+
* The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
* Trolling, insulting/derogatory comments, and personal or political attacks
28+
* Public or private harassment
29+
* Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
* Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
33+
34+
## Our Responsibilities
35+
36+
Project maintainers are responsible for clarifying the standards of acceptable
37+
behavior and are expected to take appropriate and fair corrective action in
38+
response to any instances of unacceptable behavior.
39+
40+
Project maintainers have the right and responsibility to remove, edit, or
41+
reject comments, commits, code, wiki edits, issues, and other contributions
42+
that are not aligned to this Code of Conduct, or to ban temporarily or
43+
permanently any contributor for other behaviors that they deem inappropriate,
44+
threatening, offensive, or harmful.
45+
46+
## Scope
47+
48+
This Code of Conduct applies both within project spaces and in public spaces
49+
when an individual is representing the project or its community. Examples of
50+
representing a project or community include using an official project e-mail
51+
address, posting via an official social media account, or acting as an appointed
52+
representative at an online or offline event. Representation of a project may be
53+
further defined and clarified by project maintainers.
54+
55+
## Enforcement
56+
57+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58+
reported by contacting the project team at [email protected]. All
59+
complaints will be reviewed and investigated and will result in a response that
60+
is deemed necessary and appropriate to the circumstances. The project team is
61+
obligated to maintain confidentiality with regard to the reporter of an incident.
62+
Further details of specific enforcement policies may be posted separately.
63+
64+
Project maintainers who do not follow or enforce the Code of Conduct in good
65+
faith may face temporary or permanent repercussions as determined by other
66+
members of the project's leadership.
67+
68+
## Attribution
69+
70+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71+
available at [http://contributor-covenant.org/version/1/4][version]
72+
73+
[homepage]: http://contributor-covenant.org
74+
[version]: http://contributor-covenant.org/version/1/4/

CONTRIBUTING.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Contributing
2+
3+
If you'd like to contribute to the project, you can use the usual github pull-request flow:
4+
5+
1. Fork the project
6+
2. Make your change/addition, preferably in a separate branch.
7+
3. Test the new behaviour and make sure all existing tests pass (optional, see below for more information).
8+
4. Issue a pull request with a description of your feature/bugfix.
9+
10+
## Testing
11+
12+
This project uses [rspec](http://rspec.info/) and [vimrunner](https://github.com/AndrewRadev/vimrunner) to test its behaviour. Testing vimscript this way does a great job of catching regressions, since it launches a real Vim instance and drives it (almost) as if it's a real user. Tests are written in the ruby programming language, so if you're familiar with it, you should (I hope) find the tests fairly understandable and easy to get into.
13+
14+
If you're not familiar with ruby, it's okay to skip them. I'd definitely appreciate it if you could take a look at the tests and attempt to write something that describes your change. Even if you don't, TravisCI should run the tests on every pull request, so we'll know right away if there's a regression. In that case, I'll work on the tests myself and see what I can do.
15+
16+
To run the test suite, provided you have ruby installed, first you need bundler:
17+
18+
```
19+
$ gem install bundler
20+
```
21+
22+
If you already have the `bundle` command (check it out with `which bundle`), you don't need this step. Afterwards, it should be as simple as:
23+
24+
```
25+
$ bundle install
26+
$ bundle exec rspec spec
27+
```
28+
29+
Depending on what kind of Vim you have installed, this may spawn a GUI Vim instance, or even several. You can read up on [vimrunner's README](https://github.com/AndrewRadev/vimrunner/blob/main/README.md) to understand how that works.

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2023 Andrew Radev
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
This is a temporary name until I come up with something catchier. Demo gif:
2+
3+
![Demo](http://i.andrewradev.com/6dd1230bcac46b4468000b231407b117.gif)
4+
5+
## Usage
6+
7+
TODO more info
8+
9+
Open a description of the timestamp (in quotes) under the cursor with:
10+
11+
```
12+
:StrftimePopup
13+
```
14+
15+
Set `completefunc` to `strftime#Complete` and press `<c-x><c-u>` to show a completion popup for e.g. `%hour` with all %-format keys that
16+
17+
## Contributing
18+
19+
Pull requests are welcome, but take a look at [CONTRIBUTING.md](https://github.com/AndrewRadev/strftime.vim/blob/main/CONTRIBUTING.md) first for some guidelines. Be sure to abide by the [CODE_OF_CONDUCT.md](https://github.com/AndrewRadev/strftime.vim/blob/master/CODE_OF_CONDUCT.md) as well.

_project.vim

Whitespace-only changes.

autoload/strftime.vim

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
" Taken from https://strftime.org/
2+
let s:strftime_codes = {
3+
\ '%a': "Weekday as locale's abbreviated name.",
4+
\ '%A': "Weekday as locale's full name.",
5+
\ '%w': "Weekday as a decimal number, where 0 is Sunday and 6 is Saturday.",
6+
\ '%d': "Day of the month as a zero-padded decimal number.",
7+
\ '%-d': "Day of the month as a decimal number. (Platform specific)",
8+
\ '%b': "Month as locale's abbreviated name.",
9+
\ '%B': "Month as locale's full name.",
10+
\ '%m': "Month as a zero-padded decimal number.",
11+
\ '%-m': "Month as a decimal number. (Platform specific)",
12+
\ '%y': "Year without century as a zero-padded decimal number.",
13+
\ '%Y': "Year with century as a decimal number.",
14+
\ '%H': "Hour (24-hour clock) as a zero-padded decimal number.",
15+
\ '%-H': "Hour (24-hour clock) as a decimal number. (Platform specific)",
16+
\ '%I': "Hour (12-hour clock) as a zero-padded decimal number.",
17+
\ '%-I': "Hour (12-hour clock) as a decimal number. (Platform specific)",
18+
\ '%p': "Locale's equivalent of either AM or PM.",
19+
\ '%M': "Minute as a zero-padded decimal number.",
20+
\ '%-M': "Minute as a decimal number. (Platform specific)",
21+
\ '%S': "Second as a zero-padded decimal number.",
22+
\ '%-S': "Second as a decimal number. (Platform specific)",
23+
\ '%f': "Microsecond as a decimal number, zero-padded on the left.",
24+
\ '%z': "UTC offset in the form ±HHMM[SS[.ffffff]] (empty string if the object is naive).",
25+
\ '%Z': "Time zone name (empty string if the object is naive).",
26+
\ '%j': "Day of the year as a zero-padded decimal number.",
27+
\ '%-j': "Day of the year as a decimal number. (Platform specific)",
28+
\ '%U': "Week number of the year (Sunday as the first day of the week) as a zero padded decimal number.",
29+
\ '%W': "Week number of the year (Monday as the first day of the week) as a decimal number.",
30+
\ '%c': "Locale's appropriate date and time representation.",
31+
\ '%x': "Locale's appropriate date representation.",
32+
\ '%X': "Locale's appropriate time representation.",
33+
\ '%%': "A literal '%' character.",
34+
\ }
35+
let s:popup_window = -1
36+
37+
function! strftime#Complete(findstart, base)
38+
if a:findstart
39+
" locate the start of the timestamp
40+
let [_, start_col] = searchpos('%\w\+', 'bWn', line('.'))
41+
if start_col <= 1
42+
return -3 " cancel completion
43+
else
44+
return start_col - 1
45+
endif
46+
else
47+
let word = substitute(a:base, '^%', '', '')
48+
let results = []
49+
50+
for [code, description] in items(s:strftime_codes)
51+
if description =~? word
52+
call add(results, { 'word': code, 'menu': description })
53+
endif
54+
endfor
55+
56+
return results
57+
endif
58+
endfunction
59+
60+
function! strftime#Popup()
61+
" find the start of a string on the line
62+
let [_, start_col] = searchpos('[''"]', 'bWcn', line('.'))
63+
if start_col <= 0
64+
return
65+
endif
66+
67+
let line = getline('.')
68+
69+
if line[start_col - 1] == "'"
70+
let string_contents = s:GetMotion("vi'")
71+
elseif line[start_col - 1] == '"'
72+
let string_contents = s:GetMotion('vi"')
73+
else
74+
return
75+
endif
76+
77+
let popup_lines = []
78+
let [special_symbol, _, end_index] = matchstrpos(string_contents, '^%\(%\|-\?\w\)')
79+
80+
while special_symbol != ''
81+
if has_key(s:strftime_codes, special_symbol)
82+
call add(popup_lines, special_symbol .. "\t" .. s:strftime_codes[special_symbol])
83+
else
84+
call add(popup_lines, special_symbol .. "\t" .. "[Unknown]")
85+
endif
86+
87+
let [special_symbol, _, end_index] =
88+
\ matchstrpos(string_contents, '^%\(%\|-\?\w\)', end_index + 1)
89+
endwhile
90+
91+
if len(popup_lines) > 0
92+
if s:popup_window >= 0
93+
call popup_close(s:popup_window)
94+
endif
95+
96+
let popup_lines = extend([strftime(string_contents), ''], popup_lines)
97+
let s:popup_window = popup_atcursor(popup_lines, { 'border': [] })
98+
endif
99+
endfunction
100+
101+
function! s:GetMotion(motion)
102+
let saved_view = winsaveview()
103+
104+
let saved_selection = &selection
105+
let &selection = "inclusive"
106+
let saved_register_text = getreg('z', 1)
107+
let saved_register_type = getregtype('z')
108+
let saved_opening_visual = getpos("'<")
109+
let saved_closing_visual = getpos("'>")
110+
111+
let @z = ''
112+
exec 'silent noautocmd normal! '.a:motion.'"zy'
113+
let text = @z
114+
115+
if text == ''
116+
" nothing got selected, so we might still be in visual mode
117+
exe "normal! \<esc>"
118+
endif
119+
120+
call setreg('z', saved_register_text, saved_register_type)
121+
call setpos("'<", saved_opening_visual)
122+
call setpos("'>", saved_closing_visual)
123+
let &selection = saved_selection
124+
125+
call winrestview(saved_view)
126+
127+
return text
128+
endfunction

doc/strftime.txt

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
*strftime.txt* Make it easier to read and write `strftime` strings
2+
3+
==============================================================================
4+
CONTENTS *strftime* *strftime-contents*
5+
6+
Installation................................: |strftime-installation|
7+
Usage.......................................: |strftime-usage|
8+
Settings....................................: |strftime-settings|
9+
Internals...................................: |strftime-internals|
10+
Issues......................................: |strftime-issues|
11+
12+
13+
==============================================================================
14+
INSTALLATION *strftime-installation*
15+
16+
The easiest way to install the plugin is with a plugin manager:
17+
18+
- vim-plug: https://github.com/junegunn/vim-plug
19+
- Vundle: https://github.com/VundleVim/Vundle.vim
20+
21+
If you use one, just follow the instructions in its documentation.
22+
23+
You can install the plugin yourself using Vim's |packages| functionality by
24+
cloning the project (or adding it as a submodule) under
25+
`~/.vim/pack/<any-name>/start/`. For example:
26+
>
27+
mkdir -p ~/.vim/pack/andrewradev/start
28+
cd ~/.vim/pack/andrewradev/start
29+
git clone https://github.com/andrewradev/strftime.vim.git
30+
31+
# to generate documentation tags:
32+
vim -u NONE -c "helptags strftime.vim/doc" -c q
33+
<
34+
This should automatically load the plugin for you when Vim starts.
35+
Alternatively, you can add it to `~/.vim/pack/<any-name>/opt/` instead and
36+
load it in your .vimrc manually with:
37+
>
38+
packadd strftime
39+
<
40+
If you'd rather not use git, you can download the files from the "releases"
41+
tab and unzip them in the relevant directory:
42+
https://github.com/AndrewRadev/strftime.vim/releases.
43+
44+
45+
==============================================================================
46+
USAGE *strftime-usage*
47+
48+
TODO
49+
50+
51+
==============================================================================
52+
SETTINGS *strftime-settings*
53+
54+
TODO
55+
56+
57+
==============================================================================
58+
INTERNALS *strftime-internals*
59+
60+
TODO
61+
62+
==============================================================================
63+
ISSUES *strftime-issues*
64+
65+
Any issues and suggestions are very welcome on the github bugtracker:
66+
https://github.com/AndrewRadev/strftime.vim/issues
67+
68+
69+
vim:tw=78:sw=4:ft=help:norl:

plugin/strftime.vim

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
if exists('g:loaded_strftime') || &cp
2+
finish
3+
endif
4+
5+
let g:loaded_strftime = '0.0.1' " version number
6+
let s:keepcpo = &cpo
7+
set cpo&vim
8+
9+
command! StrftimePopup call strftime#Popup()
10+
11+
" set completefunc=strftime#Complete
12+
13+
let &cpo = s:keepcpo
14+
unlet s:keepcpo

0 commit comments

Comments
 (0)