VIM python filetype specific indent fails after 50 lines of one list
I'm currently working on reformatting a python project to follow the 4 spaces indent style. The project is being done in VIM with the following plugins: fugitive, snipmate, surround, git, supertab, minibufexpl, command-t. pyflakes-pathogen, ack, gundo, pydoc, pep8, py.test, makegreen, tasklist, nerdtree, ropevim .
My .vimrc is currently:
set tabstop=4
set shiftwidth=4
set expandtab
let mapleader=","
filetype off
call pathogen#runtime_append_all_bundles()
call pathogen#helptags()
set foldmethod=indent
set foldlevel=99
map <leader>td <Plug>TaskList
map <leader>g :GundoToggle<CR>
syntax on
filetype on
filetype plugin indent on
let g:pyflakes_use_quickfix = 0
let g:pep8_map='<leader>8'
au FileType python set omnifunc=pythoncomplete#Complete
let g:SuperTabDefaultCompletionType = "context"
set completeopt=menuone,longest,preview
The project is not mine, and I would like to keep the code functionally untouched from the original.
The code consists of a few assignment operations. The left side of each is the variable name, the right side is a very, very long list with multiple nested lists.
If I attempted to utilize VIM's re-indent functionality "gg=G" or even "100==" from the start of the asignment, VIM will properly indent the first fifty lines of the right side of the asignment. However after the fiftieth line of the right side, VIM begins indenting the second level an additional four spaces.
animations = [
["stand", 0, amf_client_prediction,
# [3.0, "myanim", 0, 50, arf_cyclic|arf_loop_pos_0_25],
[3.0, "anim_human", 50, 52, arf_use_stand_progress|arf_cyclic, 0, (0, 0, 0), 0.25],
[3.0, "anim_human", 60, 62, arf_use_stand_progress|arf_cyclic, 0, (0, 0, 0), 0.75],
[3.0, "anim_human", 70, 72, arf_use_stand_progress|arf_cyclic, 0, (0, 0, 0), 0.25],
[3.0, "anim_human", 80, 82, arf_use_stand_progress|arf_cyclic|arf_two_handed_blade, 0, (0, 0, 0), 0.5],
## [35.0, "stand_woman", 0, 1059, arf_use_stand_progress|arf_cyclic|arf_two_handed_blade, 0, (0, 0, 0), 0.5],
## [43.0, "stand_woman_public", 0, 1313, arf_use_stand_progress|arf_cyclic|arf_two_handed_blade, 0, (0, 0, 0), 0.5],
# [35.0, "tavern_stand", 0, 472, arf_cyclic|arf_loop_pos_0_25],
],
["stand_man", 0, amf_client_prediction,
[11.0, "stand_man", 0, 315, arf_use_stand_progress|arf_cyclic, 0, (0, 0, 0), 0.25],
],
["stand_player_first_person", 0, amf_client_prediction,
[3.5, "anim_human", 90, 100, arf_use_stand_progress|arf_cyclic, 0, (0, 0, 0), 0.25],
[3.5, "anim_human", 110, 120, arf_use_stand_progress|arf_cyclic, 0, (0, 0, 0), 0.25],
],
["jump", acf_enforce_lowerbody, amf_priority_jump|amf_play|amf_client_prediction|amf_continue_to_next,
## [1.09, "jump", 22, 48, arf_blend_in_1],
[1.0, "jump", 22, 46, arf_blend_in_1],
## [0.8, "anim_human", 270, 272, arf_blend_in_4],
],
["jump_loop", acf_enforce_lowerbody, amf_priority_jump|amf_play|amf_client_prediction,
## [0.8, "jump_loop", 0, 30, arf_blend_in_2|arf_cyclic],
[0.5, "jump_loop", 0, 14, arf_blend_in_3|arf_cyclic],
],
["jump_end", acf_enforce_lowerbody, amf_priority_jump_end|amf_play|amf_client_prediction,
## [0.1, "jump", 48, 55, arf_blend_in_1],
[0.3, "jump", 48, 55, arf_blend_in_2],
],
["jump_end_hard", acf_enforce_lowerbody, amf_priority_jump_end|amf_play|amf_client_prediction,
## [0.8, "jump_end_hard", 29, 54, arf_blend_in_1],
[0.6, "jump_end_hard", 36, 54, arf_blend_in_1],
],
["stand_unarmed", 0, amf_client_prediction,
[8, "noweapon_cstance", 0, 100, arf_use_stand_progress|arf_cyclic, 0, (0, 0, 0), 0.25],
],
["stand_single", 0, amf_client_prediction,
[9.0, "sword_loop01", 0, 200, arf_use_stand_progress|arf_cyclic, 0, (0, 0, 0), 0.25],
],
["stand_greatsword", 0, amf_client_prediction,
[6.0, "greatsword_cstance", 0, 91, arf_use_stand_progress|arf_cyclic, 0, (0, 0, 0), 0.25],
],
["stand_staff", 0, amf_client_prediction,
[2.0, "staff_cstance", 0, 60, arf_use_stand_progress|arf_cyclic, 0, (0, 0, 0), 0.0],
],
["stand_crossbow", 0, amf_client_prediction,
[2.0, "staff_cstance", 0, 60, arf_use_stand_progress|arf_cyclic, 0, (0, 0, 0), 0.0],
],
["turn_right", acf_enforce_lowerbody, amf_play|amf_client_prediction,
[0.95, "stand_man", 0, 30, arf_use_stand_progress|arf_cyclic, 0, (0, 0, 0), 0.25], #TODO
],
["turn_left", acf_enforce_lowerbody, amf_play|amf_client_prediction,
[0.95, "stand_man", 0, 30, arf_use_stand_progress|arf_cyclic, 0, (0, 0, 0), 0.25], #TODO
],
["turn_right_single", acf_enforce_lowerbody, amf_play|amf_client_prediction,
[0.95, "turn_man_onehanded", 0, 23, arf_cyclic|blend_in_walk|arf_make_walk_sound,pack2f(0.4,0.9), (0, 0, 0), 0.0],
],
["turn_left_single", acf_enforce_lowerbody, amf_play|amf_client_prediction,
[0.95, "turn_man_onehanded", 30, 53, arf_cyclic|blend_in_walk|arf_make_walk_sound,pack2f(0.4,0.9), (0, 0, 0), 0.0],
],
["turn_right_staff", acf_enforce_lowerbody, amf_play|amf_client_prediction,
[0.95, "turn_man_staff", 0, 20, arf_cyclic|blend_in_walk|arf_make_walk_sound,pack2f(0.4,0.9), (0, 0, 0), 0.0],
],
["turn_left_staff", acf_enforce_lowerbody, amf_play|amf_client_prediction,
[0.95, "turn_man_staff", 30, 50, arf_cyclic|blend_in_walk|arf_make_walk_sound,pack2f(0.4,0.9), (0, 0, 0), 0.0],
],
["turn_right_greatsword", acf_enforce_lowerbody, amf_play|amf_client_prediction,
[0.95, "turn_man_greatsword", 0, 20, arf_cyclic|blend_in_walk|arf_make_walk_sound,pack2f(0.4,0.9), (0, 0, 0), 0.0],
],
["turn_left_greatsword", acf_enforce_lowerbody, amf_play|amf_client_prediction,
[0.95, "turn_man_greatsword", 30, 50, arf_cyclic|blend_in_walk|arf_make_walk_sound,pack2f(0.4,0.9), (0, 0, 0), 0.0],
],
["prepare_kick_0", acf_enforce_lowerbody, amf_priority_kick|amf_play|amf_client_prediction|amf_continue_to_next,
[0.05, "kick_rightleg", 10, 12, arf_blend_in_3],
],
Does VIM utilize some sort of a buffer that sets a maximum number of lines that will be tracked for indentations? If so, is there any way to increase this buffer size?
Otherwise, if this is simply a fault of the built-in indentation logic, do more robust third-party solutions exists that can provide indentation functionality for such a specific case?
If more information is necessary, I will update.
Asked by: Freddie294 | Posted: 27-01-2022
Answer 1
hmmm in $VIMRUNTIME/indent/python.vim it looks like it scans back the past 50 lines to get context
let s:maxoff = 50 " maximum number of lines to look backwards for ()
you can see what VIM is using to indent by checking the indentexpr of the current buffer
:set indentexpr?
which returns, indentexpr=GetPythonIndent(v:lnum)
and that filetype plugin indent on
in your .vimrc is whats loading it when you load a python file
Similar questions
python - Filetype information
I'm in the process of writing a python script, and I want to find out information about a file, such as for example a mime-type (or any useful depiction of what a file contains).
I've heard about python-magic, but I'm really looking for the solution that will allow me to find this information, without requiring the installation of additional packages.
Am I stuck to maintaining a list of file extens...
How to know the filetype through python
In the very beginning,I tried to do like this(hoped to get some useful information in the head):
>>content=open("fileurl","rb").read()
I found that PNG (png)'s Header is lik this: 89504E47 (I don't know wheather it's true or not)
But when I did in this way,the result is:
>>> content[:20]
'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x01\x90'
the \xis wha...
python - Django- Check the filetype of an uploaded file and then alter the template
I want to write a function that checks the extension of the uploaded file and depending on that assigns a variable a value.
I hope it makes sense. I basically want to check the filetype of an uploaded file and then alter the template accordingly.
The code that I am thinking of implementing is something like this but I am kind of confused
models.py
class ScribbleMedia(models.Model):
...
How to serve filetype object in python
I'm using the URLLib2 method to download a file from another server via a rest api (the url can't be exposed to the user--that's why it needs to be done on the backend).
It gives me the following response:
(<addinfourl at 4365818480 whose fp = <google.appengine.dist27.socket._fileobject object at 0x1043883d0>>
I'm now trying to find a way to serve this file to the end...
Python: A way to detect a filetype attached to a string?
In IronPython 2.6*, I'm trying to build a function that "corrects" a string; I have two arguments, FILE and EXTN. The idea is for them to be concatenated as necessary later in the program, but you know some people don't read instructions and you're bound to have someone enter "FILE.*" as their FILE, which would mess everything up.
I'm looking for a way to take
file - Python frozen app filetype
I've got a python GUI application (wx) that is able to open zip files with an alternate extension (.giz).
def GetGIZData(self, filepath):
#{extract the zip to a temp dir and read the files}
pass
My question is this: if I've got a file at C:\InputFile.giz, how do I get a handle on "C:\InputFile.giz" from a frozen python app in Windows when I double click on InputFile.giz? (Essentia...
Python: How to find google drive filetype?
I'm currently using the session.get() code found at this stackoverflow. When I save the drive files they don't have a filetype suffix, so I have to add one manually to based on file type to open it. Is there a way I can parse the chunk and get filetype variable or maybe even search by hexcode? Better method?
import requests
def download_file_from_google_drive(id, destination):
URL = "https://docs.google...
python - batch file to open custom filetype
I have a custom filetype (.photon) that is read by a python script which I generally run like this in a terminal:
py C:\Users\greym\Desktop\photon\photon.py C:\Users\greym\Desktop\photon\test.photon
the last argument is the file that is read by the python script how I make it so I can click on that file and it will run it through the python script
python - Save As, each filetype has different callback function
I use python tkinter, and Import tkinter.filedialog to save as files. The program has functions to save each file type.
Using filedialog.asksaveasfilename Returns file path only.
The Problem: how to get the file type, to call the right function?
Below is a sample Code of what I did.
python
filename= filedialog.asksav...
Trying to open a certain filetype using my python exe
I made a simple python file encryptor. I want to open all encrypted (or .aes) files using my program. I have already made it into a working executable using pyinstaller but when I tried to open a .aes file with my program (through the context menu in the file explorer), it unsurprisingly started the program but did not take the .aes file as input. I want to open any .aes file using my program and for the python script to s...
Still can't find your answer? Check out these communities...
PySlackers | Full Stack Python | NHS Python | Pythonist Cafe | Hacker Earth | Discord Python