annotate runtime/autoload/gzip.vim @ 18176:dfe9db84e326 v8.1.2083

patch 8.1.2083: multi-byte chars do not work properly with "%.*S" in printf() Commit: https://github.com/vim/vim/commit/ce0fac28977af31f1dec411d3535b4de2c3169b3 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Sep 27 13:32:06 2019 +0200 patch 8.1.2083: multi-byte chars do not work properly with "%.*S" in printf() Problem: Multi-byte chars do not work properly with "%.*S" in printf(). Solution: Use mb_ptr2cells(). Daniel Hahler, closes https://github.com/vim/vim/issues/4989)
author Bram Moolenaar <Bram@vim.org>
date Fri, 27 Sep 2019 13:45:04 +0200
parents 876fbdd84e52
children 4027cefc2aab
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
1 " Vim autoload file for editing compressed files.
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
2 " Maintainer: Bram Moolenaar <Bram@vim.org>
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 6336
diff changeset
3 " Last Change: 2016 Sep 28
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
4
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
5 " These functions are used by the gzip plugin.
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
6
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
7 " Function to check that executing "cmd [-f]" works.
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
8 " The result is cached in s:have_"cmd" for speed.
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
9 fun s:check(cmd)
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
10 let name = substitute(a:cmd, '\(\S*\).*', '\1', '')
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
11 if !exists("s:have_" . name)
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
12 let e = executable(name)
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
13 if e < 0
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
14 let r = system(name . " --version")
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
15 let e = (r !~ "not found" && r != "")
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
16 endif
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
17 exe "let s:have_" . name . "=" . e
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
18 endif
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
19 exe "return s:have_" . name
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
20 endfun
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
21
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
22 " Set b:gzip_comp_arg to the gzip argument to be used for compression, based on
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
23 " the flags in the compressed file.
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
24 " The only compression methods that can be detected are max speed (-1) and max
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
25 " compression (-9).
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
26 fun s:set_compression(line)
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
27 " get the Compression Method
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
28 let l:cm = char2nr(a:line[2])
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
29 " if it's 8 (DEFLATE), we can check for the compression level
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
30 if l:cm == 8
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
31 " get the eXtra FLags
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
32 let l:xfl = char2nr(a:line[8])
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
33 " max compression
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
34 if l:xfl == 2
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
35 let b:gzip_comp_arg = "-9"
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
36 " min compression
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
37 elseif l:xfl == 4
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
38 let b:gzip_comp_arg = "-1"
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
39 endif
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
40 endif
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
41 endfun
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
42
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
43
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
44 " After reading compressed file: Uncompress text in buffer with "cmd"
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
45 fun gzip#read(cmd)
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
46 " don't do anything if the cmd is not supported
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
47 if !s:check(a:cmd)
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
48 return
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
49 endif
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
50
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
51 " for gzip check current compression level and set b:gzip_comp_arg.
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
52 silent! unlet b:gzip_comp_arg
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
53 if a:cmd[0] == 'g'
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
54 call s:set_compression(getline(1))
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
55 endif
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
56
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
57 " make 'patchmode' empty, we don't want a copy of the written file
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
58 let pm_save = &pm
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
59 set pm=
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
60 " remove 'a' and 'A' from 'cpo' to avoid the alternate file changes
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
61 let cpo_save = &cpo
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
62 set cpo-=a cpo-=A
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
63 " set 'modifiable'
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
64 let ma_save = &ma
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
65 setlocal ma
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 6336
diff changeset
66 " set 'write'
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 6336
diff changeset
67 let write_save = &write
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 6336
diff changeset
68 set write
1190
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
69 " Reset 'foldenable', otherwise line numbers get adjusted.
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
70 if has("folding")
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
71 let fen_save = &fen
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
72 setlocal nofen
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
73 endif
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
74
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
75 " when filtering the whole buffer, it will become empty
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
76 let empty = line("'[") == 1 && line("']") == line("$")
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
77 let tmp = tempname()
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
78 let tmpe = tmp . "." . expand("<afile>:e")
1592
e06e177de52a updated for version 7.1-305
vimboss
parents: 1190
diff changeset
79 if exists('*fnameescape')
e06e177de52a updated for version 7.1-305
vimboss
parents: 1190
diff changeset
80 let tmp_esc = fnameescape(tmp)
e06e177de52a updated for version 7.1-305
vimboss
parents: 1190
diff changeset
81 let tmpe_esc = fnameescape(tmpe)
e06e177de52a updated for version 7.1-305
vimboss
parents: 1190
diff changeset
82 else
e06e177de52a updated for version 7.1-305
vimboss
parents: 1190
diff changeset
83 let tmp_esc = escape(tmp, ' ')
e06e177de52a updated for version 7.1-305
vimboss
parents: 1190
diff changeset
84 let tmpe_esc = escape(tmpe, ' ')
e06e177de52a updated for version 7.1-305
vimboss
parents: 1190
diff changeset
85 endif
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
86 " write the just read lines to a temp file "'[,']w tmp.gz"
1592
e06e177de52a updated for version 7.1-305
vimboss
parents: 1190
diff changeset
87 execute "silent '[,']w " . tmpe_esc
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
88 " uncompress the temp file: call system("gzip -dn tmp.gz")
985
656853d9c014 updated for version 7.0-111
vimboss
parents: 922
diff changeset
89 call system(a:cmd . " " . s:escape(tmpe))
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
90 if !filereadable(tmp)
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
91 " uncompress didn't work! Keep the compressed file then.
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
92 echoerr "Error: Could not read uncompressed file"
1190
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
93 let ok = 0
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
94 else
1190
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
95 let ok = 1
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
96 " delete the compressed lines; remember the line number
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
97 let l = line("'[") - 1
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
98 if exists(":lockmarks")
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
99 lockmarks '[,']d _
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
100 else
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
101 '[,']d _
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
102 endif
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
103 " read in the uncompressed lines "'[-1r tmp"
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
104 " Use ++edit if the buffer was empty, keep the 'ff' and 'fenc' options.
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
105 setlocal nobin
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
106 if exists(":lockmarks")
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
107 if empty
1592
e06e177de52a updated for version 7.1-305
vimboss
parents: 1190
diff changeset
108 execute "silent lockmarks " . l . "r ++edit " . tmp_esc
1190
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
109 else
1592
e06e177de52a updated for version 7.1-305
vimboss
parents: 1190
diff changeset
110 execute "silent lockmarks " . l . "r " . tmp_esc
1190
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
111 endif
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
112 else
1592
e06e177de52a updated for version 7.1-305
vimboss
parents: 1190
diff changeset
113 execute "silent " . l . "r " . tmp_esc
1190
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
114 endif
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
115
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
116 " if buffer became empty, delete trailing blank line
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 446
diff changeset
117 if empty
1190
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
118 silent $delete _
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
119 1
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 446
diff changeset
120 endif
1190
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
121 " delete the temp file and the used buffers
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
122 call delete(tmp)
1592
e06e177de52a updated for version 7.1-305
vimboss
parents: 1190
diff changeset
123 silent! exe "bwipe " . tmp_esc
e06e177de52a updated for version 7.1-305
vimboss
parents: 1190
diff changeset
124 silent! exe "bwipe " . tmpe_esc
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
125 endif
6336
4abac79c0b7a Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1668
diff changeset
126 " Store the OK flag, so that we can use it when writing.
4abac79c0b7a Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1668
diff changeset
127 let b:uncompressOk = ok
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
128
1190
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
129 " Restore saved option values.
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
130 let &pm = pm_save
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
131 let &cpo = cpo_save
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
132 let &l:ma = ma_save
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 6336
diff changeset
133 let &write = write_save
1190
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
134 if has("folding")
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
135 let &l:fen = fen_save
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
136 endif
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
137
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
138 " When uncompressed the whole buffer, do autocommands
1190
4e90dc161511 updated for version 7.1b
vimboss
parents: 1132
diff changeset
139 if ok && empty
1592
e06e177de52a updated for version 7.1-305
vimboss
parents: 1190
diff changeset
140 if exists('*fnameescape')
e06e177de52a updated for version 7.1-305
vimboss
parents: 1190
diff changeset
141 let fname = fnameescape(expand("%:r"))
e06e177de52a updated for version 7.1-305
vimboss
parents: 1190
diff changeset
142 else
e06e177de52a updated for version 7.1-305
vimboss
parents: 1190
diff changeset
143 let fname = escape(expand("%:r"), " \t\n*?[{`$\\%#'\"|!<")
e06e177de52a updated for version 7.1-305
vimboss
parents: 1190
diff changeset
144 endif
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
145 if &verbose >= 8
1592
e06e177de52a updated for version 7.1-305
vimboss
parents: 1190
diff changeset
146 execute "doau BufReadPost " . fname
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
147 else
1592
e06e177de52a updated for version 7.1-305
vimboss
parents: 1190
diff changeset
148 execute "silent! doau BufReadPost " . fname
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
149 endif
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
150 endif
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
151 endfun
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
152
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
153 " After writing compressed file: Compress written file with "cmd"
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
154 fun gzip#write(cmd)
6336
4abac79c0b7a Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1668
diff changeset
155 if exists('b:uncompressOk') && !b:uncompressOk
4abac79c0b7a Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1668
diff changeset
156 echomsg "Not compressing file because uncompress failed; reset b:uncompressOk to compress anyway"
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
157 " don't do anything if the cmd is not supported
6336
4abac79c0b7a Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1668
diff changeset
158 elseif s:check(a:cmd)
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
159 " Rename the file before compressing it.
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
160 let nm = resolve(expand("<afile>"))
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
161 let nmt = s:tempname(nm)
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
162 if rename(nm, nmt) == 0
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
163 if exists("b:gzip_comp_arg")
1668
0b796e045c42 updated for version 7.2b-000
vimboss
parents: 1592
diff changeset
164 call system(a:cmd . " " . b:gzip_comp_arg . " -- " . s:escape(nmt))
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
165 else
1668
0b796e045c42 updated for version 7.2b-000
vimboss
parents: 1592
diff changeset
166 call system(a:cmd . " -- " . s:escape(nmt))
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
167 endif
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
168 call rename(nmt . "." . expand("<afile>:e"), nm)
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
169 endif
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
170 endif
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
171 endfun
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
172
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
173 " Before appending to compressed file: Uncompress file with "cmd"
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
174 fun gzip#appre(cmd)
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
175 " don't do anything if the cmd is not supported
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
176 if s:check(a:cmd)
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
177 let nm = expand("<afile>")
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
178
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
179 " for gzip check current compression level and set b:gzip_comp_arg.
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
180 silent! unlet b:gzip_comp_arg
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
181 if a:cmd[0] == 'g'
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
182 call s:set_compression(readfile(nm, "b", 1)[0])
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
183 endif
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
184
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
185 " Rename to a weird name to avoid the risk of overwriting another file
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
186 let nmt = expand("<afile>:p:h") . "/X~=@l9q5"
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
187 let nmte = nmt . "." . expand("<afile>:e")
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
188 if rename(nm, nmte) == 0
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
189 if &patchmode != "" && getfsize(nm . &patchmode) == -1
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
190 " Create patchmode file by creating the decompressed file new
1668
0b796e045c42 updated for version 7.2b-000
vimboss
parents: 1592
diff changeset
191 call system(a:cmd . " -c -- " . s:escape(nmte) . " > " . s:escape(nmt))
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
192 call rename(nmte, nm . &patchmode)
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
193 else
1668
0b796e045c42 updated for version 7.2b-000
vimboss
parents: 1592
diff changeset
194 call system(a:cmd . " -- " . s:escape(nmte))
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
195 endif
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
196 call rename(nmt, nm)
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
197 endif
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
198 endif
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
199 endfun
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
200
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
201 " find a file name for the file to be compressed. Use "name" without an
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
202 " extension if possible. Otherwise use a weird name to avoid overwriting an
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
203 " existing file.
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
204 fun s:tempname(name)
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
205 let fn = fnamemodify(a:name, ":r")
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
206 if !filereadable(fn) && !isdirectory(fn)
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
207 return fn
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
208 endif
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
209 return fnamemodify(a:name, ":p:h") . "/X~=@l9q5"
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
210 endfun
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
211
985
656853d9c014 updated for version 7.0-111
vimboss
parents: 922
diff changeset
212 fun s:escape(name)
656853d9c014 updated for version 7.0-111
vimboss
parents: 922
diff changeset
213 " shellescape() was added by patch 7.0.111
1132
857a5e3e1d34 updated for version 7.1a
vimboss
parents: 985
diff changeset
214 if exists("*shellescape")
985
656853d9c014 updated for version 7.0-111
vimboss
parents: 922
diff changeset
215 return shellescape(a:name)
656853d9c014 updated for version 7.0-111
vimboss
parents: 922
diff changeset
216 endif
656853d9c014 updated for version 7.0-111
vimboss
parents: 922
diff changeset
217 return "'" . a:name . "'"
656853d9c014 updated for version 7.0-111
vimboss
parents: 922
diff changeset
218 endfun
656853d9c014 updated for version 7.0-111
vimboss
parents: 922
diff changeset
219
446
7472c565592a updated for version 7.0117
vimboss
parents:
diff changeset
220 " vim: set sw=2 :