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

Addsearchprog #46

Open
wants to merge 2 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
4 changes: 2 additions & 2 deletions pythonx/netranger/Vim.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,11 @@ def debug(*msg):
def WarningMsg(msg):
vim.command(
'unsilent echohl WarningMsg | unsilent echo "{}" | echohl None '.
format(msg.replace('"', '\\"')))
format(msg.replace('"', '\\"').replace('\\','\\\\')))


def Echo(msg):
vim.command(f'unsilent echo "{msg}"')
vim.command('unsilent echo "%s"' % (msg.replace("\\","\\\\"),))
Copy link
Owner

Choose a reason for hiding this comment

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

Please use fstring to be consistent with other part of the codebase.



def UserInput(hint, default=''):
Expand Down
29 changes: 27 additions & 2 deletions pythonx/netranger/netranger.py
Original file line number Diff line number Diff line change
Expand Up @@ -2031,8 +2031,10 @@ def _NETRSearchUpdate(self):

ignore_case = False
if pattern and pattern:
if (Vim.options['smartcase'] and re.match(
'[A-Z]', pattern)) or not Vim.options['ignorecase']:
if (Vim.options['smartcase'] and
re.match("(?=.*[a-z])(?=.*[A-Z])",pattern)) and not Vim.options['ignorecase']:
# if (Vim.options['smartcase'] and re.match(
# '[A-Z]', pattern)) or not Vim.options['ignorecase']:
pattern = re.compile('.*' + pattern)
else:
pattern = re.compile('.*' + pattern, re.IGNORECASE)
Expand Down Expand Up @@ -2076,6 +2078,26 @@ def _NETRSearchStop(self, accept):
# clear command line
Vim.command('echo')

def _NETRSearchGTNext(self,forward):
if forward:
accept_line_nr = [n.name for n in self._cur_search_buf.nodes
].index(Vim.current.line) + 1

self._NETRSearchStop(True)
if forward:
nod=self.cur_buf.nodes[accept_line_nr-1]
self.cur_buf._redraw()
self.cur_buf.set_clineno_by_node(nod)
# self.cur_buf.update_nodes_and_redraw(force_redraw=True)
if nod.is_DIR:
self.NETRBufOpen()
self.NETRSearch()
else:
self.NETRParentDir()
Copy link
Owner

Choose a reason for hiding this comment

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

I feel like this is a very niche need. Why would you want to go to parent directory when you search? Search and goto the search target sounds like a plausible need, but search and goto parent sounds like two unrelated things.

self.NETRSearch()

Vim.command('echo')

def _NETRSearchMove(self, binding):
if binding[0] == '<':
binding = f'\{binding}>'
Expand All @@ -2084,13 +2106,16 @@ def _NETRSearchMove(self, binding):
def _NETRSearchMap(self):
stop_template = 'cnoremap <buffer> {} <cmd>python3 ranger._NETRSearchStop({})<cr><cr>'
move_template = 'cnoremap <buffer><nowait> {} <cmd>python3 ranger._NETRSearchMove("{}")<cr>'
gt_template = 'cnoremap <buffer><nowait> {} <cmd>python3 ranger._NETRSearchGTNext({})<cr>'
Vim.command(stop_template.format('<cr>', True))
Vim.command(stop_template.format('<esc>', False))
Vim.command(stop_template.format('<c-c>', False))
Vim.command(move_template.format('<c-j>', '<down'))
Vim.command(move_template.format('<c-k>', '<up'))
Vim.command(move_template.format('<down>', '<down'))
Vim.command(move_template.format('<up>', '<up'))
Vim.command(gt_template.format('<c-/>',True))
Vim.command(gt_template.format('<M-/>',False))

def NETRSearch(self):
self._cur_search_buf = self.cur_buf
Expand Down