Skip to content

Commit

Permalink
Version 3.0
Browse files Browse the repository at this point in the history
 New Features
 ------------
 - You can specify which Vim instance to edit the file by setting a variable in your .vimrc (i.e. let g:outlook_servername = 'OUTLOOK')

 Bug Fixes
 ---------
 - For some (international?) Windows versions, there were errors when (or a failure) editing the file.  Needed to escape the backslashes of the filename.
  • Loading branch information
dfishburn authored and vim-scripts committed Oct 18, 2010
1 parent 3974b9e commit 31df3dd
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 43 deletions.
22 changes: 20 additions & 2 deletions doc/outlook.txt
@@ -1,12 +1,12 @@
*outlook.txt* For Vim version 7.0. Last change: 2010 May 06
*outlook.txt* For Vim version 7.0. Last change: 2010 May 09


VIM REFERENCE MANUAL
by
David Fishburn <dfishburn dot vim at gmail dot com>

Outlook Vim Plugin
outlook.vim version 2.0
outlook.vim version 3.0

For instructions on installing this file, type
:help add-local-help
Expand Down Expand Up @@ -70,6 +70,19 @@ David Fishburn
==============================================================================
2. What's New *outlook-new*

Version 3.0

New Features
------------
- You can specify which Vim instance to edit the file by setting a variable
in your .vimrc (i.e. let g:outlook_servername = 'OUTLOOK')

Bug Fixes
---------
- For some (international?) Windows versions, there were errors when (or a
failure) editing the file. Needed to escape the backslashes of the filename.


Version 2.0

New Features
Expand Down Expand Up @@ -203,6 +216,11 @@ Version 1.0
let g:outlook_javascript = 'C:\Documents and Settings\Username\My Documents\outlookvim.js'
let g:outlook_javascript = expand('$APPDATA\Microsoft\outlookvim.js')
let g:outlook_javascript = expand('$USERPROFILE\Application Data\Microsoft\outlookvim.js')
<
This setting (default = '') will force all emails to be edited in a particular
Vim instance. If the instance has not be started, a message is displayed
with an example command line to start an appropriate Vim. >
let g:outlook_servername = ''
<
This setting (default = 1) overrides the default textwidth the mail ftplugin sets. This
allows you to automatically format text using gq by setting the following: >
Expand Down
77 changes: 45 additions & 32 deletions plugin/OutlookVim.bas
Expand Up @@ -5,7 +5,7 @@
' Macro Security settings and creating digit certificates
' http://www.pcreview.co.uk/forums/thread-854025.php
'
' Version 2.0
' Version 3.0

Option Explicit

Expand Down Expand Up @@ -67,7 +67,7 @@ Sub Edit()
' Const VIMLocation = "C:\Vim\vim72\gvim.exe"


Dim ol, insp, item, fso, tempfile, tfolder, tname, tfile, cfile, entryID, appRef, x, Vim, vimKeys
Dim ol, insp, item, fso, tempfile, tfolder, tname, tfile, cfile, entryID, appRef, x, index, Vim, vimKeys, vimResponse, vimServerName
Dim overwrite As Boolean, unicode As Boolean

' MsgBox ("Just starting LaunchVim")
Expand All @@ -91,7 +91,7 @@ Sub Edit()
If item.entryID = "" Then
' If there is no EntryID, Vim will not be able to update
' the email during the save.
' Saving the item in Outlook will generate an EntryID
' Saving the item in Outlook will generate an EntryID
' and allow Vim to edit the contents.
item.Save
If Err.Number <> 0 Then
Expand All @@ -102,6 +102,37 @@ Sub Edit()
End If
End If

' Create an instance of Vim (if one does not already exist)
Set Vim = CreateObject("Vim.Application")
If Vim Is Nothing Then
MsgBox ("Could not create a Vim OLE object, please ensure Vim has been installed." & vbCrLf & "Inside Vim, run this command, it should echo 1," & vbCrLf & " :echo has('ole')")
Exit Sub
End If

