Skip to content

Commit c27b13c

Browse files
committed
+lint
1 parent ca7a1e8 commit c27b13c

File tree

8 files changed

+147
-155
lines changed

8 files changed

+147
-155
lines changed

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Note: VIM users should use alternate marks [[[ and ]]] as the original ones can confuse nested substitutions, e.g.: ${${${VAR}}}
2+
# # Space or Tabs? https://stackoverflow.com/questions/35649847/objective-reasons-for-using-spaces-instead-of-tabs-for-indentation
3+
4+
root = true
5+
6+
[*]
7+
indent_style = space
8+
indent_size = 2
9+
charset = utf-8
10+
end_of_line = lf
11+
trim_trailing_whitespace = true
12+
insert_final_newline = true
13+
14+
[**.{md,rst}]
15+
trim_trailing_whitespace = false
File renamed without changes.

zew-backward-kill-shell-word

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
#
44
# MIT License
55
# -----------
6-
#
6+
#
77
# Permission is hereby granted, free of charge, to any person obtaining a copy
88
# of this software and associated documentation files (the "Software"), to deal
99
# in the Software without restriction, including without limitation the rights
1010
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1111
# copies of the Software, and to permit persons to whom the Software is
1212
# furnished to do so, subject to the following conditions:
13-
#
13+
#
1414
# The above copyright notice and this permission notice shall be included in
1515
# all copies or substantial portions of the Software.
16-
#
16+
#
1717
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1818
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1919
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -23,7 +23,7 @@
2323
# THE SOFTWARE.
2424
#
2525
# Modifications Copyright (c) 2016 Sebastian Gniazdowski
26-
#
26+
# Modifications Copyright (c) 2021 Salvydas Luksosius
2727

2828
local MATCH; integer MBEGIN MEND
2929
integer start end_of_word end_of_cut=$CURSOR

zew-history-complete-word

Lines changed: 64 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ zmodload zsh/terminfo 2>/dev/null
66
zmodload zsh/termcap 2>/dev/null
77

88
# Prepare output variables for zew-process-buffer
9-
local ZEW_PB_WORDS ZEW_PB_WORDS_BEGINNINGS ZEW_PB_SPACES
9+
local ZEW_PB_WORDS ZEW_PB_WORDS_BEGINNINGS ZEW_PB_SPACES
1010
local ZEW_PB_SELECTED_WORD ZEW_PB_LEFT ZEW_PB_RIGHT
1111

1212
typeset -g __zew_hcw_index __zew_hcw_left __zew_hcw_right
@@ -22,34 +22,33 @@ zew-process-buffer "$BUFFER" "$CURSOR"
2222

2323
# First call or restart?
2424
if [[ "$__zew_hcw_call_count" -le 1 || "$__zew_hcw_restart" = "1" ]]; then
25-
# '0' will get changed into $to_display limit
26-
[[ "$WIDGET" != *-backwards ]] && __zew_hcw_index="1" || __zew_hcw_index="0"
27-
__zew_hcw_widget_name="${WIDGET%-backwards}"
28-
__zew_hcw_left="$ZEW_PB_LEFT"
29-
__zew_hcw_right="$ZEW_PB_RIGHT"
30-
__zew_hcw_found=( )
31-
__zew_hcw_finished="0"
32-
__zew_hcw_restart="0"
25+
# '0' will get changed into $to_display limit
26+
[[ "$WIDGET" != *-backwards ]] && __zew_hcw_index="1" || __zew_hcw_index="0"
27+
__zew_hcw_widget_name="${WIDGET%-backwards}"
28+
__zew_hcw_left="$ZEW_PB_LEFT"
29+
__zew_hcw_right="$ZEW_PB_RIGHT"
30+
__zew_hcw_found=( )
31+
__zew_hcw_finished="0"
32+
__zew_hcw_restart="0"
3333
else
34-
# Consecutive call
35-
[[ "$WIDGET" != *-backwards ]] && (( __zew_hcw_index ++ )) || (( __zew_hcw_index -- ))
34+
# Consecutive call
35+
[[ "$WIDGET" != *-backwards ]] && (( __zew_hcw_index ++ )) || (( __zew_hcw_index -- ))
3636
fi
3737

