Skip to content

Commit 18149ab

Browse files
committed
better line following
1 parent f76385c commit 18149ab

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
# vim-decadence
1+
# ![Decadence](icon.png) vim-decadence
22

33
Write music in vim using [decadence](https://github.com/flipcoder/decadence)
44

55
This is only the plug-in repo. The backend code is in the repo above.
66

7-
![Decadence](https://imgur.com/N3yNWyJl.png)
7+
![Screenshot](https://i.imgur.com/HmzNhXf.png)
88

99
WORK IN PROGRESS
10+

plugin/dc.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ def set_dc_path(self,p):
1313
def check_paths(self):
1414
if not self.PYTHON or not self.DC_PATH:
1515
print("vim-decadence: in your .vimrc, set the locations:")
16-
print(" let g:decadence_python = '/usr/bin/python2'")
16+
print(" let g:decadence_python = '/usr/bin/python'")
1717
print(" let g:decadence_path = '~/bin/decadence/decadence.py'")
1818
print("In the future, this will be automatic.")
1919
return False
2020
return True
2121

2222
def __init__(self):
2323
self.processes = []
24+
self.process_buf = {}
2425
self.playing = False
2526
self.PYTHON = None
2627
self.DC_PATH = None
@@ -34,6 +35,7 @@ def stop(self):
3435
except:
3536
pass
3637
term += 1
38+
self.process_buf = {}
3739
self.processes = []
3840
return term
3941
def refresh(self):
@@ -45,7 +47,7 @@ def play(self):
4547
vim.command('call dc#starttimer()')
4648
vim.command('set cursorline')
4749
print('Playing')
48-
self.processes.append(subprocess.Popen([\
50+
p = subprocess.Popen([\
4951
self.PYTHON,\
5052
self.DC_PATH,\
5153
'--follow',
@@ -54,21 +56,26 @@ def play(self):
5456
],
5557
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
5658
bufsize=1, universal_newlines=True
57-
))
59+
)
60+
self.processes.append(p)
61+
self.process_buf[p] = ''
5862
def playline(self):
5963
if not self.check_paths(): return
6064
self.stop()
61-
self.processes.append(subprocess.Popen([\
65+
p = subprocess.Popen([\
6266
self.PYTHON,\
6367
self.DC_PATH,\
6468
'-l',\
6569
vim.current.line\
66-
], stdout=self.DEVNULL, stderr=self.DEVNULL))
70+
], stdout=self.DEVNULL, stderr=self.DEVNULL)
71+
self.processes.append(p)
72+
self.process_buf[p] = ''
6773
def poll(self):
6874
running = 0
6975
done = False
7076
active = 0
7177
for p in self.processes:
78+
# phash = hash(p)
7279
working = False
7380
if p.poll()==None:
7481
active += 1
@@ -83,15 +90,21 @@ def poll(self):
8390
buf = p.stdout.read(1)
8491
if not buf:
8592
break
93+
pbuf = self.process_buf[p]
8694
if buf=='\n':
87-
vim.command('normal! '+str(buf.count('\n'))+'j')
95+
# vim.command('normal! '+str(buf.count('\n'))+'j')
96+
vim.command('exe ' + str(int(pbuf)+1))
97+
self.process_buf[p] = ''
98+
else:
99+
self.process_buf[p] += buf
88100
working = True
89101
if working:
90102
running += 1
91103
if not active:
92104
print('Stopped')
93105
vim.command('call dc#stoptimer()')
94106
vim.command('set cursorline&')
107+
return running
95108
def reload(self):
96109
for i in xrange(2): # first 2 lines check for header
97110
try:

plugin/dc.vim

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ execute 'pyfile '. escape(expand('<sfile>:p:h'),'\') . '/dc.py'
77
function! dc#play()
88
py VimDecadence.play()
99
endfunc
10+
function! dc#stop()
11+
py VimDecadence.play()
12+
endfunc
1013
function! dc#playline()
1114
py VimDecadence.playline()
1215
endfunc
@@ -20,7 +23,7 @@ function! dc#starttimer()
2023
if exists('s:dctimer')
2124
call timer_stop(s:dctimer)
2225
endif
23-
let s:dctimer = timer_start(100, 'dc#poll', {'repeat':-1})
26+
let s:dctimer = timer_start(10, 'dc#poll', {'repeat':-1})
2427
endfunc
2528
function! dc#stoptimer()
2629
call timer_stop(s:dctimer)
@@ -38,7 +41,9 @@ command! -nargs=0 DecadenceStopTimer call dc#stoptimer()
3841
au! BufRead,BufWritePost *.dc DecadenceReload
3942

4043
if !exists("g:decadence_no_mappings") || !g:decadence_no_mappings
41-
"nmap <silent> <buffer> <cr> :DecadencePlay<cr>
44+
"nmap <silent><buffer> <cr><cr> :DecadencePlay<cr>
45+
"nmap <silent><buffer> <cr><esc> :DecadenceStop<cr>
46+
"nmap <silent><buffer> <cr><space> :DecadencePlayLine<cr>
4247
endif
4348

4449
if exists("g:decadence_path")

0 commit comments

Comments
 (0)