Skip to content

Commit b2bd3cf

Browse files
committed
feat: Add smartsign feature with shift symbol mapping
1 parent d475127 commit b2bd3cf

File tree

3 files changed

+50
-11
lines changed

3 files changed

+50
-11
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ set -g @easymotion-perf 'false'
4040

4141
# Case sensitive search (default: false)
4242
set -g @easymotion-case-sensitive 'false'
43+
44+
# Enable smartsign feature (default: false)
45+
set -g @easymotion-smartsign 'false'
4346
```
4447

4548

easymotion.py

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,32 @@
1515
# Configuration from environment
1616
HINTS = os.environ.get('TMUX_EASYMOTION_HINTS', 'asdfghjkl;')
1717
CASE_SENSITIVE = os.environ.get('TMUX_EASYMOTION_CASE_SENSITIVE', 'false').lower() == 'true'
18+
SMARTSIGN = os.environ.get('TMUX_EASYMOTION_SMARTSIGN', 'false').lower() == 'true'
19+
20+
# Smartsign mapping table
21+
SMARTSIGN_TABLE = {
22+
',': '<',
23+
'.': '>',
24+
'/': '?',
25+
'1': '!',
26+
'2': '@',
27+
'3': '#',
28+
'4': '$',
29+
'5': '%',
30+
'6': '^',
31+
'7': '&',
32+
'8': '*',
33+
'9': '(',
34+
'0': ')',
35+
'-': '_',
36+
'=': '+',
37+
';': ':',
38+
'[': '{',
39+
']': '}',
40+
'`': '~',
41+
"'": '"',
42+
'\\': '|'
43+
}
1844
VERTICAL_BORDER = os.environ.get('TMUX_EASYMOTION_VERTICAL_BORDER', '│')
1945
HORIZONTAL_BORDER = os.environ.get('TMUX_EASYMOTION_HORIZONTAL_BORDER', '─')
2046
USE_CURSES = os.environ.get(
@@ -487,23 +513,31 @@ def draw_all_panes(panes, max_x, padding_cache, terminal_height, screen):
487513
def find_matches(panes, search_ch):
488514
"""Find all matches and return match list"""
489515
matches = []
516+
517+
# If smartsign is enabled, add corresponding symbol
518+
search_chars = [search_ch]
519+
if SMARTSIGN and search_ch in SMARTSIGN_TABLE:
520+
search_chars.append(SMARTSIGN_TABLE[search_ch])
521+
490522
for pane in panes:
491523
for line_num, line in enumerate(pane.lines):
492-
# Search each position in the line
493524
pos = 0
494525
while pos < len(line):
495-
if CASE_SENSITIVE:
496-
idx = line.find(search_ch, pos)
497-
else:
498-
idx = line.lower().find(search_ch.lower(), pos)
499-
if idx == -1:
526+
found = False
527+
for ch in search_chars:
528+
if CASE_SENSITIVE:
529+
idx = line.find(ch, pos)
530+
else:
531+
idx = line.lower().find(ch.lower(), pos)
532+
if idx != -1:
533+
visual_col = sum(get_char_width(c) for c in line[:idx])
534+
matches.append((pane, line_num, visual_col))
535+
found = True
536+
pos = idx + 1
537+
break
538+
if not found:
500539
break
501540

502-
# Calculate visual column position
503-
visual_col = sum(get_char_width(c) for c in line[:idx])
504-
matches.append((pane, line_num, visual_col))
505-
pos = idx + 1
506-
507541
return matches
508542

509543

easymotion.tmux

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ USE_CURSES=$(get_tmux_option "@easymotion-use-curses" "false")
2121
DEBUG=$(get_tmux_option "@easymotion-debug" "false")
2222
PERF=$(get_tmux_option "@easymotion-perf" "false")
2323
CASE_SENSITIVE=$(get_tmux_option "@easymotion-case-sensitive" "false")
24+
SMARTSIGN=$(get_tmux_option "@easymotion-smartsign" "false")
2425

2526
# Execute Python script with environment variables
2627
tmux bind $(get_tmux_option "@easymotion-key" "s") run-shell "TMUX_EASYMOTION_HINTS='$HINTS' \
@@ -30,4 +31,5 @@ tmux bind $(get_tmux_option "@easymotion-key" "s") run-shell "TMUX_EASYMOTION_HI
3031
TMUX_EASYMOTION_DEBUG='$DEBUG' \
3132
TMUX_EASYMOTION_PERF='$PERF' \
3233
TMUX_EASYMOTION_CASE_SENSITIVE='$CASE_SENSITIVE' \
34+
TMUX_EASYMOTION_SMARTSIGN='$SMARTSIGN' \
3335
$CURRENT_DIR/easymotion.py"

0 commit comments

Comments
 (0)