On 2013-10-02, 14:33 GMT, ZyX wrote:
> 1. Function s:GetRelVer does not give any error messages.
> 2. Yet it does nothing.
>
> Not sure whether this behavior is fine.

It shouldn't matter. s:GetRelVer() is called on line 97, i.e.,
after ver and rel should be set as best as we can set it without
using the Python library. So, if s:GetRelVer() does nothing, no
harm is done and we are not worse than we would be without using
the Python library.

> There is also a possible error:
>
>> +    specfile = vim.current.buffer.name
>> +    spec = rpm.spec(specfile)
>
> . How rpm.spec() behaves if specfile is None? This is unlikely 
> because `None` means buffer with no file name (which means to 
> get this ftplugin loaded one needs to explicitly do `:set 
> filetype=spec` or `:filetype spec`) and not saved to disk, but 
> possible.

Good point! I have covered whole the rest of the Python function 
with

    if specfile:
        ...

(see the refreshed version of the patch below; still also
available at http://luther.ceplovi.cz/git/vim.git, branch
spec_vim)

> Also from this patch I see that you are using `ver` and `rel` 
> in a function *different* from s:GetRelVer. But I do not see 
> you adding any assignments for `ver` and `rel`. In fact you 
> assign them in s:GetRelVer, but this function returns nothing. 
> Do you expect vim or python magically propagate these 
> variables to a separate scope? They will not. In fact new 
> function is not different from

They do, because s:GetRelVer() is called inside of 
s:SpecChangelog() function so they are local to that function.

Notice, that I have been using this modification for almost
a year, so I happily accept any reasonable corrections, but trust
me, at least the basic functionality really works.

Also, I have very briefly tested this patch with vim built
without Python and I haven't noticed any problems. It works as
badly as it does without the Python library.

Bram, what do you think?

Matěj

=================================================================
With the rising complexity of our spec files, I get more to the
situations when spec.vim is not able to parse the spec file
properly and doesn't generate verrel properly.

However, we have rpm-python library in Fedora, which should be
able to parse anything valid in any SPEC file. This patches
additional (optional, doesn't change anything in situation when
either the library or the python feature is not available)
functionality using the library for the additional parsing of the
spec file.

Signed-off-by: Matěj Cepl <[email protected]>
---
 runtime/ftplugin/spec.vim | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/runtime/ftplugin/spec.vim b/runtime/ftplugin/spec.vim
index 9778e1c..967da46 100644
--- a/runtime/ftplugin/spec.vim
+++ b/runtime/ftplugin/spec.vim
@@ -19,6 +19,31 @@ endif
 
 noremap <buffer> <unique> <script> <Plug>SpecChangelog :call 
<SID>SpecChangelog("")<CR>
 
+if !exists("*s:GetRelVer")
+    function! s:GetRelVer()
+        if has('python')
+python << PYEND
+import sys, datetime, shutil, tempfile
+import vim
+
+try:
+    import rpm
+except ImportError:
+    pass
+else:
+    specfile = vim.current.buffer.name
+    if specfile:
+        spec = rpm.spec(specfile)
+        headers = spec.packages[0].header
+        version = headers['Version']
+        release = ".".join(headers['Release'].split(".")[:-1])
+        vim.command("let ver = " + version)
+        vim.command("let rel = " + release)
+PYEND
+        endif
+    endfunction
+endif
+
 if !exists("*s:SpecChangelog")
        function s:SpecChangelog(format)
                if strlen(a:format) == 0
@@ -68,6 +93,9 @@ if !exists("*s:SpecChangelog")
                else
                        let include_release_info = 0
                endif
+
+        call s:GetRelVer()
+
                if (chgline == -1)
                        let option = confirm("Can't find %changelog. Create 
one? ","&End of file\n&Here\n&Cancel",3)
                        if (option == 1)
@@ -82,7 +110,7 @@ if !exists("*s:SpecChangelog")
                        endif
                endif
                if (chgline != -1)
-                       let parsed_format = "* ".strftime(format)
+                       let parsed_format = "* ".strftime(format)." - 
".ver."-".rel
                        let release_info = "+ ".name."-".ver."-".rel
                        let wrong_format = 0
                        let wrong_release = 0
-- 
1.8.4.474.g128a96c

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Raspunde prin e-mail lui