Skip to content

Commit

Permalink
Make sure vim-misc is installed, politely complain if it isn't
Browse files Browse the repository at this point in the history
  • Loading branch information
xolox committed Aug 19, 2013
1 parent 4cb3c4c commit 4aa630e
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 55 deletions.
1 change: 1 addition & 0 deletions addon-info.json
@@ -0,0 +1 @@
{"vim_script_nr": 2252, "dependencies": {"vim-misc": {}}, "homepage": "http://peterodding.com/code/vim/publish", "name": "vim-publish"}
2 changes: 1 addition & 1 deletion autoload/xolox/publish.vim
Expand Up @@ -3,7 +3,7 @@
" Last Change: August 19, 2013
" URL: http://peterodding.com/code/vim/publish/

let g:xolox#publish#version = '1.7.13'
let g:xolox#publish#version = '1.7.14'

function! xolox#publish#resolve_files(directory, pathnames) " {{{1
" Create a dictionary that maps the fully resolved pathnames of the files to
Expand Down
120 changes: 67 additions & 53 deletions doc/publish.txt
@@ -1,25 +1,25 @@
*publish.txt* Publish hyperlinked, syntax highlighted source code with Vim

===============================================================================
*publish-contents*
Contents ~

1. Introduction |publish-introduction|
2. Installation & usage |publish-installation-usage|
3. Publishing to a remote location (website)
4. Contact |publish-contact|
5. License |publish-license|
1. Introduction |publish-introduction|
2. Installation & usage |publish-installation-usage|
3. Publishing to a remote location (website) |publishing-to-remote-location|
4. Contact |publish-contact|
5. License |publish-license|
6. References |publish-references|

===============================================================================
*publish-introduction*
*publish-introduction*
Introduction ~

The Vim text editor includes the script |2html.vim| which can be used to convert
a syntax highlighted buffer in Vim to an HTML document that, when viewed in a
web browser, should look exactly the same. After using that script for a while
and discovering the excellent Exuberant Ctags [1] I wondered "Wouldn't it be
nice to have those tags converted to hyperlinks when I publish source code as
HTML?".
The Vim text editor includes the script |2html.vim| which can be used to
convert a syntax highlighted buffer in Vim to an HTML document that, when
viewed in a web browser, should look exactly the same. After using that script
for a while and discovering the excellent Exuberant Ctags [1] I wondered
_"Wouldn't it be nice to have those tags converted to hyperlinks when I publish
source code as HTML?"_.

After several attempts I managed a working prototype, but it was quite rough
around the edges and I didn't really have the time or interest to clean it up.
Expand All @@ -29,91 +29,105 @@ wondering what the result looks like, I've published the plug-in source code
[2] as a demonstration.

===============================================================================
*publish-installation-usage*
*publish-installation-usage*
Installation & usage ~

