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 VIM REFERENCE MANUAL
by by
David Fishburn <dfishburn dot vim at gmail dot com> David Fishburn <dfishburn dot vim at gmail dot com>


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


For instructions on installing this file, type For instructions on installing this file, type
:help add-local-help :help add-local-help
Expand Down Expand Up @@ -70,6 +70,19 @@ David Fishburn
============================================================================== ==============================================================================
2. What's New *outlook-new* 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 Version 2.0


New Features 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 = 'C:\Documents and Settings\Username\My Documents\outlookvim.js'
let g:outlook_javascript = expand('$APPDATA\Microsoft\outlookvim.js') let g:outlook_javascript = expand('$APPDATA\Microsoft\outlookvim.js')
let g:outlook_javascript = expand('$USERPROFILE\Application Data\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 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: > 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 ' Macro Security settings and creating digit certificates
' http://www.pcreview.co.uk/forums/thread-854025.php ' http://www.pcreview.co.uk/forums/thread-854025.php
' '
' Version 2.0 ' Version 3.0


Option Explicit Option Explicit


Expand Down Expand Up @@ -67,7 +67,7 @@ Sub Edit()
' Const VIMLocation = "C:\Vim\vim72\gvim.exe" ' 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 Dim overwrite As Boolean, unicode As Boolean


' MsgBox ("Just starting LaunchVim") ' MsgBox ("Just starting LaunchVim")
Expand All @@ -91,7 +91,7 @@ Sub Edit()
If item.entryID = "" Then If item.entryID = "" Then
' If there is no EntryID, Vim will not be able to update ' If there is no EntryID, Vim will not be able to update
' the email during the save. ' 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. ' and allow Vim to edit the contents.
item.Save item.Save
If Err.Number <> 0 Then If Err.Number <> 0 Then
Expand All @@ -102,6 +102,37 @@ Sub Edit()
End If End If
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 fso = CreateObject("Scripting.FileSystemObject")
Set tfolder = fso.GetSpecialFolder(TemporaryFolder) Set tfolder = fso.GetSpecialFolder(TemporaryFolder)
tname = fso.GetTempName tname = fso.GetTempName
Expand All @@ -126,9 +157,9 @@ Sub Edit()
If Err.Number <> 0 Then If Err.Number <> 0 Then
' Clear Err object fields. ' Clear Err object fields.
' Err.Clear ' 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 tfile.Close
fso.DeleteFile (tfolder.ShortPath & "\" & tname & "\" & tname) fso.DeleteFile (tfolder.ShortPath & "\\" & tname)
' Quit will close Outlook ' Quit will close Outlook
' Quit ' Quit
Exit Sub Exit Sub
Expand All @@ -152,30 +183,24 @@ Sub Edit()
If Err.Number <> 0 Then If Err.Number <> 0 Then
' Clear Err object fields. ' Clear Err object fields.
' Err.Clear ' 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 cfile.Close
fso.DeleteFile (tfolder.ShortPath & "\" & tname & "\" & tname) fso.DeleteFile (tfolder.ShortPath & "\\" & tname)
fso.DeleteFile (tfolder.ShortPath & "\" & tname & "\" & tname & ".ctl") fso.DeleteFile (tfolder.ShortPath & "\\" & tname & ".ctl")
' Quit will close Outlook ' Quit will close Outlook
' Quit ' Quit
Exit Sub Exit Sub
End If End If
cfile.Close cfile.Close
' MsgBox ("id:" & item.EntryID) ' MsgBox ("id:" & item.EntryID)
' MsgBox tfolder.ShortPath & "\" & tname ' MsgBox tfolder.ShortPath & "\\" & tname



' Create an instance of Vim (if one does not already exist) vimKeys = ":call Outlook_EditFile( '" & tfolder.ShortPath & "\\" & tname & "', '"
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 "
If unicode Then If unicode Then
vimKeys = vimKeys & " ++enc=utf-16 " vimKeys = vimKeys & "utf-16"
End If End If
vimKeys = vimKeys & tfolder.ShortPath & "\" & tname & "<Enter>" vimKeys = vimKeys & "' )<Enter>"


' MsgBox (vimKeys) ' MsgBox (vimKeys)
' Use Vim's OLE feature to edit the email ' Use Vim's OLE feature to edit the email
Expand All @@ -185,18 +210,6 @@ Sub Edit()
' Force the Vim to the foreground ' Force the Vim to the foreground
Vim.SetForeground 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: Finished:
End Sub End Sub


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

ReturnValue = CloseHandle(proc.hProcess) ReturnValue = CloseHandle(proc.hProcess)


End Sub 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 " outlook.vim - Edit emails using Vim from Outlook
" --------------------------------------------------------------- " ---------------------------------------------------------------
" Version: 2.0 " Version: 3.0
" Authors: David Fishburn <dfishburn dot vim at gmail dot com> " Authors: David Fishburn <dfishburn dot vim at gmail dot com>
" Last Modified: 2010 May 06 " Last Modified: 2010 May 09
" Created: 2009 Jan 17 " Created: 2009 Jan 17
" Homepage: http://vim.sourceforge.net/script.php?script_id=??? " Homepage: http://vim.sourceforge.net/script.php?script_id=???
" Help: :h outlook.txt " Help: :h outlook.txt
Expand Down Expand Up @@ -41,15 +41,20 @@ else
let &textwidth = 76 let &textwidth = 76
endif 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) function! Outlook_WarningMsg(msg)
echohl WarningMsg echohl WarningMsg
echomsg a:msg echomsg "outlook: ".a:msg
echohl None echohl None
endfunction endfunction


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


Expand All @@ -67,23 +72,40 @@ function! Outlook_ExecuteJS(filename)
echomsg result echomsg result
endfunction 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 " Check is cscript.exe is already in the PATH
" Some path entries may end in a \ (c:\util\;), this must also be replaced " Some path entries may end in a \ (c:\util\;), this must also be replaced
" or globpath fails to parse the directories " or globpath fails to parse the directories
if strlen(globpath(substitute($PATH, '\\\?;', ',', 'g'), 'cscript.exe')) == 0 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 finish
endif endif


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

0 comments on commit 31df3dd

Please sign in to comment.