Skip to content

Commit 168d0cd

Browse files
committed
Bug fix for last commit :-\
* Use g:xolox#shell#version instead of g:shell_version! * Option handling with xolox#misc#option#get({name}, {default}) * Document xolox#shell#fullscreen(), xolox#shell#is_fullscreen()
1 parent 6cbfe98 commit 168d0cd

File tree

4 files changed

+69
-64
lines changed

4 files changed

+69
-64
lines changed

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ This plug-in aims to improve the integration between [Vim][vim] and its environm
1010

1111
Two [Windows DLL files][dll] are included to perform these functions on Windows, while on UNIX external commands are used.
1212

13-
## Usage
14-
15-
The below paragraphs document the functionality in the `shell.vim` plug-in. I'd be very grateful if people would test the plug-in in different environments and report their results by contacting the [vim-dev](http://vimdoc.sourceforge.net/htmldoc/intro.html#vim-dev) mailing-list or e-mailing me directly at <peter@peterodding.com>. You can test the plug-in by unpacking the [ZIP archive from www.vim.org][download] in the `%USERPROFILE%\vimfiles` directory (on Windows) or the `~/.vim/` directory (on UNIX), restarting Vim and checking whether the commands below work as documented.
13+
## Usage (commands & functions)
1614

1715
### The `:Fullscreen` command
1816

@@ -50,6 +48,14 @@ Vim will be completely unresponsive until you "press any key to continue" in the
5048

5149
Note that on Windows this function uses Vim's ['shell'][sh_opt] and ['shellcmdflag'][shcf_opt] options to compose the command line passed to the DLL.
5250

