Skip to content

Commit

Permalink
Extract :Maximize from :Fullscreen (suggested by Benjamin Bergman)
Browse files Browse the repository at this point in the history
  • Loading branch information
xolox committed Sep 17, 2011
1 parent 34ef803 commit 665a2b5
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 33 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ This plug-in aims to improve the integration between [Vim][vim] and its environm


* The `:Fullscreen` command and `<F11>` mapping toggle Vim between normal and full-screen mode (see the [screenshots](http://peterodding.com/code/vim/shell/screenshots/)). To invoke this functionality without using the `:Fullscreen` command see the `xolox#shell#fullscreen()` and `xolox#shell#is_fullscreen()` functions. * The `:Fullscreen` command and `<F11>` mapping toggle Vim between normal and full-screen mode (see the [screenshots](http://peterodding.com/code/vim/shell/screenshots/)). To invoke this functionality without using the `:Fullscreen` command see the `xolox#shell#fullscreen()` and `xolox#shell#is_fullscreen()` functions.


* The `:Maximize` command and `<Control-F11>` mapping toggle Vim between normal and maximized state: They show/hide Vim's menu bar, tool bar and/or tab line without hiding the operating system task bar.

* The `:Open` command and `<F6>` mapping know how to open file and directory names, URLs and e-mail addresses in your favorite programs (file manager, web browser, e-mail client, etc). To invoke this functionality without using the `:Open` command see my [open.vim](http://peterodding.com/code/vim/open-associated-programs/) plug-in, which was split off from `shell.vim` so that other Vim plug-ins can bundle it without bringing in all the other crap :-). * The `:Open` command and `<F6>` mapping know how to open file and directory names, URLs and e-mail addresses in your favorite programs (file manager, web browser, e-mail client, etc). To invoke this functionality without using the `:Open` command see my [open.vim](http://peterodding.com/code/vim/open-associated-programs/) plug-in, which was split off from `shell.vim` so that other Vim plug-ins can bundle it without bringing in all the other crap :-).


* The `xolox#shell#execute()` function enables other Vim plug-ins (like my [easytags.vim] [easytags] plug-in) to execute external commands in the background (i.e. asynchronously) *without opening a command prompt window on Windows*. * The `xolox#shell#execute()` function enables other Vim plug-ins (like my [easytags.vim] [easytags] plug-in) to execute external commands in the background (i.e. asynchronously) *without opening a command prompt window on Windows*.
Expand All @@ -12,11 +14,13 @@ Two [Windows DLL files][dll] are included to perform these functions on Windows,


## Usage (commands & functions) ## Usage (commands & functions)


### The `:Fullscreen` command ### The `:Maximize` command


The `:Fullscreen` command toggles Vim between normal and [full-screen mode](http://peterodding.com/code/vim/shell/screenshots/). It's mapped to `<F11>` by default, see `g:shell_mappings_enabled` if you don't like this. This command toggles the visibility of Vim's main menu, tool bar and/or tab line. It's mapped to `<Control-F11>` by default, see `g:shell_mappings_enabled` if you don't like this. If you want to change which items are hidden see the `g:shell_fullscreen_items` option.

### The `:Fullscreen` command


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] [gui] is switched to real full-screen mode (hiding any [taskbars, panels or docks](http://en.wikipedia.org/wiki/Taskbar)). When you leave full-screen Vim's main menu, toolbar and tabline are restored and the [GUI window] [gui] is switched back to normal mode. The `:Fullscreen` command toggles Vim between normal and [full-screen mode](http://peterodding.com/code/vim/shell/screenshots/). It's mapped to `<F11>` by default, see `g:shell_mappings_enabled` if you don't like this. This command first executes `:Maximize` and then (if possible) switches Vim's [GUI window] [gui] to real full-screen mode (hiding any [taskbars, panels or docks](http://en.wikipedia.org/wiki/Taskbar)). When you leave full-screen Vim's main menu, toolbar and tabline are restored and the [GUI window] [gui] is switched back to normal mode.


Note that on UNIX this command even works inside of graphical terminal emulators like `gnome-terminal` or `xterm` (try it out!). Note that on UNIX this command even works inside of graphical terminal emulators like `gnome-terminal` or `xterm` (try it out!).


Expand Down
51 changes: 32 additions & 19 deletions autoload/xolox/shell.vim
Original file line number Original file line Diff line number Diff line change
@@ -1,14 +1,15 @@
" Vim auto-load script " Vim auto-load script
" Author: Peter Odding <peter@peterodding.com> " Author: Peter Odding <peter@peterodding.com>
" Last Change: September 4, 2011 " Last Change: September 18, 2011
" URL: http://peterodding.com/code/vim/shell/ " URL: http://peterodding.com/code/vim/shell/


let g:xolox#shell#version = '0.9.11' let g:xolox#shell#version = '0.9.12'


if !exists('s:fullscreen_enabled') if !exists('s:fullscreen_enabled')
let s:enoimpl = "%s() hasn't been implemented on your platform! %s" let s:enoimpl = "%s() hasn't been implemented on your platform! %s"
let s:contact = "If you have suggestions, please contact peter@peterodding.com." let s:contact = "If you have suggestions, please contact peter@peterodding.com."
let s:fullscreen_enabled = 0 let s:fullscreen_enabled = 0
let s:maximized = 0
endif endif


function! xolox#shell#open_cmd(arg) " -- implementation of the :Open command {{{1 function! xolox#shell#open_cmd(arg) " -- implementation of the :Open command {{{1
Expand Down Expand Up @@ -137,16 +138,9 @@ function! xolox#shell#execute(command, synchronous, ...) " -- execute external c
endtry endtry
endfunction endfunction


function! xolox#shell#fullscreen() " -- toggle Vim between normal and full-screen mode {{{1 function! xolox#shell#maximize(...) " -- show/hide Vim's menu, tool bar and/or tab line {{{1

let new_state = a:0 == 0 ? !s:maximized : a:1
" When entering full-screen... if new_state && !s:maximized
if !s:fullscreen_enabled
" Save the window position and size when running Windows, because my
" dynamic link library doesn't save/restore them while "wmctrl" does.
if xolox#misc#os#is_win()
let [s:lines_save, s:columns_save] = [&lines, &columns]
let [s:winpos_x_save, s:winpos_y_save] = [getwinposx(), getwinposy()]
endif
" Hide the main menu, tool bar and/or tab line. Remember what was hidden " 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. " so its visibility can be restored when the user leaves full-screen.
let s:go_toggled = '' let s:go_toggled = ''
Expand All @@ -161,6 +155,31 @@ function! xolox#shell#fullscreen() " -- toggle Vim between normal and full-scree
let s:stal_save = &stal let s:stal_save = &stal
set showtabline=0 set showtabline=0
endif endif
let s:maximized = 1
elseif s:maximized && !new_state
" Restore display of previously hidden GUI components?
let &go .= s:go_toggled
if exists('s:stal_save')
let &stal = s:stal_save
unlet s:stal_save
endif
unlet s:go_toggled
let s:maximized = 0
endif
return s:maximized
endfunction

function! xolox#shell#fullscreen() " -- toggle Vim between normal and full-screen mode {{{1

" When entering full-screen...
if !s:fullscreen_enabled
" Save the window position and size when running Windows, because my
" dynamic link library doesn't save/restore them while "wmctrl" does.
if xolox#misc#os#is_win()
let [s:lines_save, s:columns_save] = [&lines, &columns]
let [s:winpos_x_save, s:winpos_y_save] = [getwinposx(), getwinposy()]
endif
call xolox#shell#maximize(1)
endif endif


" Now try to toggle the real full-screen status of Vim's GUI window using a " Now try to toggle the real full-screen status of Vim's GUI window using a
Expand All @@ -187,13 +206,7 @@ function! xolox#shell#fullscreen() " -- toggle Vim between normal and full-scree


" When leaving full-screen... " When leaving full-screen...
if s:fullscreen_enabled if s:fullscreen_enabled
" Restore display of previously hidden GUI components? call xolox#shell#maximize(0)
let &go .= s:go_toggled
if exists('s:stal_save')
let &stal = s:stal_save
unlet s:stal_save
endif
unlet s:go_toggled
" Restore window position and size only on Windows -- I don't know why " Restore window position and size only on Windows -- I don't know why
" but the following actually breaks when running under "wmctrl"... " but the following actually breaks when running under "wmctrl"...
if xolox#misc#os#is_win() if xolox#misc#os#is_win()
Expand Down
24 changes: 16 additions & 8 deletions doc/shell.txt
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ This plug-in aims to improve the integration between Vim and its environment
without using the |:Fullscreen| command see the 'xolox#shell#fullscreen()' without using the |:Fullscreen| command see the 'xolox#shell#fullscreen()'
and 'xolox#shell#is_fullscreen()' functions. and 'xolox#shell#is_fullscreen()' functions.


- The |:Maximize| command and '<Control-F11>' mapping toggle Vim between
normal and maximized state: They show/hide Vim's menu bar, tool bar and/or
tab line without hiding the operating system task bar.

- The |:Open| command and '<F6>' mapping know how to open file and directory - The |:Open| command and '<F6>' mapping know how to open file and directory
names, URLs and e-mail addresses in your favorite programs (file manager, names, URLs and e-mail addresses in your favorite programs (file manager,
web browser, e-mail client, etc). To invoke this functionality without web browser, e-mail client, etc). To invoke this functionality without
Expand All @@ -26,19 +30,23 @@ while on UNIX external commands are used.
*shell-usage-(commands-functions)* *shell-usage-(commands-functions)*
Usage (commands & functions) ~ Usage (commands & functions) ~


-------------------------------------------------------------------------------
The *:Maximize* command

This command toggles the visibility of Vim's main menu, tool bar and/or tab
line. It's mapped to '<Control-F11>' by default, see |g:shell_mappings_enabled|
if you don't like this. If you want to change which items are hidden see the
|g:shell_fullscreen_items| option.

------------------------------------------------------------------------------- -------------------------------------------------------------------------------
The *:Fullscreen* command The *:Fullscreen* command


The |:Fullscreen| command toggles Vim between normal and full-screen mode [1]. The |:Fullscreen| command toggles Vim between normal and full-screen mode [1].
It's mapped to '<F11>' by default, see |g:shell_mappings_enabled| if you don't It's mapped to '<F11>' by default, see |g:shell_mappings_enabled| if you don't
like this. like this. This command first executes |:Maximize| and then (if possible)

switches Vim's |GUI| window to real full-screen mode (hiding any taskbars,
When you enter full-screen mode the main menu, toolbar and tabline are all panels or docks [5]). When you leave full-screen Vim's main menu, toolbar and
hidden (see |g:shell_fullscreen_items| if you want to change this) and when tabline are restored and the |GUI| window is switched back to normal mode.
possible Vim's |GUI| window is switched to real full-screen mode (hiding any
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.


Note that on UNIX this command even works inside of graphical terminal Note that on UNIX this command even works inside of graphical terminal
emulators like 'gnome-terminal' or 'xterm' (try it out!). emulators like 'gnome-terminal' or 'xterm' (try it out!).
Expand Down
9 changes: 6 additions & 3 deletions plugin/shell.vim
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,6 @@
" Vim plug-in " Vim plug-in
" Author: Peter Odding <peter@peterodding.com> " Author: Peter Odding <peter@peterodding.com>
" Last Change: August 31, 2011 " Last Change: September 18, 2011
" URL: http://peterodding.com/code/vim/shell/ " URL: http://peterodding.com/code/vim/shell/


" Support for automatic update using the GLVS plug-in. " Support for automatic update using the GLVS plug-in.
Expand Down Expand Up @@ -28,15 +28,18 @@ augroup END
" Regular commands. {{{1 " Regular commands. {{{1


command! -bar -nargs=? -complete=file Open call xolox#shell#open_cmd(<q-args>) command! -bar -nargs=? -complete=file Open call xolox#shell#open_cmd(<q-args>)
command! -bar Maximize call xolox#shell#maximize()
command! -bar Fullscreen call xolox#shell#fullscreen() command! -bar Fullscreen call xolox#shell#fullscreen()


" Default key mappings. {{{1 " Default key mappings. {{{1


if g:shell_mappings_enabled if g:shell_mappings_enabled
inoremap <F11> <C-o>:Fullscreen<CR>
nnoremap <F11> :Fullscreen<CR>
inoremap <F6> <C-o>:Open<CR> inoremap <F6> <C-o>:Open<CR>
nnoremap <F6> :Open<CR> nnoremap <F6> :Open<CR>
inoremap <F11> <C-o>:Fullscreen<CR>
nnoremap <F11> :Fullscreen<CR>
inoremap <C-F11> <C-o>:Maximize<CR>
nnoremap <C-F11> :Maximize<CR>
endif endif


" Make sure the plug-in is only loaded once. " Make sure the plug-in is only loaded once.
Expand Down

0 comments on commit 665a2b5

Please sign in to comment.