Skip to content

Commit

Permalink
Bug fix for last commit :-\
Browse files Browse the repository at this point in the history
 * 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()
  • Loading branch information
xolox committed Aug 31, 2011
1 parent 6cbfe98 commit 168d0cd
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 64 deletions.
14 changes: 10 additions & 4 deletions README.md
Expand Up @@ -10,9 +10,7 @@ This plug-in aims to improve the integration between [Vim][vim] and its environm

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

## Usage

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.
## Usage (commands & functions)

### The `:Fullscreen` command

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

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.

### The `xolox#shell#fullscreen()` function

Call this function to toggle Vim's full screen status. The `:Fullscreen` command is just a shorter way to call this function.

### The `xolox#shell#is_fullscreen()` function

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.

### The `g:shell_fullscreen_items` option

This variable is a string containing any combination of the following characters:
Expand All @@ -58,7 +64,7 @@ This variable is a string containing any combination of the following characters
* `T`: Hide the [toolbar](http://vimdoc.sourceforge.net/htmldoc/options.html#%27go-T%27) when switching to full-screen;
* `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)).

By default all the above items are hidden in full-screen mode.
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.

### The `g:shell_mappings_enabled` option

Expand Down
38 changes: 24 additions & 14 deletions autoload/xolox/shell.vim
Expand Up @@ -3,7 +3,7 @@
" Last Change: August 31, 2011
" URL: http://peterodding.com/code/vim/shell/

let g:xolox#shell#version = '0.9.8'
let g:xolox#shell#version = '0.9.9'

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

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

function! xolox#shell#highlight_urls() " -- highlight URLs and e-mail addresses embedded in source code comments {{{1
if exists('g:syntax_on') && &ft !~ g:shell_hl_exclude
" URL highlighting breaks highlighting of <a href="..."> tags in HTML.
if exists('g:syntax_on') && &ft !~ xolox#misc#option#get('shell_hl_exclude', '^\(x|ht\)ml$')
if &ft == 'help'
let command = 'syntax match %s /%s/'
let urlgroup = 'HelpURL'
Expand All @@ -84,8 +85,8 @@ function! xolox#shell#highlight_urls() " -- highlight URLs and e-mail addresses
let urlgroup = 'CommentURL'
let mailgroup = 'CommentEmail'
endif
execute printf(command, urlgroup, escape(g:shell_patt_url, '/'))
execute printf(command, mailgroup, escape(g:shell_patt_mail, '/'))
execute printf(command, urlgroup, escape(xolox#shell#url_pattern(), '/'))
execute printf(command, mailgroup, escape(xolox#shell#mail_pattern(), '/'))
execute 'highlight def link' urlgroup 'Underlined'
execute 'highlight def link' mailgroup 'Underlined'
endif
Expand Down Expand Up @@ -129,7 +130,7 @@ function! xolox#shell#execute(command, synchronous, ...) " -- execute external c
return 1
endif
catch
call xolox#misc#msg#warn("shell.vim %s: %s at %s", g:shell_version, v:exception, v:throwpoint)
call xolox#misc#msg#warn("shell.vim %s: %s at %s", g:xolox#shell#version, v:exception, v:throwpoint)
finally
if exists('tempin') | call delete(tempin) | endif
if exists('tempout') | call delete(tempout) | endif
Expand All @@ -149,13 +150,14 @@ function! xolox#shell#fullscreen() " -- toggle Vim between normal and full-scree
" Hide the main menu, tool bar and/or tab line. Remember what was hidden
" so its visibility can be restored when the user leaves full-screen.
let s:go_toggled = ''
for item in split(g:shell_fullscreen_items, '.\zs')
let fullscreen_items = xolox#misc#option#get('shell_fullscreen_items', 'mTe')
for item in split(fullscreen_items, '.\zs')
if &go =~# item
let s:go_toggled .= item
execute 'set go-=' . item
endif
endfor
if g:shell_fullscreen_items =~# 'e' && &stal != 0
if fullscreen_items =~# 'e' && &stal != 0
let s:stal_save = &stal
set showtabline=0
endif
Expand All @@ -180,7 +182,7 @@ function! xolox#shell#fullscreen() " -- toggle Vim between normal and full-scree
throw printf(s:enoimpl, 'fullscreen', s:contact)
endif
catch
call xolox#misc#msg#warn("shell.vim %s: %s at %s", g:shell_version, v:exception, v:throwpoint)
call xolox#misc#msg#warn("shell.vim %s: %s at %s", g:xolox#shell#version, v:exception, v:throwpoint)
endtry

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

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

function! xolox#shell#url_pattern() " -- get the preferred/default pattern to match URLs {{{1
return xolox#misc#option#get('shell_patt_url', '\<\w\{3,}://\(\S*\w\)\+[/?#]\?')
endfunction

function! xolox#shell#mail_pattern() " -- get the preferred/default pattern to match e-mail addresses {{{1
return xolox#misc#option#get('shell_patt_mail', '\<\w\{3,}://\(\S*\w\)\+[/?#]\?')
endfunction

" Miscellaneous script-local functions. {{{1

if xolox#misc#os#is_win()
Expand Down
63 changes: 35 additions & 28 deletions doc/shell.txt
Expand Up @@ -23,16 +23,8 @@ Two Windows DLL files [4] are included to perform these functions on Windows,
while on UNIX external commands are used.

===============================================================================
*shell-usage*
Usage ~

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| 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 [5] in the '%USERPROFILE%\vimfiles'
directory (on Windows) or the '~/.vim/' directory (on UNIX), restarting Vim
and checking whether the commands below work as documented.
*shell-usage-(commands-functions)*
Usage (commands & functions) ~

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

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

-------------------------------------------------------------------------------
The *xolox#shell#fullscreen()* function

Call this function to toggle Vim's full screen status. The |:Fullscreen|
command is just a shorter way to call this function.

-------------------------------------------------------------------------------
The *xolox#shell#is_fullscreen()* function

Call this function to determine whether Vim is in full screen mode. My
session.vim plug-in [6] uses this to persist full screen mode.

-------------------------------------------------------------------------------
The *g:shell_fullscreen_items* option

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

By default all the above items are hidden in full-screen mode.
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.

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

===============================================================================
*shell-other-full-screen-implementations*
Other full-screen implementations ~

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

===============================================================================
*shell-license*
License ~

This software is licensed under the MIT license [13]. Copyright 2011 Peter
This software is licensed under the MIT license [14]. Copyright 2011 Peter
Odding <peter@peterodding.com>.

===============================================================================
Expand All @@ -206,14 +212,15 @@ References ~
[2] http://peterodding.com/code/vim/open-associated-programs/
[3] http://peterodding.com/code/vim/easytags/
[4] http://en.wikipedia.org/wiki/Dynamic-link_library
[5] http://peterodding.com/code/vim/downloads/shell.zip
[6] http://en.wikipedia.org/wiki/Taskbar
[5] http://en.wikipedia.org/wiki/Taskbar
[6] http://peterodding.com/code/vim/session
[7] http://en.wikipedia.org/wiki/Ctags
[8] http://www.vim.org/scripts/script.php?script_id=3123
[9] http://github.com/xolox/vim-shell
[10] http://github.com/xolox/vim-shell/blob/master/dll/Makefile
[11] http://www.vim.org/scripts/script.php?script_id=687
[12] http://www.vim.org/scripts/script.php?script_id=2596
[13] http://en.wikipedia.org/wiki/MIT_License
[8] http://peterodding.com/code/vim/downloads/shell.zip
[9] http://www.vim.org/scripts/script.php?script_id=3123
[10] http://github.com/xolox/vim-shell
[11] http://github.com/xolox/vim-shell/blob/master/dll/Makefile
[12] http://www.vim.org/scripts/script.php?script_id=687
[13] http://www.vim.org/scripts/script.php?script_id=2596
[14] http://en.wikipedia.org/wiki/MIT_License

vim: ft=help
18 changes: 0 additions & 18 deletions plugin/shell.vim
Expand Up @@ -18,24 +18,6 @@ if !exists('g:shell_mappings_enabled')
let g:shell_mappings_enabled = 1
endif

if !exists('g:shell_fullscreen_items')
" Change this if :Fullscreen shouldn't hide the menu/toolbar/tabline.
let g:shell_fullscreen_items = 'mTe'
endif

if !exists('g:shell_hl_exclude')
" URL highlighting breaks highlighting of <a href="..."> tags in HTML.
let g:shell_hl_exclude = '^\(x|ht\)ml$'
endif

if !exists('g:shell_patt_url')
let g:shell_patt_url = '\<\w\{3,}://\(\S*\w\)\+[/?#]\?'
endif

if !exists('g:shell_patt_mail')
let g:shell_patt_mail = '\<\w[^@ \t\r]*\w@\w[^@ \t\r]\+\w\>'
endif

" Automatic commands. {{{1

augroup PluginShell
Expand Down

0 comments on commit 168d0cd

Please sign in to comment.