51+
### The `xolox#shell#fullscreen()` function
52+
53+
Call this function to toggle Vim's full screen status. The `:Fullscreen` command is just a shorter way to call this function.
54+
55+
### The `xolox#shell#is_fullscreen()` function
56+
57+
Call this function to determine whether Vim is in full screen mode. My [session.vim plug-in](http://peterodding.com/code/vim/session) uses this to persist full screen mode.
58+
5359
### The `g:shell_fullscreen_items` option
5460

5561
This variable is a string containing any combination of the following characters:
@@ -58,7 +64,7 @@ This variable is a string containing any combination of the following characters
5864
* `T`: Hide the [toolbar](http://vimdoc.sourceforge.net/htmldoc/options.html#%27go-T%27) when switching to full-screen;
5965
* `e`: Hide the [tabline](http://vimdoc.sourceforge.net/htmldoc/options.html#%27go-e%27) when switching to full-screen (this also toggles the [showtabline option](http://vimdoc.sourceforge.net/htmldoc/options.html#%27showtabline%27)).
6066

61-
By default all the above items are hidden in full-screen mode.
67+
By default all the above items are hidden in full-screen mode. You can also set the buffer local variable `b:shell_fullscreen_items` to change these settings for specific buffers.
6268

6369
### The `g:shell_mappings_enabled` option
6470

autoload/xolox/shell.vim

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
" Last Change: August 31, 2011
44
" URL: http://peterodding.com/code/vim/shell/
55

6-
let g:xolox#shell#version = '0.9.8'
6+
let g:xolox#shell#version = '0.9.9'
77

88
if !exists('s:fullscreen_enabled')
99
let s:enoimpl = "%s() hasn't been implemented on your platform! %s"
@@ -17,7 +17,7 @@ function! xolox#shell#open_cmd(arg) " -- implementation of the :Open command {{{
1717
if !s:open_at_cursor()
1818
call xolox#misc#open#file(expand('%:p:h'))
1919
endif
20-
elseif a:arg =~ g:shell_patt_url || a:arg =~ g:shell_patt_mail
20+
elseif a:arg =~ xolox#shell#url_pattern() || a:arg =~ xolox#shell#mail_pattern()
2121
call xolox#misc#open#url(a:arg)
2222
else
2323
let arg = fnamemodify(a:arg, ':p')
@@ -29,19 +29,19 @@ function! xolox#shell#open_cmd(arg) " -- implementation of the :Open command {{{
2929
endif
3030
endif
3131
catch
32-
call xolox#misc#msg#warn("shell.vim %s: %s at %s", g:shell_version, v:exception, v:throwpoint)
32+
call xolox#misc#msg#warn("shell.vim %s: %s at %s", g:xolox#shell#version, v:exception, v:throwpoint)
3333
endtry
3434
endfunction
3535

3636
function! s:open_at_cursor()
3737
let cWORD = expand('<cWORD>')
3838
" Start by trying to match a URL in <cWORD> because URLs can be more-or-less
3939
" unambiguously distinguished from e-mail addresses and filenames.
40-
let match = matchstr(cWORD, g:shell_patt_url)
40+
let match = matchstr(cWORD, xolox#shell#url_pattern())
4141
if match == ''
4242
" Now try to match an e-mail address in <cWORD> because most filenames
4343
" won't contain an @-sign while e-mail addresses require it.
44-
let match = matchstr(cWORD, g:shell_patt_mail)
44+
let match = matchstr(cWORD, xolox#shell#mail_pattern())
4545
endif
4646
if match != ''
4747
call xolox#misc#open#url(match)
@@ -68,13 +68,14 @@ function! xolox#shell#open_with_windows_shell(location)
6868
let error = s:library_call('openurl', a:location)
6969
if error != ''
7070
let msg = "shell.vim %s: Failed to open '%s' with Windows shell! (error: %s)"
71-
throw printf(msg, g:shell_version, a:location, strtrans(xolox#misc#str#trim(error)))
71+
throw printf(msg, g:xolox#shell#version, a:location, strtrans(xolox#misc#str#trim(error)))
7272
endif
7373
endif
7474
endfunction
7575

7676
function! xolox#shell#highlight_urls() " -- highlight URLs and e-mail addresses embedded in source code comments {{{1
77-
if exists('g:syntax_on') && &ft !~ g:shell_hl_exclude
77+
" URL highlighting breaks highlighting of <a href="..."> tags in HTML.
78+
if exists('g:syntax_on') && &ft !~ xolox#misc#option#get('shell_hl_exclude', '^\(x|ht\)ml$')
7879
if &ft == 'help'
7980
let command = 'syntax match %s /%s/'
8081
let urlgroup = 'HelpURL'
@@ -84,8 +85,8 @@ function! xolox#shell#highlight_urls() " -- highlight URLs and e-mail addresses
8485
let urlgroup = 'CommentURL'
8586
let mailgroup = 'CommentEmail'
8687
endif
87-
execute printf(command, urlgroup, escape(g:shell_patt_url, '/'))
88-
execute printf(command, mailgroup, escape(g:shell_patt_mail, '/'))
88+
execute printf(command, urlgroup, escape(xolox#shell#url_pattern(), '/'))
89+
execute printf(command, mailgroup, escape(xolox#shell#mail_pattern(), '/'))
8990
execute 'highlight def link' urlgroup 'Underlined'
9091
execute 'highlight def link' mailgroup 'Underlined'
9192
endif
@@ -129,7 +130,7 @@ function! xolox#shell#execute(command, synchronous, ...) " -- execute external c
129130
return 1
130131
endif
131132
catch
132-
call xolox#misc#msg#warn("shell.vim %s: %s at %s", g:shell_version, v:exception, v:throwpoint)
133+
call xolox#misc#msg#warn("shell.vim %s: %s at %s", g:xolox#shell#version, v:exception, v:throwpoint)
133134
finally
134135
if exists('tempin') | call delete(tempin) | endif
135136
if exists('tempout') | call delete(tempout) | endif
@@ -149,13 +150,14 @@ function! xolox#shell#fullscreen() " -- toggle Vim between normal and full-scree
149150
" Hide the main menu, tool bar and/or tab line. Remember what was hidden
150151
" so its visibility can be restored when the user leaves full-screen.
151152
let s:go_toggled = ''
152-
for item in split(g:shell_fullscreen_items, '.\zs')
153+
let fullscreen_items = xolox#misc#option#get('shell_fullscreen_items', 'mTe')
154+
for item in split(fullscreen_items, '.\zs')
153155
if &go =~# item
154156
let s:go_toggled .= item
155157
execute 'set go-=' . item
156158
endif
157159
endfor
158-
if g:shell_fullscreen_items =~# 'e' && &stal != 0
160+
if fullscreen_items =~# 'e' && &stal != 0
159161
let s:stal_save = &stal
160162
set showtabline=0
161163
endif
@@ -180,7 +182,7 @@ function! xolox#shell#fullscreen() " -- toggle Vim between normal and full-scree
180182
throw printf(s:enoimpl, 'fullscreen', s:contact)
181183
endif
182184
catch
183-
call xolox#misc#msg#warn("shell.vim %s: %s at %s", g:shell_version, v:exception, v:throwpoint)
185+
call xolox#misc#msg#warn("shell.vim %s: %s at %s", g:xolox#shell#version, v:exception, v:throwpoint)
184186
endtry
185187

186188
" When leaving full-screen...
@@ -209,7 +211,7 @@ function! xolox#shell#fullscreen() " -- toggle Vim between normal and full-scree
209211
" Take a moment to let Vim's GUI finish redrawing (:redraw is
210212
" useless here because it only redraws Vim's internal state).
211213
sleep 50 m
212-
call xolox#misc#msg#info("shell.vim %s: To return from full-screen type <F11> or execute :Fullscreen.", g:shell_version)
214+
call xolox#misc#msg#info("shell.vim %s: To return from full-screen type <F11> or execute :Fullscreen.", g:xolox#shell#version)
213215
endif
214216

215217
endfunction
@@ -218,6 +220,14 @@ function! xolox#shell#is_fullscreen() " -- check whether Vim is currently in ful
218220
return s:fullscreen_enabled
219221
endfunction
220222

223+
function! xolox#shell#url_pattern() " -- get the preferred/default pattern to match URLs {{{1
224+
return xolox#misc#option#get('shell_patt_url', '\<\w\{3,}://\(\S*\w\)\+[/?#]\?')
225+
endfunction
226+
227+
function! xolox#shell#mail_pattern() " -- get the preferred/default pattern to match e-mail addresses {{{1
228+
return xolox#misc#option#get('shell_patt_mail', '\<\w\{3,}://\(\S*\w\)\+[/?#]\?')
229+
endfunction
230+
221231
" Miscellaneous script-local functions. {{{1
222232

223233
if xolox#misc#os#is_win()

doc/shell.txt

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,8 @@ Two Windows DLL files [4] are included to perform these functions on Windows,
2323
while on UNIX external commands are used.
2424

2525
===============================================================================
26-
*shell-usage*
27-
Usage ~
28-
29-
The below paragraphs document the functionality in the 'shell.vim' plug-in.
30-
I'd be very grateful if people would test the plug-in in different
31-
environments and report their results by contacting the |vim-dev| mailing-list
32-
or e-mailing me directly at peter@peterodding.com. You can test the plug-in by
33-
unpacking the ZIP archive from www.vim.org [5] in the '%USERPROFILE%\vimfiles'
34-
directory (on Windows) or the '~/.vim/' directory (on UNIX), restarting Vim
35-
and checking whether the commands below work as documented.
26+
*shell-usage-(commands-functions)*
27+
Usage (commands & functions) ~
3628

3729
-------------------------------------------------------------------------------
3830
The *:Fullscreen* command
@@ -44,7 +36,7 @@ like this.
4436
When you enter full-screen mode the main menu, toolbar and tabline are all
4537
hidden (see |g:shell_fullscreen_items| if you want to change this) and when
4638
possible Vim's |GUI| window is switched to real full-screen mode (hiding any
47-
taskbars, panels or docks [6]). When you leave full-screen Vim's main menu,
39+
taskbars, panels or docks [5]). When you leave full-screen Vim's main menu,
4840
toolbar and tabline are restored and the |GUI| window is switched back to normal
4941
mode.
5042

@@ -110,6 +102,18 @@ command that takes a while to finish and blocks Vim while doing so.
110102
Note that on Windows this function uses Vim's |'shell'| and |'shellcmdflag'|
111103
options to compose the command line passed to the DLL.
112104

105+
-------------------------------------------------------------------------------
106+
The *xolox#shell#fullscreen()* function
107+
108+
Call this function to toggle Vim's full screen status. The |:Fullscreen|
109+
command is just a shorter way to call this function.
110+
111+
-------------------------------------------------------------------------------
112+
The *xolox#shell#is_fullscreen()* function
113+
114+
Call this function to determine whether Vim is in full screen mode. My
115+
session.vim plug-in [6] uses this to persist full screen mode.
116+
113117
-------------------------------------------------------------------------------
114118
The *g:shell_fullscreen_items* option
115119

@@ -123,7 +127,9 @@ characters:
123127
- 'e': Hide the tabline (see |'go-e'|) when switching to full-screen (this also
124128
toggles the showtabline option (see |'showtabline'|)).
125129

126-
By default all the above items are hidden in full-screen mode.
130+
By default all the above items are hidden in full-screen mode. You can also
131+
set the buffer local variable 'b:shell_fullscreen_items' to change these
132+
settings for specific buffers.
127133

128134
-------------------------------------------------------------------------------
129135
The *g:shell_mappings_enabled* option
@@ -166,18 +172,18 @@ Windows and calls out to external programs such as 'wmctrl', 'gnome-open',
166172
Before I go ahead and bundle the DLL files with my easytags.vim [3] plug-in I
167173
need to make sure they're compatible with as many Windows Vim installations
168174
out there as possible, e.g. XP/Vista/7, different service packs, 32/64 bits,
169-
etc. I've uploaded a ZIP archive including two compiled DLL files [5] to the
170-
Vim scripts page [8] for this plug-in (build using the latest Windows SDK but
175+
etc. I've uploaded a ZIP archive including two compiled DLL files [8] to the
176+
Vim scripts page [9] for this plug-in (build using the latest Windows SDK but
171177
targeting Windows XP x86/x64 DEBUG, should also work on Vista/7) and the
172-
source code is available in the GitHub repository [9] (see the 'NMAKE'makefile
173-
[10] for compile instructions).
178+
source code is available in the GitHub repository [10] (see the
179+
'NMAKE'makefile [11] for compile instructions).
174180

175181
===============================================================================
176182
*shell-other-full-screen-implementations*
177183
Other full-screen implementations ~
178184

179-
After publishing this plug-in I found that the Vim plug-ins VimTweak [11] and
180-
gvimfullscreen_win32 [12] also implement full-screen on Windows using a
185+
After publishing this plug-in I found that the Vim plug-ins VimTweak [12] and
186+
gvimfullscreen_win32 [13] also implement full-screen on Windows using a
181187
similar approach as my plug-in. I prefer the effect of my plug-in because it
182188
seems to hide window decorations more effectively. Also note that my plug-in
183189
was developed independently of the other two.
@@ -189,13 +195,13 @@ Contact ~
189195
If you have questions, bug reports, suggestions, etc. the author can be
190196
contacted at peter@peterodding.com. The latest version is available at
191197
http://peterodding.com/code/vim/shell/ and http://github.com/xolox/vim-shell.
192-
If you like the plug-in please vote for it on Vim Online [8].
198+
If you like the plug-in please vote for it on Vim Online [9].
193199

194200
===============================================================================
195201
*shell-license*
196202
License ~
197203

198-
This software is licensed under the MIT license [13]. Copyright 2011 Peter
204+
This software is licensed under the MIT license [14]. Copyright 2011 Peter
199205
Odding <peter@peterodding.com>.
200206

201207
===============================================================================
@@ -206,14 +212,15 @@ References ~
206212
[2] http://peterodding.com/code/vim/open-associated-programs/
207213
[3] http://peterodding.com/code/vim/easytags/
208214
[4] http://en.wikipedia.org/wiki/Dynamic-link_library
209-
[5] http://peterodding.com/code/vim/downloads/shell.zip
210-
[6] http://en.wikipedia.org/wiki/Taskbar
215+
[5] http://en.wikipedia.org/wiki/Taskbar
216+
[6] http://peterodding.com/code/vim/session
211217
[7] http://en.wikipedia.org/wiki/Ctags
212-
[8] http://www.vim.org/scripts/script.php?script_id=3123
213-
[9] http://github.com/xolox/vim-shell
214-
[10] http://github.com/xolox/vim-shell/blob/master/dll/Makefile
215-
[11] http://www.vim.org/scripts/script.php?script_id=687
216-
[12] http://www.vim.org/scripts/script.php?script_id=2596
217-
[13] http://en.wikipedia.org/wiki/MIT_License
218+
[8] http://peterodding.com/code/vim/downloads/shell.zip
219+
[9] http://www.vim.org/scripts/script.php?script_id=3123
220+
[10] http://github.com/xolox/vim-shell
221+
[11] http://github.com/xolox/vim-shell/blob/master/dll/Makefile
222+
[12] http://www.vim.org/scripts/script.php?script_id=687
223+
[13] http://www.vim.org/scripts/script.php?script_id=2596
224+
[14] http://en.wikipedia.org/wiki/MIT_License
218225

219226
vim: ft=help

plugin/shell.vim

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,6 @@ if !exists('g:shell_mappings_enabled')
1818
let g:shell_mappings_enabled = 1
1919
endif
2020

21-
if !exists('g:shell_fullscreen_items')
22-
" Change this if :Fullscreen shouldn't hide the menu/toolbar/tabline.
23-
let g:shell_fullscreen_items = 'mTe'
24-
endif
25-
26-
if !exists('g:shell_hl_exclude')
27-
" URL highlighting breaks highlighting of <a href="..."> tags in HTML.
28-
let g:shell_hl_exclude = '^\(x|ht\)ml$'
29-
endif
30-
31-
if !exists('g:shell_patt_url')
32-
let g:shell_patt_url = '\<\w\{3,}://\(\S*\w\)\+[/?#]\?'
33-
endif
34-
35-
if !exists('g:shell_patt_mail')
36-
let g:shell_patt_mail = '\<\w[^@ \t\r]*\w@\w[^@ \t\r]\+\w\>'
37-
endif
38-
3921
" Automatic commands. {{{1
4022

4123
augroup PluginShell

0 commit comments

Comments
 (0)