jceb / vim-orgmode

Text outlining and task management for Vim based on Emacs' Org-Mode
http://www.vim.org/scripts/script.php?script_id=3642
Other
3.13k stars 268 forks source link

TypeError in new_checkbox #179

Open geleynse opened 9 years ago

geleynse commented 9 years ago

new_checkbox is throwing a TypeError when run using the default <localleader>cn command:

  File "vim-orgmode/ftplugin/orgmode/plugins/EditCheckbox.py", line 116, in new_checkbox
    vim.current.buffer[start:start] = [unicode(nc)]
TypeError: bad argument type for built-in operation

toggle also appears not to work using the default <localleader>cc command, but there are no errors displayed.

powentan commented 9 years ago

Hi @Trano ,

Can you provide more details on how to reproduce this issue?

  1. OS
  2. Python version
  3. Reproduce steps (Please provide your working data if possible)
geleynse commented 9 years ago
  1. OS: OSX 10.9.5
  2. Python Version: 2.7.5
  3. Open a new org document. Insert a heading. Type <localleader>cn and observe the error given above.

I was able to reproduce the same error on an entirely new document.

jceb commented 9 years ago

On ArchLinux and Debian it works fine .. can't test with OSX. Anyone around who has a Mac?

powentan commented 9 years ago

Hi @Trano,

I got a Mac and had a try. It produced the same error as you said.

Please help verify the following change if you can:

  1. Open file: "vim-orgmode/ftplugin/orgmode/plugins/EditCheckbox.py"
  2. Replace line 116 from "vim.current.buffer[start:start] = [unicode(nc)]" to "vim.current.buffer[start:start] = [unicode(str(nc))]" (i.e. convert nc (new checkbox) to string explicitly)

It works on my Mac machine. If it works for you too, please tell me.

geleynse commented 9 years ago

@powentan, I tried the change that you suggested and continue to get the same error.

I also tested on a different machine and am getting the same issue on Ubuntu running Python 2.7.3. The suggested change does not fix the issue on either computer.

It seems like the problem is on the left hand side of the assignment. Changing line 116 to vim.current.buffer[start:start] = [unicode('test')] causes the same error message.

jceb commented 9 years ago

@Trano, would you post the output of the :version command, especially the vim version and the included patches? It might be that there is a specific bug in vim's python integration in the Mac version. Please also run the following command in a empty buffer:

:py import vim; vim.current.buffer[0] = 'some text on line 1'
:py import vim; vim.current.buffer[1:1] = ['some text on line 2']
:py import vim; vim.current.buffer[1:1] = ['some text on line 2 again', 'and on line 3']

It should place some text on the first 4 lines.

geleynse commented 9 years ago

I was running the tests asked as well as a few others and found a fix that works.

Instead of changing line 116 to vim.current.buffer[start:start] = [unicode(str(nc))] I changed it to vim.current.buffer[start:start] = [str(unicode(nc))] and that fixes the issue for both creating and toggling checkboxes.

This change fixes the issue on both my OSX and Ubuntu boxes that were having the issue.

jceb commented 9 years ago

Thanks, I still don't understand what goes wrong here. Would post the output of :echo &encoding? On my system I've :set encoding=utf-8.

geleynse commented 9 years ago

Encoding is utf-8 on both machines.

jceb commented 9 years ago

Okay, let's start over. First, please post your vim version on MacOS and Ubuntu (output of :version).

geleynse commented 9 years ago

Mac OSX:

VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Dec 19 2013 15:19:49) Compiled by root@apple.com Normal version without GUI. Features included (+) or not (-): -arabic +autocmd -balloon_eval -browse +builtin_terms +byte_offset +cindent -clientserver -clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments -conceal +cryptv +cscope +cursorbind +cursorshape +dialog_con +diff +digraphs -dnd -ebcdic -emacs_tags +eval +ex_extra +extra_search -farsi +file_in_path +find_in_path +float +folding -footer +fork() -gettext -hangul_input +iconv +insert_expand +jumplist -keymap -langmap +libcall +linebreak +lispindent +listcmds +localmap -lua +menu +mksession +modify_fname +mouse -mouseshape -mouse_dec -mouse_gpm -mouse_jsbterm -mouse_netterm -mouse_sysmouse +mouse_xterm +multi_byte +multi_lang -mzscheme +netbeans_intg -osfiletype +path_extra -perl +persistent_undo +postscript +printer -profile +python/dyn -python3 +quickfix +reltime -rightleft +ruby/dyn +scrollbind +signs +smartindent -sniff +startuptime +statusline -sun_workshop +syntax +tag_binary +tag_old_static -tag_any_white -tcl +terminfo +termresponse +textobjects +title -toolbar +user_commands +vertsplit +virtualedit +visual +visualextra +viminfo +vreplace +wildignore +wildmenu +windows +writebackup -X11 -xfontset -xim -xsmp -xterm_clipboard -xterm_save system vimrc file: "$VIM/vimrc" user vimrc file: "$HOME/.vimrc" user exrc file: "$HOME/.exrc" fall-back for $VIM: "/usr/share/vim" Compilation: gcc -c -I. -D_FORTIFY_SOURCE=0 -Iproto -DHAVE_CONFIG_H -arch i386 -arch x86_64 -g -Os -pipe Linking: gcc -arch i386 -arch x86_64 -o vim -lncurses

Ubuntu:

VIM - Vi IMproved 7.3 (2010 Aug 15, compiled May 4 2012 04:25:35) Included patches: 1-429 Modified by pkg-vim-maintainers@lists.alioth.debian.org Compiled by buildd@ Huge version without GUI. Features included (+) or not (-): +arabic +autocmd -balloon_eval -browse ++builtin_terms +byte_offset +cindent -clientserver -clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments +conceal +cryptv +cscope +cursorbind +cursorshape +dialog_con +diff +digraphs -dnd -ebcdic +emacs_tags +eval +ex_extra +extra_search +farsi +file_in_path +find_in_path +float +folding -footer +fork() +gettext -hangul_input +iconv +insert_expand +jumplist +keymap +langmap +libcall +linebreak +lispindent +listcmds +localmap -lua +menu +mksession +modify_fname +mouse -mouseshape +mouse_dec +mouse_gpm -mouse_jsbterm +mouse_netterm -mouse_sysmouse +mouse_xterm +mouse_urxvt +multi_byte +multi_lang -mzscheme +netbeans_intg +path_extra -perl +persistent_undo +postscript +printer +profile +python -python3 +quickfix +reltime +rightleft -ruby +scrollbind +signs +smartindent -sniff +startuptime +statusline -sun_workshop +syntax +tag_binary +tag_old_static -tag_any_white -tcl +terminfo +termresponse +textobjects +title -toolbar +user_commands +vertsplit +virtualedit +visual +visualextra +viminfo +vreplace +wildignore +wildmenu +windows +writebackup -X11 -xfontset -xim -xsmp -xterm_clipboard -xterm_save system vimrc file: "$VIM/vimrc" user vimrc file: "$HOME/.vimrc" user exrc file: "$HOME/.exrc" fall-back for $VIM: "/usr/share/vim" Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 Linking: gcc -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,--as-needed -o vim -lm -ltinfo -lnsl -lselinux -lacl -lattr -lgpm -ldl -L/usr/lib/python2.7/config -lpython2.7 -lpthread -ldl -lutil -lm -Xlinker -export-dynam ic -Wl,-O1 -Wl,-Bsymbolic-functions

jceb commented 9 years ago

Would you be able to try out vim 7.4 and see if the error remains?

smu commented 8 years ago

I experience the same issue on Debian wheezy with python 2.7.3. [str(unicode(nc))], however, does not solve the problem for me. Encoding is utf-8

Additionally, one test case fails:

$ ./run_tests.py 
..........................................................................................................................................E....................................................................................
======================================================================
ERROR: test_item_incrementz (test_plugin_edit_checkbox.EditCheckboxTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/muthers/.vim/bundle/vim-orgmode/tests/test_plugin_edit_checkbox.py", line 228, in test_item_incrementz
    self.assertEqual(vim.current.buffer[11], u"  aa. item")
IndexError: list index out of range

----------------------------------------------------------------------
Ran 223 tests in 0.655s

FAILED (errors=1)
luisfontes commented 8 years ago

Had this issue as well on OS X with vim 7.3. Upgrading to 7.4 solved it.