3838
# Find history words matching $left ... $right
3939
if [ "$#__zew_hcw_found" -eq "0" ]; then
4040
repeat 1; do
41-
__zew_hcw_found=( "${(@M)historywords:#(#i)$__zew_hcw_left*$__zew_hcw_right}" )
41+
__zew_hcw_found=( "${(@M)historywords:#(#i)$__zew_hcw_left*$__zew_hcw_right}" )
4242
done
43-
44-
# The first result should be always $__zew_hcw_left$__zew_hcw_right
45-
if [ "$__zew_hcw_found[1]" != "$__zew_hcw_left$__zew_hcw_right" ]; then
46-
__zew_hcw_found=( "$__zew_hcw_left$__zew_hcw_right" "$__zew_hcw_found[@]" )
47-
fi
43+
# The first result should be always $__zew_hcw_left$__zew_hcw_right
44+
if [ "$__zew_hcw_found[1]" != "$__zew_hcw_left$__zew_hcw_right" ]; then
45+
__zew_hcw_found=( "$__zew_hcw_left$__zew_hcw_right" "$__zew_hcw_found[@]" )
46+
fi
4847
fi
4948

5049
if [ "$#__zew_hcw_found" -le "0" ]; then
51-
zle -M "No matches found"
52-
return 0
50+
zle -M "No matches found"
51+
return 0
5352
fi
5453

5554
# Pagination, index value guards
@@ -81,15 +80,15 @@ zle -M -- \
8180
local buf=""
8281
integer nwords="${#ZEW_PB_WORDS}"
8382
for (( i=1; i<=nwords; i++ )); do
84-
if [ "$i" = "$ZEW_PB_SELECTED_WORD" ]; then
85-
buf+="${ZEW_PB_SPACES[i]}${__zew_hcw_found[__zew_hcw_index]}"
86-
else
87-
buf+="${ZEW_PB_SPACES[i]}${ZEW_PB_WORDS[i]}"
88-
fi
83+
if [ "$i" = "$ZEW_PB_SELECTED_WORD" ]; then
84+
buf+="${ZEW_PB_SPACES[i]}${__zew_hcw_found[__zew_hcw_index]}"
85+
else
86+
buf+="${ZEW_PB_SPACES[i]}${ZEW_PB_WORDS[i]}"
87+
fi
8988
done
9089

9190
if [[ "$nwords" = "0" && "$ZEW_PB_SELECTED_WORD" = "0" ]]; then
92-
buf+="${__zew_hcw_found[__zew_hcw_index]}"
91+
buf+="${__zew_hcw_found[__zew_hcw_index]}"
9392
fi
9493

9594
# Add trailing spaces
@@ -101,66 +100,56 @@ BUFFER="$buf"
101100
}
102101

103102
_zhcw_self_insert() {
104-
LBUFFER+="${KEYS[-1]}"
105-
__zew_hcw_restart="1"
106-
_zhcw_main
103+
LBUFFER+="${KEYS[-1]}"
104+
__zew_hcw_restart="1"
105+
_zhcw_main
107106
}
108107

109108
_zhcw_backward_delete_char() {
110-
LBUFFER="${LBUFFER%?}"
111-
__zew_hcw_restart="1"
112-
_zhcw_main
109+
LBUFFER="${LBUFFER%?}"
110+
__zew_hcw_restart="1"
111+
_zhcw_main
113112
}
114113

115114
_zhcw_delete_char() {
116-
RBUFFER="${RBUFFER#?}"
117-
__zew_hcw_restart="1"
118-
_zhcw_main
115+
RBUFFER="${RBUFFER#?}"
116+
__zew_hcw_restart="1"
117+
_zhcw_main
119118
}
120119

121120
_zhcw_main
122121

