mirror of
https://github.com/Ascyii/vim-gnupg.git
synced 2026-01-01 14:24:25 -05:00
Write whole vim keywords
endi -> endif endw -> endwhile endf -> endfunction fun -> function com -> command
This commit is contained in:
184
plugin/gnupg.vim
184
plugin/gnupg.vim
@@ -73,7 +73,7 @@ endif
|
|||||||
|
|
||||||
if (exists("g:loaded_gnupg") || &cp || exists("#BufReadPre#*.\(gpg\|asc\|pgp\)"))
|
if (exists("g:loaded_gnupg") || &cp || exists("#BufReadPre#*.\(gpg\|asc\|pgp\)"))
|
||||||
finish
|
finish
|
||||||
endi
|
endif
|
||||||
|
|
||||||
let g:loaded_gnupg = "$Revision$"
|
let g:loaded_gnupg = "$Revision$"
|
||||||
|
|
||||||
@@ -85,7 +85,7 @@ augroup GnuPG
|
|||||||
autocmd BufNewFile,BufReadPre,FileReadPre *.\(gpg\|asc\|pgp\) call s:GPGInit()
|
autocmd BufNewFile,BufReadPre,FileReadPre *.\(gpg\|asc\|pgp\) call s:GPGInit()
|
||||||
" force the user to edit the recipient list if he opens a new file and public
|
" force the user to edit the recipient list if he opens a new file and public
|
||||||
" keys are preferred
|
" keys are preferred
|
||||||
autocmd BufNewFile *.\(gpg\|asc\|pgp\) if (exists("g:GPGPreferSymmetric") && g:GPGPreferSymmetric == 0) | call s:GPGEditRecipients() | endi
|
autocmd BufNewFile *.\(gpg\|asc\|pgp\) if (exists("g:GPGPreferSymmetric") && g:GPGPreferSymmetric == 0) | call s:GPGEditRecipients() | endif
|
||||||
" do the decryption
|
" do the decryption
|
||||||
autocmd BufReadPost,FileReadPost *.\(gpg\|asc\|pgp\) call s:GPGDecrypt()
|
autocmd BufReadPost,FileReadPost *.\(gpg\|asc\|pgp\) call s:GPGDecrypt()
|
||||||
|
|
||||||
@@ -106,7 +106,7 @@ highlight default link GPGHighlightUnknownRecipient ErrorMsg
|
|||||||
"
|
"
|
||||||
" initialize the plugin
|
" initialize the plugin
|
||||||
"
|
"
|
||||||
fun s:GPGInit()
|
function s:GPGInit()
|
||||||
" first make sure nothing is written to ~/.viminfo while editing
|
" first make sure nothing is written to ~/.viminfo while editing
|
||||||
" an encrypted file.
|
" an encrypted file.
|
||||||
set viminfo=
|
set viminfo=
|
||||||
@@ -180,7 +180,7 @@ fun s:GPGInit()
|
|||||||
let s:shell = 'sh'
|
let s:shell = 'sh'
|
||||||
let s:stderrredirnull ='2>/dev/null'
|
let s:stderrredirnull ='2>/dev/null'
|
||||||
let s:GPGCommand="LANG=C LC_ALL=C " . s:GPGCommand
|
let s:GPGCommand="LANG=C LC_ALL=C " . s:GPGCommand
|
||||||
endi
|
endif
|
||||||
|
|
||||||
" find the supported algorithms
|
" find the supported algorithms
|
||||||
let &shellredir=s:shellredir
|
let &shellredir=s:shellredir
|
||||||
@@ -193,13 +193,13 @@ fun s:GPGInit()
|
|||||||
let s:GPGCipher=substitute(output, ".*Cipher: \\(.\\{-}\\)\n.*", "\\1", "")
|
let s:GPGCipher=substitute(output, ".*Cipher: \\(.\\{-}\\)\n.*", "\\1", "")
|
||||||
let s:GPGHash=substitute(output, ".*Hash: \\(.\\{-}\\)\n.*", "\\1", "")
|
let s:GPGHash=substitute(output, ".*Hash: \\(.\\{-}\\)\n.*", "\\1", "")
|
||||||
let s:GPGCompress=substitute(output, ".*Compress: \\(.\\{-}\\)\n.*", "\\1", "")
|
let s:GPGCompress=substitute(output, ".*Compress: \\(.\\{-}\\)\n.*", "\\1", "")
|
||||||
endf
|
endfunction
|
||||||
|
|
||||||
" Function: s:GPGDecrypt() {{{2
|
" Function: s:GPGDecrypt() {{{2
|
||||||
"
|
"
|
||||||
" decrypt the buffer and find all recipients of the encrypted file
|
" decrypt the buffer and find all recipients of the encrypted file
|
||||||
"
|
"
|
||||||
fun s:GPGDecrypt()
|
function s:GPGDecrypt()
|
||||||
" switch to binary mode to read the encrypted file
|
" switch to binary mode to read the encrypted file
|
||||||
set bin
|
set bin
|
||||||
|
|
||||||
@@ -238,7 +238,7 @@ fun s:GPGDecrypt()
|
|||||||
echom "The cipher " . cipher . " is not known by the local gpg command. Using default!"
|
echom "The cipher " . cipher . " is not known by the local gpg command. Using default!"
|
||||||
echo
|
echo
|
||||||
echohl None
|
echohl None
|
||||||
endi
|
endif
|
||||||
elseif (match(output, "gpg: public key is [[:xdigit:]]\\{8}") >= 0)
|
elseif (match(output, "gpg: public key is [[:xdigit:]]\\{8}") >= 0)
|
||||||
" file is asymmetric encrypted
|
" file is asymmetric encrypted
|
||||||
let b:GPGEncrypted=1
|
let b:GPGEncrypted=1
|
||||||
@@ -262,7 +262,7 @@ fun s:GPGDecrypt()
|
|||||||
echohl None
|
echohl None
|
||||||
end
|
end
|
||||||
let start=match(output, "gpg: public key is [[:xdigit:]]\\{8}", start)
|
let start=match(output, "gpg: public key is [[:xdigit:]]\\{8}", start)
|
||||||
endw
|
endwhile
|
||||||
else
|
else
|
||||||
" file is not encrypted
|
" file is not encrypted
|
||||||
let b:GPGEncrypted=0
|
let b:GPGEncrypted=0
|
||||||
@@ -272,13 +272,13 @@ fun s:GPGDecrypt()
|
|||||||
echohl None
|
echohl None
|
||||||
set nobin
|
set nobin
|
||||||
return
|
return
|
||||||
endi
|
endif
|
||||||
|
|
||||||
" check if the message is armored
|
" check if the message is armored
|
||||||
if (match(output, "gpg: armor header") >= 0)
|
if (match(output, "gpg: armor header") >= 0)
|
||||||
call s:GPGDebug(1, "this file is armored")
|
call s:GPGDebug(1, "this file is armored")
|
||||||
let b:GPGOptions+=["armor"]
|
let b:GPGOptions+=["armor"]
|
||||||
endi
|
endif
|
||||||
|
|
||||||
" finally decrypt the buffer content
|
" finally decrypt the buffer content
|
||||||
" since even with the --quiet option passphrase typos will be reported,
|
" since even with the --quiet option passphrase typos will be reported,
|
||||||
@@ -296,7 +296,7 @@ fun s:GPGDecrypt()
|
|||||||
bwipeout
|
bwipeout
|
||||||
set nobin
|
set nobin
|
||||||
return
|
return
|
||||||
endi
|
endif
|
||||||
|
|
||||||
" turn off binary mode
|
" turn off binary mode
|
||||||
set nobin
|
set nobin
|
||||||
@@ -307,13 +307,13 @@ fun s:GPGDecrypt()
|
|||||||
|
|
||||||
" refresh screen
|
" refresh screen
|
||||||
redraw!
|
redraw!
|
||||||
endf
|
endfunction
|
||||||
|
|
||||||
" Function: s:GPGEncrypt() {{{2
|
" Function: s:GPGEncrypt() {{{2
|
||||||
"
|
"
|
||||||
" encrypts the buffer to all previous recipients
|
" encrypts the buffer to all previous recipients
|
||||||
"
|
"
|
||||||
fun s:GPGEncrypt()
|
function s:GPGEncrypt()
|
||||||
" save window view
|
" save window view
|
||||||
let s:GPGWindowView = winsaveview()
|
let s:GPGWindowView = winsaveview()
|
||||||
call s:GPGDebug(2, "saved window view " . string(s:GPGWindowView))
|
call s:GPGDebug(2, "saved window view " . string(s:GPGWindowView))
|
||||||
@@ -326,7 +326,7 @@ fun s:GPGEncrypt()
|
|||||||
else
|
else
|
||||||
let s:GPGEncoding = ""
|
let s:GPGEncoding = ""
|
||||||
call s:GPGDebug(2, "encoding and fileencoding are the same (\"" . &encoding . "\"), not switching")
|
call s:GPGDebug(2, "encoding and fileencoding are the same (\"" . &encoding . "\"), not switching")
|
||||||
endi
|
endif
|
||||||
|
|
||||||
" switch buffer to binary mode
|
" switch buffer to binary mode
|
||||||
set bin
|
set bin
|
||||||
@@ -337,7 +337,7 @@ fun s:GPGEncrypt()
|
|||||||
echom "File is not encrypted, all GPG functions disabled!"
|
echom "File is not encrypted, all GPG functions disabled!"
|
||||||
echohl None
|
echohl None
|
||||||
return
|
return
|
||||||
endi
|
endif
|
||||||
|
|
||||||
let options=""
|
let options=""
|
||||||
let recipients=""
|
let recipients=""
|
||||||
@@ -350,12 +350,12 @@ fun s:GPGEncrypt()
|
|||||||
let b:GPGOptions+=["symmetric"]
|
let b:GPGOptions+=["symmetric"]
|
||||||
else
|
else
|
||||||
let b:GPGOptions+=["encrypt"]
|
let b:GPGOptions+=["encrypt"]
|
||||||
endi
|
endif
|
||||||
if (exists("g:GPGPreferArmor") && g:GPGPreferArmor == 1)
|
if (exists("g:GPGPreferArmor") && g:GPGPreferArmor == 1)
|
||||||
let b:GPGOptions+=["armor"]
|
let b:GPGOptions+=["armor"]
|
||||||
endi
|
endif
|
||||||
call s:GPGDebug(1, "no options set, so using default options: " . string(b:GPGOptions))
|
call s:GPGDebug(1, "no options set, so using default options: " . string(b:GPGOptions))
|
||||||
endi
|
endif
|
||||||
for option in b:GPGOptions
|
for option in b:GPGOptions
|
||||||
let options=options . " --" . option . " "
|
let options=options . " --" . option . " "
|
||||||
endfor
|
endfor
|
||||||
@@ -372,8 +372,8 @@ fun s:GPGEncrypt()
|
|||||||
echohl GPGWarning
|
echohl GPGWarning
|
||||||
echom "The recipient " . cur_recipient . " is not in your public keyring!"
|
echom "The recipient " . cur_recipient . " is not in your public keyring!"
|
||||||
echohl None
|
echohl None
|
||||||
endi
|
endif
|
||||||
endi
|
endif
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
" check if there are unknown recipients and warn
|
" check if there are unknown recipients and warn
|
||||||
@@ -394,12 +394,12 @@ fun s:GPGEncrypt()
|
|||||||
echom "Removing ". b:GPGRecipients[index] ." from recipientlist!\n"
|
echom "Removing ". b:GPGRecipients[index] ." from recipientlist!\n"
|
||||||
echohl None
|
echohl None
|
||||||
call remove(b:GPGRecipients, index)
|
call remove(b:GPGRecipients, index)
|
||||||
endi
|
endif
|
||||||
endw
|
endwhile
|
||||||
|
|
||||||
" Let user know whats happend and copy known_recipients back to buffer
|
" Let user know whats happend and copy known_recipients back to buffer
|
||||||
let dummy=input("Press ENTER to quit")
|
let dummy=input("Press ENTER to quit")
|
||||||
endi
|
endif
|
||||||
|
|
||||||
" built list of recipients
|
" built list of recipients
|
||||||
if (exists("b:GPGRecipients") && len(b:GPGRecipients) > 0)
|
if (exists("b:GPGRecipients") && len(b:GPGRecipients) > 0)
|
||||||
@@ -414,8 +414,8 @@ fun s:GPGEncrypt()
|
|||||||
echom "Please use GPGEditRecipients to correct!!"
|
echom "Please use GPGEditRecipients to correct!!"
|
||||||
echo
|
echo
|
||||||
echohl None
|
echohl None
|
||||||
endi
|
endif
|
||||||
endi
|
endif
|
||||||
|
|
||||||
" encrypt the buffer
|
" encrypt the buffer
|
||||||
let &shellredir=s:shellredir
|
let &shellredir=s:shellredir
|
||||||
@@ -431,19 +431,19 @@ fun s:GPGEncrypt()
|
|||||||
echohl None
|
echohl None
|
||||||
bwipeout
|
bwipeout
|
||||||
return
|
return
|
||||||
endi
|
endif
|
||||||
|
|
||||||
endf
|
endfunction
|
||||||
|
|
||||||
" Function: s:GPGEncryptPost() {{{2
|
" Function: s:GPGEncryptPost() {{{2
|
||||||
"
|
"
|
||||||
" undo changes don by encrypt, after writing
|
" undo changes don by encrypt, after writing
|
||||||
"
|
"
|
||||||
fun s:GPGEncryptPost()
|
function s:GPGEncryptPost()
|
||||||
|
|
||||||
if (exists("b:GPGEncrypted") && b:GPGEncrypted == 0)
|
if (exists("b:GPGEncrypted") && b:GPGEncrypted == 0)
|
||||||
return
|
return
|
||||||
endi
|
endif
|
||||||
|
|
||||||
" undo encryption of buffer content
|
" undo encryption of buffer content
|
||||||
silent u
|
silent u
|
||||||
@@ -455,7 +455,7 @@ fun s:GPGEncryptPost()
|
|||||||
if s:GPGEncoding != ""
|
if s:GPGEncoding != ""
|
||||||
let &encoding = s:GPGEncoding
|
let &encoding = s:GPGEncoding
|
||||||
call s:GPGDebug(2, "restored encoding \"" . &encoding . "\"")
|
call s:GPGDebug(2, "restored encoding \"" . &encoding . "\"")
|
||||||
endi
|
endif
|
||||||
|
|
||||||
" restore window view
|
" restore window view
|
||||||
call winrestview(s:GPGWindowView)
|
call winrestview(s:GPGWindowView)
|
||||||
@@ -463,20 +463,20 @@ fun s:GPGEncryptPost()
|
|||||||
|
|
||||||
" refresh screen
|
" refresh screen
|
||||||
redraw!
|
redraw!
|
||||||
endf
|
endfunction
|
||||||
|
|
||||||
" Function: s:GPGViewRecipients() {{{2
|
" Function: s:GPGViewRecipients() {{{2
|
||||||
"
|
"
|
||||||
" echo the recipients
|
" echo the recipients
|
||||||
"
|
"
|
||||||
fun s:GPGViewRecipients()
|
function s:GPGViewRecipients()
|
||||||
" guard for unencrypted files
|
" guard for unencrypted files
|
||||||
if (exists("b:GPGEncrypted") && b:GPGEncrypted == 0)
|
if (exists("b:GPGEncrypted") && b:GPGEncrypted == 0)
|
||||||
echohl GPGWarning
|
echohl GPGWarning
|
||||||
echom "File is not encrypted, all GPG functions disabled!"
|
echom "File is not encrypted, all GPG functions disabled!"
|
||||||
echohl None
|
echohl None
|
||||||
return
|
return
|
||||||
endi
|
endif
|
||||||
|
|
||||||
if (exists("b:GPGRecipients"))
|
if (exists("b:GPGRecipients"))
|
||||||
echo 'This file has following recipients (Unknown recipients have a prepended "!"):'
|
echo 'This file has following recipients (Unknown recipients have a prepended "!"):'
|
||||||
@@ -499,22 +499,22 @@ fun s:GPGViewRecipients()
|
|||||||
echohl GPGError
|
echohl GPGError
|
||||||
echom 'There are no known recipients!'
|
echom 'There are no known recipients!'
|
||||||
echohl None
|
echohl None
|
||||||
endi
|
endif
|
||||||
endi
|
endif
|
||||||
endf
|
endfunction
|
||||||
|
|
||||||
" Function: s:GPGEditRecipients() {{{2
|
" Function: s:GPGEditRecipients() {{{2
|
||||||
"
|
"
|
||||||
" create a scratch buffer with all recipients to add/remove recipients
|
" create a scratch buffer with all recipients to add/remove recipients
|
||||||
"
|
"
|
||||||
fun s:GPGEditRecipients()
|
function s:GPGEditRecipients()
|
||||||
" guard for unencrypted files
|
" guard for unencrypted files
|
||||||
if (exists("b:GPGEncrypted") && b:GPGEncrypted == 0)
|
if (exists("b:GPGEncrypted") && b:GPGEncrypted == 0)
|
||||||
echohl GPGWarning
|
echohl GPGWarning
|
||||||
echom "File is not encrypted, all GPG functions disabled!"
|
echom "File is not encrypted, all GPG functions disabled!"
|
||||||
echohl None
|
echohl None
|
||||||
return
|
return
|
||||||
endi
|
endif
|
||||||
|
|
||||||
" only do this if it isn't already a GPGRecipients_* buffer
|
" only do this if it isn't already a GPGRecipients_* buffer
|
||||||
if (match(bufname("%"), "^\\(GPGRecipients_\\|GPGOptions_\\)") != 0 && match(bufname("%"), "\.\\(gpg\\|asc\\|pgp\\)$") >= 0)
|
if (match(bufname("%"), "^\\(GPGRecipients_\\|GPGOptions_\\)") != 0 && match(bufname("%"), "\.\\(gpg\\|asc\\|pgp\\)$") >= 0)
|
||||||
@@ -540,11 +540,11 @@ fun s:GPGEditRecipients()
|
|||||||
|
|
||||||
" add a autocommand to regenerate the recipients after a write
|
" add a autocommand to regenerate the recipients after a write
|
||||||
autocmd BufHidden,BufUnload,BufWriteCmd <buffer> call s:GPGFinishRecipientsBuffer()
|
autocmd BufHidden,BufUnload,BufWriteCmd <buffer> call s:GPGFinishRecipientsBuffer()
|
||||||
endi
|
endif
|
||||||
|
|
||||||
" empty the buffer
|
" empty the buffer
|
||||||
silent normal! 1GdG
|
silent normal! 1GdG
|
||||||
endi
|
endif
|
||||||
|
|
||||||
" Mark the buffer as a scratch buffer
|
" Mark the buffer as a scratch buffer
|
||||||
setlocal buftype=acwrite
|
setlocal buftype=acwrite
|
||||||
@@ -593,7 +593,7 @@ fun s:GPGEditRecipients()
|
|||||||
syntax match GPGComment "^GPG:.*$"
|
syntax match GPGComment "^GPG:.*$"
|
||||||
highlight clear GPGComment
|
highlight clear GPGComment
|
||||||
highlight link GPGComment Comment
|
highlight link GPGComment Comment
|
||||||
endi
|
endif
|
||||||
|
|
||||||
" delete the empty first line
|
" delete the empty first line
|
||||||
silent normal! 1Gdd
|
silent normal! 1Gdd
|
||||||
@@ -601,26 +601,26 @@ fun s:GPGEditRecipients()
|
|||||||
" jump to the first recipient
|
" jump to the first recipient
|
||||||
silent normal! G
|
silent normal! G
|
||||||
|
|
||||||
endi
|
endif
|
||||||
endf
|
endfunction
|
||||||
|
|
||||||
" Function: s:GPGFinishRecipientsBuffer() {{{2
|
" Function: s:GPGFinishRecipientsBuffer() {{{2
|
||||||
"
|
"
|
||||||
" create a new recipient list from RecipientsBuffer
|
" create a new recipient list from RecipientsBuffer
|
||||||
fun s:GPGFinishRecipientsBuffer()
|
function s:GPGFinishRecipientsBuffer()
|
||||||
" guard for unencrypted files
|
" guard for unencrypted files
|
||||||
if (exists("b:GPGEncrypted") && b:GPGEncrypted == 0)
|
if (exists("b:GPGEncrypted") && b:GPGEncrypted == 0)
|
||||||
echohl GPGWarning
|
echohl GPGWarning
|
||||||
echom "File is not encrypted, all GPG functions disabled!"
|
echom "File is not encrypted, all GPG functions disabled!"
|
||||||
echohl None
|
echohl None
|
||||||
return
|
return
|
||||||
endi
|
endif
|
||||||
|
|
||||||
" go to buffer before doing work
|
" go to buffer before doing work
|
||||||
if (bufnr("%") != expand("<abuf>"))
|
if (bufnr("%") != expand("<abuf>"))
|
||||||
" switch to scratch buffer window
|
" switch to scratch buffer window
|
||||||
exe 'silent! ' . bufwinnr(expand("<afile>")) . "wincmd w"
|
exe 'silent! ' . bufwinnr(expand("<afile>")) . "wincmd w"
|
||||||
endi
|
endif
|
||||||
|
|
||||||
" clear GPGRecipients and GPGUnknownRecipients
|
" clear GPGRecipients and GPGUnknownRecipients
|
||||||
let GPGRecipients=[]
|
let GPGRecipients=[]
|
||||||
@@ -646,20 +646,20 @@ fun s:GPGFinishRecipientsBuffer()
|
|||||||
if (strlen(gpgid) > 0)
|
if (strlen(gpgid) > 0)
|
||||||
if (match(GPGRecipients, gpgid) < 0)
|
if (match(GPGRecipients, gpgid) < 0)
|
||||||
let GPGRecipients+=[gpgid]
|
let GPGRecipients+=[gpgid]
|
||||||
endi
|
endif
|
||||||
else
|
else
|
||||||
if (match(GPGUnknownRecipients, recipient) < 0)
|
if (match(GPGUnknownRecipients, recipient) < 0)
|
||||||
let GPGUnknownRecipients+=[recipient]
|
let GPGUnknownRecipients+=[recipient]
|
||||||
echohl GPGWarning
|
echohl GPGWarning
|
||||||
echom "The recipient " . recipient . " is not in your public keyring!"
|
echom "The recipient " . recipient . " is not in your public keyring!"
|
||||||
echohl None
|
echohl None
|
||||||
endi
|
endif
|
||||||
end
|
end
|
||||||
endi
|
endif
|
||||||
|
|
||||||
let currentline=currentline+1
|
let currentline=currentline+1
|
||||||
let recipient=getline(currentline)
|
let recipient=getline(currentline)
|
||||||
endw
|
endwhile
|
||||||
|
|
||||||
" write back the new recipient list to the corresponding buffer and mark it
|
" write back the new recipient list to the corresponding buffer and mark it
|
||||||
" as modified. Buffer is now for sure a encrypted buffer.
|
" as modified. Buffer is now for sure a encrypted buffer.
|
||||||
@@ -673,24 +673,24 @@ fun s:GPGFinishRecipientsBuffer()
|
|||||||
echohl GPGError
|
echohl GPGError
|
||||||
echom 'There are no known recipients!'
|
echom 'There are no known recipients!'
|
||||||
echohl None
|
echohl None
|
||||||
endi
|
endif
|
||||||
|
|
||||||
" reset modified flag
|
" reset modified flag
|
||||||
set nomodified
|
set nomodified
|
||||||
endf
|
endfunction
|
||||||
|
|
||||||
" Function: s:GPGViewOptions() {{{2
|
" Function: s:GPGViewOptions() {{{2
|
||||||
"
|
"
|
||||||
" echo the recipients
|
" echo the recipients
|
||||||
"
|
"
|
||||||
fun s:GPGViewOptions()
|
function s:GPGViewOptions()
|
||||||
" guard for unencrypted files
|
" guard for unencrypted files
|
||||||
if (exists("b:GPGEncrypted") && b:GPGEncrypted == 0)
|
if (exists("b:GPGEncrypted") && b:GPGEncrypted == 0)
|
||||||
echohl GPGWarning
|
echohl GPGWarning
|
||||||
echom "File is not encrypted, all GPG functions disabled!"
|
echom "File is not encrypted, all GPG functions disabled!"
|
||||||
echohl None
|
echohl None
|
||||||
return
|
return
|
||||||
endi
|
endif
|
||||||
|
|
||||||
if (exists("b:GPGOptions"))
|
if (exists("b:GPGOptions"))
|
||||||
echo 'This file has following options:'
|
echo 'This file has following options:'
|
||||||
@@ -698,21 +698,21 @@ fun s:GPGViewOptions()
|
|||||||
for option in b:GPGOptions
|
for option in b:GPGOptions
|
||||||
echo option
|
echo option
|
||||||
endfor
|
endfor
|
||||||
endi
|
endif
|
||||||
endf
|
endfunction
|
||||||
|
|
||||||
" Function: s:GPGEditOptions() {{{2
|
" Function: s:GPGEditOptions() {{{2
|
||||||
"
|
"
|
||||||
" create a scratch buffer with all recipients to add/remove recipients
|
" create a scratch buffer with all recipients to add/remove recipients
|
||||||
"
|
"
|
||||||
fun s:GPGEditOptions()
|
function s:GPGEditOptions()
|
||||||
" guard for unencrypted files
|
" guard for unencrypted files
|
||||||
if (exists("b:GPGEncrypted") && b:GPGEncrypted == 0)
|
if (exists("b:GPGEncrypted") && b:GPGEncrypted == 0)
|
||||||
echohl GPGWarning
|
echohl GPGWarning
|
||||||
echom "File is not encrypted, all GPG functions disabled!"
|
echom "File is not encrypted, all GPG functions disabled!"
|
||||||
echohl None
|
echohl None
|
||||||
return
|
return
|
||||||
endi
|
endif
|
||||||
|
|
||||||
" only do this if it isn't already a GPGOptions_* buffer
|
" only do this if it isn't already a GPGOptions_* buffer
|
||||||
if (match(bufname("%"), "^\\(GPGRecipients_\\|GPGOptions_\\)") != 0 && match(bufname("%"), "\.\\(gpg\\|asc\\|pgp\\)$") >= 0)
|
if (match(bufname("%"), "^\\(GPGRecipients_\\|GPGOptions_\\)") != 0 && match(bufname("%"), "\.\\(gpg\\|asc\\|pgp\\)$") >= 0)
|
||||||
@@ -738,11 +738,11 @@ fun s:GPGEditOptions()
|
|||||||
|
|
||||||
" add a autocommand to regenerate the options after a write
|
" add a autocommand to regenerate the options after a write
|
||||||
autocmd BufHidden,BufUnload,BufWriteCmd <buffer> call s:GPGFinishOptionsBuffer()
|
autocmd BufHidden,BufUnload,BufWriteCmd <buffer> call s:GPGFinishOptionsBuffer()
|
||||||
endi
|
endif
|
||||||
|
|
||||||
" empty the buffer
|
" empty the buffer
|
||||||
silent normal! 1GdG
|
silent normal! 1GdG
|
||||||
endi
|
endif
|
||||||
|
|
||||||
" Mark the buffer as a scratch buffer
|
" Mark the buffer as a scratch buffer
|
||||||
setlocal buftype=nofile
|
setlocal buftype=nofile
|
||||||
@@ -783,27 +783,27 @@ fun s:GPGEditOptions()
|
|||||||
syntax match GPGComment "^GPG:.*$"
|
syntax match GPGComment "^GPG:.*$"
|
||||||
highlight clear GPGComment
|
highlight clear GPGComment
|
||||||
highlight link GPGComment Comment
|
highlight link GPGComment Comment
|
||||||
endi
|
endif
|
||||||
endi
|
endif
|
||||||
endf
|
endfunction
|
||||||
|
|
||||||
" Function: s:GPGFinishOptionsBuffer() {{{2
|
" Function: s:GPGFinishOptionsBuffer() {{{2
|
||||||
"
|
"
|
||||||
" create a new option list from OptionsBuffer
|
" create a new option list from OptionsBuffer
|
||||||
fun s:GPGFinishOptionsBuffer()
|
function s:GPGFinishOptionsBuffer()
|
||||||
" guard for unencrypted files
|
" guard for unencrypted files
|
||||||
if (exists("b:GPGEncrypted") && b:GPGEncrypted == 0)
|
if (exists("b:GPGEncrypted") && b:GPGEncrypted == 0)
|
||||||
echohl GPGWarning
|
echohl GPGWarning
|
||||||
echom "File is not encrypted, all GPG functions disabled!"
|
echom "File is not encrypted, all GPG functions disabled!"
|
||||||
echohl None
|
echohl None
|
||||||
return
|
return
|
||||||
endi
|
endif
|
||||||
|
|
||||||
" go to buffer before doing work
|
" go to buffer before doing work
|
||||||
if (bufnr("%") != expand("<abuf>"))
|
if (bufnr("%") != expand("<abuf>"))
|
||||||
" switch to scratch buffer window
|
" switch to scratch buffer window
|
||||||
exe 'silent! ' . bufwinnr(expand("<afile>")) . "wincmd w"
|
exe 'silent! ' . bufwinnr(expand("<afile>")) . "wincmd w"
|
||||||
endi
|
endif
|
||||||
|
|
||||||
" clear GPGOptions and GPGUnknownOptions
|
" clear GPGOptions and GPGUnknownOptions
|
||||||
let GPGOptions=[]
|
let GPGOptions=[]
|
||||||
@@ -826,11 +826,11 @@ fun s:GPGFinishOptionsBuffer()
|
|||||||
" only do this if the line is not empty
|
" only do this if the line is not empty
|
||||||
if (strlen(option) > 0 && match(GPGOptions, option) < 0)
|
if (strlen(option) > 0 && match(GPGOptions, option) < 0)
|
||||||
let GPGOptions+=[option]
|
let GPGOptions+=[option]
|
||||||
endi
|
endif
|
||||||
|
|
||||||
let currentline=currentline+1
|
let currentline=currentline+1
|
||||||
let option=getline(currentline)
|
let option=getline(currentline)
|
||||||
endw
|
endwhile
|
||||||
|
|
||||||
" write back the new option list to the corresponding buffer and mark it
|
" write back the new option list to the corresponding buffer and mark it
|
||||||
" as modified
|
" as modified
|
||||||
@@ -839,13 +839,13 @@ fun s:GPGFinishOptionsBuffer()
|
|||||||
|
|
||||||
" reset modified flag
|
" reset modified flag
|
||||||
set nomodified
|
set nomodified
|
||||||
endf
|
endfunction
|
||||||
|
|
||||||
" Function: s:GPGNameToID(name) {{{2
|
" Function: s:GPGNameToID(name) {{{2
|
||||||
"
|
"
|
||||||
" find GPG key ID corresponding to a name
|
" find GPG key ID corresponding to a name
|
||||||
" Returns: ID for the given name
|
" Returns: ID for the given name
|
||||||
fun s:GPGNameToID(name)
|
function s:GPGNameToID(name)
|
||||||
" ask gpg for the id for a name
|
" ask gpg for the id for a name
|
||||||
let &shellredir=s:shellredir
|
let &shellredir=s:shellredir
|
||||||
let &shell=s:shell
|
let &shell=s:shell
|
||||||
@@ -857,7 +857,7 @@ fun s:GPGNameToID(name)
|
|||||||
" so convert it, if necessary
|
" so convert it, if necessary
|
||||||
if &encoding != "utf-8"
|
if &encoding != "utf-8"
|
||||||
let output=iconv(output, "utf-8", &encoding)
|
let output=iconv(output, "utf-8", &encoding)
|
||||||
endi
|
endif
|
||||||
let lines=split(output, "\n")
|
let lines=split(output, "\n")
|
||||||
|
|
||||||
" parse the output of gpg
|
" parse the output of gpg
|
||||||
@@ -877,20 +877,20 @@ fun s:GPGNameToID(name)
|
|||||||
let uid_seen=1
|
let uid_seen=1
|
||||||
else
|
else
|
||||||
let choices=choices . " " . fields[9] . "\n"
|
let choices=choices . " " . fields[9] . "\n"
|
||||||
endi
|
endif
|
||||||
else
|
else
|
||||||
let uid_seen=0
|
let uid_seen=0
|
||||||
let pub_seen=0
|
let pub_seen=0
|
||||||
endi
|
endif
|
||||||
endi
|
endif
|
||||||
|
|
||||||
" search for the next pub
|
" search for the next pub
|
||||||
if (pub_seen == 0)
|
if (pub_seen == 0)
|
||||||
if (fields[0] == "pub")
|
if (fields[0] == "pub")
|
||||||
let gpgids+=[fields[4]]
|
let gpgids+=[fields[4]]
|
||||||
let pub_seen=1
|
let pub_seen=1
|
||||||
endi
|
endif
|
||||||
endi
|
endif
|
||||||
|
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
@@ -901,17 +901,17 @@ fun s:GPGNameToID(name)
|
|||||||
let answer=input(choices, "0")
|
let answer=input(choices, "0")
|
||||||
while (answer == "")
|
while (answer == "")
|
||||||
let answer=input("Enter number: ", "0")
|
let answer=input("Enter number: ", "0")
|
||||||
endw
|
endwhile
|
||||||
endi
|
endif
|
||||||
|
|
||||||
return get(gpgids, answer, "")
|
return get(gpgids, answer, "")
|
||||||
endf
|
endfunction
|
||||||
|
|
||||||
" Function: s:GPGIDToName(identity) {{{2
|
" Function: s:GPGIDToName(identity) {{{2
|
||||||
"
|
"
|
||||||
" find name corresponding to a GPG key ID
|
" find name corresponding to a GPG key ID
|
||||||
" Returns: Name for the given ID
|
" Returns: Name for the given ID
|
||||||
fun s:GPGIDToName(identity)
|
function s:GPGIDToName(identity)
|
||||||
" TODO is the encryption subkey really unique?
|
" TODO is the encryption subkey really unique?
|
||||||
|
|
||||||
" ask gpg for the id for a name
|
" ask gpg for the id for a name
|
||||||
@@ -925,7 +925,7 @@ fun s:GPGIDToName(identity)
|
|||||||
" so convert it, if necessary
|
" so convert it, if necessary
|
||||||
if &encoding != "utf-8"
|
if &encoding != "utf-8"
|
||||||
let output=iconv(output, "utf-8", &encoding)
|
let output=iconv(output, "utf-8", &encoding)
|
||||||
endi
|
endif
|
||||||
let lines=split(output, "\n")
|
let lines=split(output, "\n")
|
||||||
|
|
||||||
" parse the output of gpg
|
" parse the output of gpg
|
||||||
@@ -936,32 +936,32 @@ fun s:GPGIDToName(identity)
|
|||||||
if (pub_seen == 0) " search for the next pub
|
if (pub_seen == 0) " search for the next pub
|
||||||
if (fields[0] == "pub")
|
if (fields[0] == "pub")
|
||||||
let pub_seen=1
|
let pub_seen=1
|
||||||
endi
|
endif
|
||||||
else " search for the next uid
|
else " search for the next uid
|
||||||
if (fields[0] == "uid")
|
if (fields[0] == "uid")
|
||||||
let pub_seen=0
|
let pub_seen=0
|
||||||
let uid=fields[9]
|
let uid=fields[9]
|
||||||
break
|
break
|
||||||
endi
|
endif
|
||||||
endi
|
endif
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
return uid
|
return uid
|
||||||
endf
|
endfunction
|
||||||
|
|
||||||
" Function: s:GPGDebug(level, text) {{{2
|
" Function: s:GPGDebug(level, text) {{{2
|
||||||
"
|
"
|
||||||
" output debug message, if this message has high enough importance
|
" output debug message, if this message has high enough importance
|
||||||
fun s:GPGDebug(level, text)
|
function s:GPGDebug(level, text)
|
||||||
if (g:GPGDebugLevel >= a:level)
|
if (g:GPGDebugLevel >= a:level)
|
||||||
echom a:text
|
echom a:text
|
||||||
endi
|
endif
|
||||||
endf
|
endfunction
|
||||||
|
|
||||||
" Section: Command definitions {{{1
|
" Section: Command definitions {{{1
|
||||||
com! GPGViewRecipients call s:GPGViewRecipients()
|
command! GPGViewRecipients call s:GPGViewRecipients()
|
||||||
com! GPGEditRecipients call s:GPGEditRecipients()
|
command! GPGEditRecipients call s:GPGEditRecipients()
|
||||||
com! GPGViewOptions call s:GPGViewOptions()
|
command! GPGViewOptions call s:GPGViewOptions()
|
||||||
com! GPGEditOptions call s:GPGEditOptions()
|
command! GPGEditOptions call s:GPGEditOptions()
|
||||||
|
|
||||||
" vim600: foldmethod=marker:foldlevel=0
|
" vim600: foldmethod=marker:foldlevel=0
|
||||||
|
|||||||
Reference in New Issue
Block a user