Unzip the most recent ZIP archive [3] file inside your Vim profile directory
(usually this is '~/.vim' on UNIX and '%USERPROFILE%\vimfiles' on Windows),
restart Vim and execute the command ':helptags ~/.vim/doc' (use ':helptags
~\vimfiles\doc' instead on Windows). As an example we'll publish the plug-in
using itself. First create a tags file that contains entries for the files you
want to publish using a shell command such as:
>
$ ctags -Rf ~/.publish_tags ~/.vim/
_Please note that the vim-publish plug-in requires my vim-misc plug-in which is
separately distributed._

Unzip the most recent ZIP archives of the vim-publish [3] and vim-misc [4]
plug-ins inside your Vim profile directory (usually this is '~/.vim' on UNIX
and '%USERPROFILE%\vimfiles' on Windows), restart Vim and execute the command
':helptags ~/.vim/doc' (use ':helptags ~\vimfiles\doc' instead on Windows). If
you prefer you can also use Pathogen [5], Vundle [6] or a similar tool to
install & update the vim-publish [7] and vim-misc [8] plug-ins using a local
clone of the git repository.

As an example we'll publish the plug-in using itself. First create a tags file
that contains entries for the files you want to publish using a shell command
such as:
>
$ ctags -Rf ~/.publish_tags ~/.vim/
<
If this doesn't work because |ctags| isn't installed you can download it from
the Exuberant Ctags homepage [1], or if you're running Debian/Ubuntu you can
install it by executing the following shell command:
>
$ sudo apt-get install exuberant-ctags
$ sudo apt-get install exuberant-ctags
<
The plug-in needs an up-to-date tags file so that it can create hyperlinks
between the published files. Now start Vim and write a script that registers
the tags file you just created and calls the function 'Publish()' as follows:
>
:set tags=~/.publish_tags
:let sources = '/home/peter/.vim'
:let target = 'sftp://peterodding.com/code/vim/profile'
:call Publish(sources, target, [
\ 'autoload/xolox/escape.vim',
\ 'autoload/xolox/path.vim',
\ 'autoload/publish.vim',
\ 'plugin/publish.vim',
\ ])
Change the 'sources' and 'target' variables to reflect your situation, save
the script as '~/publish_test.vim' and try it in Vim by executing the command
:set tags=~/.publish_tags
:let sources = '/home/peter/.vim'
:let target = 'sftp://peterodding.com/code/vim/profile'
:call Publish(sources, target, [
\ 'autoload/xolox/escape.vim',
\ 'autoload/xolox/path.vim',
\ 'autoload/publish.vim',
\ 'plugin/publish.vim',
\ ])
<
Change the 'sources' and 'target' variables to reflect your situation, save the
script as '~/publish_test.vim' and try it in Vim by executing the command
':source ~/publish_test.vim'. If everything goes well Vim will be busy for a
moment and after that you will find a bunch of syntax highlighted, interlinked
HTML documents in the 'target' directory!

===============================================================================
*publishing-to-remote-location*
Publishing to a remote location (website) ~

As you can see from the example above it's possible to publish files directly
to your web server using the |netrw| plug-in that's bundled with Vim, simply by
starting the 'target' path with 'sftp://'. All you need for this to work is
the ability to establish SCP [4] connections to your server. There are however
two disadvantages to remote publishing over SFTP [5]:
starting the 'target' path with 'sftp://'. All you need for this to work is the
ability to establish SCP [9] connections to your server. There are however two
disadvantages to remote publishing over SFTP [10]:

- The 'publish.vim' plug-in can't automatically create directories on the
1. The 'publish.vim' plug-in can't automatically create directories on the
remote side, which means you'll have to do so by hand -- very bothersome.

- It can take a while to publish a dozen files because a new connection is
2. It can take a while to publish a dozen files because a new connection is
established for every file that's uploaded to the remote location.

As a workaround to both of these issues the 'publish.vim' plug-in will
automatically use rsync [6] when both the local and remote system have it
automatically use rsync [11] when both the local and remote system have it
installed. This cuts the time to publish to a remote location in half and
enables the plug-in to automatically create directories on the remote side.

===============================================================================
*publish-contact*
*publish-contact*
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/publish/ and http://github.com/xolox/vim-publish.
If you like the script please vote for it on Vim Online [7].
http://peterodding.com/code/vim/publish/ and http://github.com/xolox/vim-
publish. If you like the script please vote for it on Vim Online [12].

===============================================================================
*publish-license*
*publish-license*
License ~

This software is licensed under the MIT license [8]. Š 2013 Peter Odding
This software is licensed under the MIT license [13]. Š 2013 Peter Odding
<peter@peterodding.com>.

===============================================================================
*publish-references*
*publish-references*
References ~

[1] http://ctags.sourceforge.net/
[2] http://peterodding.com/code/vim/profile/plugin/publish.vim
[3] http://peterodding.com/code/vim/downloads/publish.zip
[4] http://en.wikipedia.org/wiki/Secure_copy
[5] http://en.wikipedia.org/wiki/SSH_file_transfer_protocol
[6] http://en.wikipedia.org/wiki/rsync
[7] http://www.vim.org/scripts/script.php?script_id=2252
[8] http://en.wikipedia.org/wiki/MIT_License
[4] http://peterodding.com/code/vim/downloads/misc.zip
[5] http://www.vim.org/scripts/script.php?script_id=2332
[6] https://github.com/gmarik/vundle
[7] https://github.com/xolox/vim-publish
[8] https://github.com/xolox/vim-misc
[9] http://en.wikipedia.org/wiki/Secure_copy
[10] http://en.wikipedia.org/wiki/SSH_file_transfer_protocol
[11] http://en.wikipedia.org/wiki/rsync
[12] http://www.vim.org/scripts/script.php?script_id=2252
[13] http://en.wikipedia.org/wiki/MIT_License

vim: ft=help
15 changes: 14 additions & 1 deletion plugin/publish.vim
@@ -1,6 +1,6 @@
" Vim plug-in
" Author: Peter Odding <peter@peterodding.com>
" Last Change: September 4, 2011
" Last Change: August 19, 2013
" URL: http://peterodding.com/code/vim/publish/

" Support for automatic update using the GLVS plug-in.
Expand All @@ -11,6 +11,19 @@ if &cp || exists('g:loaded_publish')
finish
endif

" Make sure vim-misc is installed.
try
" The point of this code is to do something completely innocent while making
" sure the vim-misc plug-in is installed. We specifically don't use Vim's
" exists() function because it doesn't load auto-load scripts that haven't
" already been loaded yet (last tested on Vim 7.3).
call type(g:xolox#misc#version)
catch
echomsg "Warning: The vim-publish plug-in requires the vim-misc plug-in which seems not to be installed! For more information please review the installation instructions in the readme (also available on the homepage and on GitHub). The vim-publish plug-in will now be disabled."
let g:loaded_publish = 1
finish
endtry

if !exists('g:publish_omit_dothtml')
let g:publish_omit_dothtml = 0
endif
Expand Down

0 comments on commit 4aa630e

Please sign in to comment.