123122
if [ "$__zew_hcw_call_count" -eq "1" ]; then
124123
# Make the zhcw keymap a copy of the current main
125-
bindkey -N zhcw emacs
126-
127-
local down_widget="${WIDGET%-backwards}"
128-
local up_widget="${down_widget}-backwards"
129-
130-
# Manual, termcap, terminfo
131-
bindkey -M zhcw '^[OA' "$up_widget"
132-
bindkey -M zhcw '^[OB' "$down_widget"
133-
bindkey -M zhcw '^[[A' "$up_widget"
134-
bindkey -M zhcw '^[[B' "$down_widget"
135-
[ -n "$termcap[ku]" ] && bindkey -M zhcw "$termcap[ku]" "$up_widget"
136-
[ -n "$termcap[kd]" ] && bindkey -M zhcw "$termcap[kd]" "$down_widget"
137-
[ -n "$termcap[kD]" ] && bindkey -M zhcw "$termcap[kD]" delete-char
138-
[ -n "$terminfo[kcuu1]" ] && bindkey -M zhcw "$terminfo[kcuu1]" "$up_widget"
139-
[ -n "$terminfo[kcud1]" ] && bindkey -M zhcw "$terminfo[kcud1]" "$down_widget"
140-
[ -n "$terminfo[kdch1]" ] && bindkey -M zhcw "$terminfo[kdch1]" delete-char
141-
142-
# Needed for Fedora 23, zsh-5.1.1
143-
bindkey -M zhcw ' ' self-insert
144-
145-
# Substitute self-insert, backward-delete-char, delete-char
146-
zle -A self-insert saved-self-insert
147-
zle -A backward-delete-char saved-backward-delete-char
148-
zle -A delete-char saved-delete-char
149-
150-
zle -N self-insert _zhcw_self_insert
151-
zle -N backward-delete-char _zhcw_backward_delete_char
152-
zle -N delete-char _zhcw_delete_char
153-
154-
zle recursive-edit -K zhcw
155-
zle -M ""
156-
157-
zle -A saved-self-insert self-insert
158-
zle -A saved-backward-delete-char backward-delete-char
159-
zle -A saved-delete-char delete-char
160-
zle -D saved-self-insert saved-backward-delete-char saved-delete-char
161-
162-
# Full reinitialisation at next call
163-
__zew_hcw_call_count="0"
124+
bindkey -N zhcw emacs
125+
local down_widget="${WIDGET%-backwards}"
126+
local up_widget="${down_widget}-backwards"
127+
# Manual, termcap, terminfo
128+
bindkey -M zhcw '^[OA' "$up_widget"
129+
bindkey -M zhcw '^[OB' "$down_widget"
130+
bindkey -M zhcw '^[[A' "$up_widget"
131+
bindkey -M zhcw '^[[B' "$down_widget"
132+
[ -n "$termcap[ku]" ] && bindkey -M zhcw "$termcap[ku]" "$up_widget"
133+
[ -n "$termcap[kd]" ] && bindkey -M zhcw "$termcap[kd]" "$down_widget"
134+
[ -n "$termcap[kD]" ] && bindkey -M zhcw "$termcap[kD]" delete-char
135+
[ -n "$terminfo[kcuu1]" ] && bindkey -M zhcw "$terminfo[kcuu1]" "$up_widget"
136+
[ -n "$terminfo[kcud1]" ] && bindkey -M zhcw "$terminfo[kcud1]" "$down_widget"
137+
[ -n "$terminfo[kdch1]" ] && bindkey -M zhcw "$terminfo[kdch1]" delete-char
138+
# Needed for Fedora 23, zsh-5.1.1
139+
bindkey -M zhcw ' ' self-insert
140+
# Substitute self-insert, backward-delete-char, delete-char
141+
zle -A self-insert saved-self-insert
142+
zle -A backward-delete-char saved-backward-delete-char
143+
zle -A delete-char saved-delete-char
144+
zle -N self-insert _zhcw_self_insert
145+
zle -N backward-delete-char _zhcw_backward_delete_char
146+
zle -N delete-char _zhcw_delete_char
147+
zle recursive-edit -K zhcw
148+
zle -M ""
149+
zle -A saved-self-insert self-insert
150+
zle -A saved-backward-delete-char backward-delete-char
151+
zle -A saved-delete-char delete-char
152+
zle -D saved-self-insert saved-backward-delete-char saved-delete-char
153+
# Full reinitialisation at next call
154+
__zew_hcw_call_count="0"
164155
fi
165-
166-
# vim:ft=zsh

