Skip to content

Commit 85004fd

Browse files
committed
vimcat: Support ts=X noet (hard tab stops.)
Use the ncurses tabs program to set the terminal hard tab stop if the user's init file has ts=X noet where X != 8. This will not yet work with modelines and filetype plugins, see: #251 Signed-off-by: Rafael Kitover <rkitover@gmail.com>
1 parent 71f117f commit 85004fd

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

vimcat

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ else
3737
exit 1
3838
fi
3939

40+
tab_stop=8
41+
4042
quit() {
4143
(
4244
kill "$vim_pid" >/dev/null 2>&1
@@ -59,6 +61,9 @@ quit() {
5961

6062
rm -rf "$tmp_dir" 2>/dev/null # rm -rf "" shows error on OpenBSD
6163
) &
64+
65+
[ $tab_stop -ne 8 ] && tabs -8 2>/dev/null
66+
6267
exit "$@"
6368
}
6469

@@ -139,6 +144,34 @@ squeeze_blank_lines() {
139144
}'
140145
}
141146

147+
read_vim_settings() {
148+
i=1
149+
OLDIFS=$IFS
150+
IFS='
151+
'
152+
for var in $(IFS=$OLDIFS; "$vim" -NEnR ${vimcatrc:+-u "$vimcatrc"} ${extra_cmd:+--cmd "$extra_cmd"} ${extra_c:+-c "$extra_c"} -i NONE +'
153+
let g:tab_stop = 8
154+
if ! &et
155+
let g:tab_stop = &ts
156+
endif
157+
call writefile([""] + map([g:tab_stop], "\"VAL:\".v:val"), "/dev/stderr")
158+
quit
159+
' </dev/tty 2>&1 >/dev/null); do
160+
case "$var" in
161+
VAL:*)
162+
case $i in
163+
1)
164+
tab_stop=${var#VAL:}
165+
break
166+
;;
167+
esac
168+
i=$((i + 1))
169+
;;
170+
esac
171+
done
172+
IFS=$OLDIFS
173+
}
174+
142175
# if no args and stdin is on a terminal, pretend we're cat and wait on stdin.
143176
if [ $# -eq 0 -a -t 0 ]; then
144177
exec cat
@@ -282,6 +315,8 @@ if [ -n "$output_file" -a $# -gt 1 ]; then
282315
quit 1
283316
fi
284317

318+
read_vim_settings
319+
285320
chunks_dir=$tmp_dir/chunks
286321
mkdir "$chunks_dir"
287322

@@ -318,6 +353,10 @@ do
318353
dest_file=$out_fifo
319354

320355
(
356+
if [ $tab_stop -ne 8 ]; then
357+
stty tab0 2>/dev/null
358+
tabs -${tab_stop} 2>/dev/null
359+
fi
321360
while :; do
322361
[ ! -z "$scroll_time" ] && sleep ${scroll_time}
323362
cat "$out_fifo" & cat_pid=$!

0 commit comments

Comments
 (0)