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

Major fixes, among them windows file handling #44

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pythonx/netranger/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,11 @@ def on_stderr(job_id, err_msg):
pickle.dump(arguments, f)

if sudo:
Vim.AsyncRun('sudo {} {} {}'.format(self.ServerCmd, cmd, fname),
Vim.AsyncRun('sudo {} {} {}'.format(self.ServerCmd, cmd, fname).replace('\\','\\\\'),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to put the replace in Vim.AsyncRun

on_exit=on_exit,
term=True)
else:
Vim.AsyncRun('{} {} {}'.format(self.ServerCmd, cmd, fname),
Vim.AsyncRun('{} {} {}'.format(self.ServerCmd, cmd, fname).replace('\\','\\\\'),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

on_stderr=on_stderr,
on_exit=on_exit)

Expand All @@ -197,6 +197,7 @@ def mv(self, src_arr, dst, sudo=False, on_exit=None):

@classmethod
def cp(self, src_arr, dst, sudo=False, on_exit=None):
print("uuu",src_arr,dst)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove.

self.exec_server_cmd('cp',
on_exit, {
'src': src_arr,
Expand Down
39 changes: 33 additions & 6 deletions pythonx/netranger/netranger.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,8 @@ def abbrev_cwd(self, width):
if len(res) <= width:
return res.ljust(width)

res=res.replace('\\','/') #windows

sp = res.split('/')
szm1 = len(sp) - 1
total = 2 * (szm1) + len(sp[-1])
Expand All @@ -418,6 +420,7 @@ def abbrev_cwd(self, width):
return '/'.join(sp).ljust(width)
else:
total += len(sp[i]) - 1
return res[-1 * width:]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose we never reach this point. Did you encounter any issue or did you see lsp warning? If it's the later, maybe it's ok to just return res?


def redraw_header_content(self):
self._header_node.name = self.abbrev_cwd(self.winwidth).strip()
Expand Down Expand Up @@ -856,16 +859,16 @@ def _close_last_previewee(self):
return

if is_DIR:
Vim.command(f'{win_nr}hide')
Vim.command(f'silent! {win_nr}hide')
else:
if Vim.eval(f'getbufvar({bufnr}, "&buftype")') == 'terminal':
Vim.command(f'bwipeout! {bufnr}')
Vim.command(f'silent! bwipeout! {bufnr}')
elif Vim.eval(f'getbufvar({bufnr}, "&modified")') == '1':
Vim.command(f'{win_nr}hide')
Vim.command(f'silent! {win_nr}hide')
elif len(Vim.eval(f'win_findbuf({bufnr})')) > 1:
Vim.command(f'{win_nr}hide')
Vim.command(f'silent! {win_nr}hide')
else:
Vim.command(f'bwipeout! {bufnr}')
Vim.command(f'silent! bwipeout! {bufnr}')

def preview_on(self):
""" Turn preview panel on. """
Expand Down Expand Up @@ -1091,9 +1094,33 @@ class Netranger(object):
1. BufEnter: on_bufenter. create/update NetRangerBuf.
2. CursorMoved: on_cursormoved. update node highlighting and some othe stuff.
"""
def generate_and_ret_buf(self):
bufname = Vim.current.buffer.name
if len(bufname) > 0 and bufname[-1] == '~':
bufname = os.path.expanduser('~')
if not os.path.isdir(bufname):
return
if os.path.islink(bufname):
bufname = os.path.join(os.path.dirname(bufname),
os.readlink(bufname))
bufname = os.path.abspath(bufname)

# if self.buf_existed(bufname):
# self._bufs[Vim.current.buffer.number] = self._wd2bufnum[bufname]
# else:
self.gen_new_buf(bufname)

return self._bufs[Vim.current.buffer.number]




@property
def cur_buf(self):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you elaborate what issues you encountered. We already have a a gen_new_buf function called by on_bufenter, which should guarantee that all call to cur_buf to be valid.

return self._bufs[Vim.current.buffer.number]
if Vim.current.buffer.number in self._bufs:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you encounter a key not found error here?

return self._bufs[Vim.current.buffer.number]
else:
return self.generate_and_ret_buf()

@property
def cur_node(self):
Expand Down
6 changes: 5 additions & 1 deletion pythonx/netranger/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

def GenNetRangerScriptCmd(script):
python = sys.executable
path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
if os.name == 'nt':
path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
f'..\\{script}.py')
else:
path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
f'../{script}.py')
return f'{python} {path}'