vimResponse = Vim.Eval("(exists('g:loaded_outlook')?1:0)")
If vimResponse = 0 Then
MsgBox ("Please install the plugin OutlookVim from www.vim.org to continue" & vbCrLf)
Exit Sub
End If

vimResponse = Vim.Eval("(exists('g:outlook_servername')?1:0)")
If vimResponse = 0 Then
MsgBox ("Please ensure g:outlook_servername is set in version 3.0 or above of OutlookVim" & vbCrLf)
Exit Sub
End If

vimServerName = Vim.Eval("g:outlook_servername")
If vimServerName <> "" Then
vimResponse = Vim.Eval("match(serverlist(), '\<" & vimServerName & "\>')")
If vimResponse = -1 Then
MsgBox ("There are no Vim instances running named: " & vbCrLf & vimServerName & vbCrLf & vbCrLf _
& "Found these Vim instances: " & vbCrLf & Vim.Eval("serverlist()") & vbCrLf _
& "Please start a new Vim instance using " & vbCrLf & " 'gvim --servername " & vimServerName & "'" _
)
Exit Sub
End If
End If

Set fso = CreateObject("Scripting.FileSystemObject")
Set tfolder = fso.GetSpecialFolder(TemporaryFolder)
tname = fso.GetTempName
Expand All @@ -126,9 +157,9 @@ Sub Edit()
If Err.Number <> 0 Then
' Clear Err object fields.
' Err.Clear
MsgBox ("Could not create email file [" & tfolder & "\" & tname & "] " & vbCrLf & Err.Description)
MsgBox ("Could not create email file [" & tfolder.ShortPath & "\\" & tname & "] " & vbCrLf & Err.Description)
tfile.Close
fso.DeleteFile (tfolder.ShortPath & "\" & tname & "\" & tname)
fso.DeleteFile (tfolder.ShortPath & "\\" & tname)
' Quit will close Outlook
' Quit
Exit Sub
Expand All @@ -152,30 +183,24 @@ Sub Edit()
If Err.Number <> 0 Then
' Clear Err object fields.
' Err.Clear
MsgBox ("Could not create control file [" & tfolder & "\" & tname & "] " & vbCrLf & Err.Description)
MsgBox ("Could not create control file [" & tfolder.ShortPath & "\\" & tname & "] " & vbCrLf & Err.Description)
cfile.Close
fso.DeleteFile (tfolder.ShortPath & "\" & tname & "\" & tname)
fso.DeleteFile (tfolder.ShortPath & "\" & tname & "\" & tname & ".ctl")
fso.DeleteFile (tfolder.ShortPath & "\\" & tname)
fso.DeleteFile (tfolder.ShortPath & "\\" & tname & ".ctl")
' Quit will close Outlook
' Quit
Exit Sub
End If
cfile.Close
' MsgBox ("id:" & item.EntryID)
' MsgBox tfolder.ShortPath & "\" & tname
' MsgBox tfolder.ShortPath & "\\" & tname


' Create an instance of Vim (if one does not already exist)
Set Vim = CreateObject("Vim.Application")
If Vim Is Nothing Then
MsgBox ("Could not create a Vim OLE object, please ensure Vim has been installed." & vbCrLf & "Inside Vim, run this command, it should echo 1," & vbCrLf & " :echo has('ole')")
Exit Sub
End If

vimKeys = "<ESC>:e "
vimKeys = ":call Outlook_EditFile( '" & tfolder.ShortPath & "\\" & tname & "', '"
If unicode Then
vimKeys = vimKeys & " ++enc=utf-16 "
vimKeys = vimKeys & "utf-16"
End If
vimKeys = vimKeys & tfolder.ShortPath & "\" & tname & "<Enter>"
vimKeys = vimKeys & "' )<Enter>"

' MsgBox (vimKeys)
' Use Vim's OLE feature to edit the email
Expand All @@ -185,18 +210,6 @@ Sub Edit()
' Force the Vim to the foreground
Vim.SetForeground

' Do not spawn a new instance of Vim
' ExecCmd VIMLocation & " " & Chr(34) & tfolder.Path & "\" & tname & Chr(34)

' Since the above Vim command forks, do not bother to wait
' and read and delete the file
' Set tfile = fso.OpenTextFile(tfolder.Path & "\" & tname, 1)
' item.body = Replace(tfile.ReadAll, Chr(10), Chr(13) & Chr(10))
' tfile.Close

' Outlookvim javascript file will delete the file when finished
' fso.DeleteFile (tfolder.Path & "\" & tname)

Finished:
End Sub

Expand All @@ -218,7 +231,7 @@ Public Sub ExecCmd(cmdline$)
ReturnValue = WaitForSingleObject(proc.hProcess, 0)
DoEvents
Loop Until ReturnValue <> 258

ReturnValue = CloseHandle(proc.hProcess)

End Sub
Expand Down
36 changes: 29 additions & 7 deletions plugin/outlook.vim
@@ -1,8 +1,8 @@
" outlook.vim - Edit emails using Vim from Outlook
" ---------------------------------------------------------------
" Version: 2.0
" Version: 3.0
" Authors: David Fishburn <dfishburn dot vim at gmail dot com>
" Last Modified: 2010 May 06
" Last Modified: 2010 May 09
" Created: 2009 Jan 17
" Homepage: http://vim.sourceforge.net/script.php?script_id=???
" Help: :h outlook.txt
Expand Down Expand Up @@ -41,15 +41,20 @@ else
let &textwidth = 76
endif

" servername - Choose which Vim server instance to edit the email with
if !exists('g:outlook_servername')
let g:outlook_servername = ''
endif

function! Outlook_WarningMsg(msg)
echohl WarningMsg
echomsg a:msg
echomsg "outlook: ".a:msg
echohl None
endfunction

function! Outlook_ErrorMsg(msg)
echohl ErrorMsg
echomsg a:msg
echomsg "outlook: ".a:msg
echohl None
endfunction

Expand All @@ -67,23 +72,40 @@ function! Outlook_ExecuteJS(filename)
echomsg result
endfunction

function! Outlook_EditFile(filename, encoding)
let cmd = ':e '.
\ (a:encoding==''?'':'++enc='.a:encoding).
\ ' '.a:filename.
\ "\n"
let g:outlook_last_cmd = cmd
if g:outlook_servername == '' || g:outlook_servername == v:servername
exec cmd
else
if match( serverlist(), '\<'.g:outlook_servername.'\>' ) > -1
call remote_send( g:outlook_servername, cmd )
else
call Outlook_ErrorMsg( 'Please start a new Vim instance using "gvim --servername '.g:outlook_servername.'"')
endif
endif
endfunction

" Check is cscript.exe is already in the PATH
" Some path entries may end in a \ (c:\util\;), this must also be replaced
" or globpath fails to parse the directories
if strlen(globpath(substitute($PATH, '\\\?;', ',', 'g'), 'cscript.exe')) == 0
call Outlook_ErrorMsg("outlook: Cannot find cscript.exe in system path")
call Outlook_ErrorMsg("Cannot find cscript.exe in system path")
finish
endif

if exists('g:outlook_javascript')
if !filereadable(expand(g:outlook_javascript))
call Outlook_ErrorMsg("outlook: Cannot find javascript: " .
call Outlook_ErrorMsg("Cannot find javascript: " .
\ expand(g:outlook_javascript) )
finish
endif
else
if !filereadable(expand(s:outlook_javascript_default))
call Outlook_ErrorMsg("outlook: Cannot find javascript: " .
call Outlook_ErrorMsg("Cannot find javascript: " .
\ expand(s:outlook_javascript_default) )
finish
endif
Expand Down
4 changes: 2 additions & 2 deletions plugin/outlookvim.js
@@ -1,8 +1,8 @@
// outlookvim.js
//
// Author: David Fishburn
// Version: 2.0
// Last Modified: 2010 May 06
// Version: 3.0
// Last Modified: 2010 May 09
// Homepage: http://vim.sourceforge.net/script.php?script_id=???
//
// Purpose:
Expand Down

0 comments on commit 31df3dd

Please sign in to comment.