zew-process-buffer

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ ZEW_PB_SELECTED_WORD="-1"
2626

2727
# (Z+n+) will return 1 element for buf that is empty or only whitespace
2828
if [[ "$buf" = ( |$'\t')# ]]; then
29-
ZEW_PB_WORDS=( )
30-
integer nwords=0
29+
ZEW_PB_WORDS=( )
30+
integer nwords=0
3131
else
32-
integer nwords="${#ZEW_PB_WORDS}"
32+
integer nwords="${#ZEW_PB_WORDS}"
3333
fi
3434

3535
# Remove ZEW_PB_WORDS one by one, counting characters,
@@ -43,44 +43,44 @@ integer char_count=0
4343
# (Z) handles spaces nicely, but we need them for the user
4444
# Also compute words beginnings and the selected word
4545
for (( i=1; i<=nwords; i++ )); do
46-
# Remove spurious space generated by Z-flag when
47-
# input is an unbound '$(' (happens with zsh < 5.1)
48-
# and also real spaces gathered by an unbound '$(',
49-
# to handle them in a way normal to this loop
50-
ZEW_PB_WORDS[i]="${ZEW_PB_WORDS[i]%% ##}"
51-
word="${ZEW_PB_WORDS[i]}"
52-
53-
# In general, $buf can start with white spaces
54-
# We will not search for them, but instead for
55-
# leading character of current shell word,
56-
# negated. This is an ambition to completely
57-
# avoid character classes
58-
59-
# Remove white spaces
60-
buf="${buf##(#m)[^$word[1]]#}"
61-
# Count them
62-
char_count=char_count+"$#MATCH"
63-
# This is the beginning of current word
64-
ZEW_PB_WORDS_BEGINNINGS[i]=$(( char_count + 1 ))
65-
# Remember the spaces
66-
ZEW_PB_SPACES[i]="$MATCH"
67-
68-
# Remove the word
69-
MATCH=""
70-
buf="${buf#(#m)$word}"
71-
72-
# If shell word not found, return. This shoudln't happen
73-
[ -z "$MATCH" ] && return 0
74-
75-
# Spaces point to previous shell word
76-
# Visual cursor right after spaces (-ge) -> not enough to select previous word (-gt required)
77-
[[ "$ZEW_PB_SELECTED_WORD" -eq "-1" && "$char_count" -gt "$cursor" ]] && ZEW_PB_SELECTED_WORD=$(( i-1 ))
78-
79-
# Actual characters point to current shell word
80-
# Visual cursor right after letters (-ge) -> enough to select current word
81-
char_count=char_count+"$#word"
82-
[[ "$ZEW_PB_SELECTED_WORD" -eq "-1" && "$char_count" -ge "$cursor" ]] && ZEW_PB_SELECTED_WORD="$i"
83-
done
46+
# Remove spurious space generated by Z-flag when
47+
# input is an unbound '$(' (happens with zsh < 5.1)
48+
# and also real spaces gathered by an unbound '$(',
49+
# to handle them in a way normal to this loop
50+
ZEW_PB_WORDS[i]="${ZEW_PB_WORDS[i]%% ##}"
51+
word="${ZEW_PB_WORDS[i]}"
52+
53+
# In general, $buf can start with white spaces
54+
# We will not search for them, but instead for
55+
# leading character of current shell word,
56+
# negated. This is an ambition to completely
57+
# avoid character classes
58+
59+
# Remove white spaces
60+
buf="${buf##(#m)[^$word[1]]#}"
61+
# Count them
62+
char_count=char_count+"$#MATCH"
63+
# This is the beginning of current word
64+
ZEW_PB_WORDS_BEGINNINGS[i]=$(( char_count + 1 ))
65+
# Remember the spaces
66+
ZEW_PB_SPACES[i]="$MATCH"
67+
68+
# Remove the word
69+
MATCH=""
70+
buf="${buf#(#m)$word}"
71+
72+
# If shell word not found, return. This shoudln't happen
73+
[ -z "$MATCH" ] && return 0
74+
75+
# Spaces point to previous shell word
76+
# Visual cursor right after spaces (-ge) -> not enough to select previous word (-gt required)
77+
[[ "$ZEW_PB_SELECTED_WORD" -eq "-1" && "$char_count" -gt "$cursor" ]] && ZEW_PB_SELECTED_WORD=$(( i-1 ))
78+
79+
# Actual characters point to current shell word
80+
# Visual cursor right after letters (-ge) -> enough to select current word
81+
char_count=char_count+"$#word"
82+
[[ "$ZEW_PB_SELECTED_WORD" -eq "-1" && "$char_count" -ge "$cursor" ]] && ZEW_PB_SELECTED_WORD="$i"
83+
done
8484

8585
# What's left in $buf can be only white spaces
8686
char_count=char_count+"$#buf"
@@ -94,5 +94,3 @@ integer diff=$(( cursor - ZEW_PB_WORDS_BEGINNINGS[ZEW_PB_SELECTED_WORD] + 1 ))
9494
word="${ZEW_PB_WORDS[ZEW_PB_SELECTED_WORD]}"
9595
ZEW_PB_LEFT="${word[1,diff]}"
9696
ZEW_PB_RIGHT="${word[diff+1,-1]}"
97-
98-
# vim:ft=zsh

zew-rotate-shell-words

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
# Transpose shell-words, i.e. parts of lines obtained by (Z) flag, i.e.
2-
# as if zsh parsed the line.
1+
# Transpose shell-words, i.e. parts of lines obtained by (Z) flag, i.e. as if zsh parsed the line.
32
#
4-
# Code to activate the functionality with binding to Alt-t:
5-
# autoload zew-rotate-shell-words
3+
# Code to activate the functionality with binding to Alt-t: autoload zew-rotate-shell-words
64
# zle -N zew-rotate-shell-words
75
# zle -N zew-rotate-shell-words-backwards zew-rotate-shell-words
86
# bindkey '^[r' zew-rotate-shell-words
@@ -24,10 +22,10 @@ zew-process-buffer "$BUFFER"
2422
[ "$ZEW_PB_SELECTED_WORD" -le 1 ] && return 0
2523

2624
# Rotate
27-
if [[ "$WIDGET" != *-backwards ]]; then
28-
ZEW_PB_WORDS=( "${ZEW_PB_WORDS[-1]}" "${(@)ZEW_PB_WORDS[1,-2]}" )
25+
if [[ "$WIDGET" != *-backwards ]]; then
26+
ZEW_PB_WORDS=( "${ZEW_PB_WORDS[-1]}" "${(@)ZEW_PB_WORDS[1,-2]}" )
2927
else
30-
ZEW_PB_WORDS=( "${(@)ZEW_PB_WORDS[2,-1]}" "${ZEW_PB_WORDS[1]}" )
28+
ZEW_PB_WORDS=( "${(@)ZEW_PB_WORDS[2,-1]}" "${ZEW_PB_WORDS[1]}" )
3129
fi
3230

3331
# Build BUFFER
@@ -36,8 +34,8 @@ integer newcursor
3634
buf=""
3735

3836
for (( i=1; i<=size; i++ )); do
39-
buf+="$ZEW_PB_SPACES[i]$ZEW_PB_WORDS[i]"
40-
[ "$i" = "$ZEW_PB_SELECTED_WORD" ] && newcursor="$#buf"
37+
buf+="$ZEW_PB_SPACES[i]$ZEW_PB_WORDS[i]"
38+
[ "$i" = "$ZEW_PB_SELECTED_WORD" ] && newcursor="$#buf"
4139
done
4240

4341
# Append final white spaces
@@ -47,5 +45,3 @@ BUFFER="$buf"
4745
CURSOR="$newcursor"
4846

4947
return 0
50-
51-
# vim:ft=zsh

0 commit comments

Comments
 (0)