indentation

Grab a line's whitespace/indention with Python

喜你入骨 提交于 2019-11-27 23:41:15
Basically, if I have a line of text which starts with indention, what's the best way to grab that indention and put it into a variable in Python? For example, if the line is: \t\tthis line has two tabs of indention Then it would return '\t\t'. Or, if the line was: this line has four spaces of indention Then it would return four spaces. So I guess you could say that I just need to strip everything from a string from first non-whitespace character to the end. Thoughts? import re s = "\t\tthis line has two tabs of indention" re.match(r"\s*", s).group() // "\t\t" s = " this line has four spaces of

How to fix the YAML syntax error: did not find expected '-' indicator while parsing a block?

白昼怎懂夜的黑 提交于 2019-11-27 23:12:38
问题 I have some code written in my .travis.yml written for a Python library. Using lint.travis-ci.org, I came to know that there is some indentation problem in my YAML file. Here is the part which the error points to install: - if [[ "${TEST_PY3}" == "false" ]]; then pip install Cython; python setup.py build; # To build networkx-metis mkdir core; # For the installation of networkx core cd core; git clone https://github.com/orkohunter/networkx.git; cd networkx/; git checkout addons; python setup

Copy-paste into Python interactive interpreter and indentation

荒凉一梦 提交于 2019-11-27 22:12:08
This piece of code, test.py: if 1: print "foo" print "bar" can be succesfully executed with execfile("test.py") or python test.py , but when one tries to copy-paste it into python interpreter: File "<stdin>", line 3 print "bar" ^ SyntaxError: invalid syntax Why is it so? Can interpreter by configured in such a way that it would read copy-pasted text succesfully? I guess that may affect typing in the interpreter, but that's ok for me. rplnt Indentation is probably lost or broken. Have a look at IPython -- it's enhanced python interpreter with many convenient features. One of them is a magic

stopping vim from removing indentation on empty lines

青春壹個敷衍的年華 提交于 2019-11-27 21:21:08
When the cursor is placed at the end of a line containing nothing but withspace characters, vim will, when i press enter, remove that whitespace. I find this irritating, as it breaks my script for selecting code that are indented to the same level. How can I prevent vim from doing this? In my .vimrc ( http://bjuhn.com/randomstuff/vimrc ) I have the following: filetype plugin on set copyindent that is, I am not using any syntax-aware auto-indention, as I have yet to find one that does everything to my liking. Prince Goulash The Vim wiki suggests this: inoremap <CR> <CR>x<BS> because the

How to indent the fluent interface pattern “correctly” with eclipse?

会有一股神秘感。 提交于 2019-11-27 19:56:13
问题 I just created a generator for some fluent interfaces. Now I have lots of code looking like this: new MyFluentInterface() .setFirst( "first" ) .setSecond( "second" ) .setThird( "third" ) .invoke( obj ); I like the indentation shown above, but I can't find a way to configure eclipse to indent this correctly. eclipse always indents like this: new MyFluentInterface() .setFirst( "first" ) .setSecond( "second" ) .setThird( "third" ) .invoke( obj ); How can I configure eclipse so that it indents

How to preserve whitespace indentation of text enclosed in HTML <pre> tags excluding the current indentation level of the <pre> tag in the document?

强颜欢笑 提交于 2019-11-27 18:57:34
I'm trying to display my code on a website but I'm having problems preserving the whitespace indentation correctly. For instance given the following snippet: <html> <body> Here is my code: <pre> def some_funtion return 'Hello, World!' end </pre> <body> </html> This is displayed in the browser as: Here is my code: def some_funtion return 'Hello, World!' end When I would like it displayed as: Here is my code: def some_funtion return 'Hello, World!' end The difference is that that current indentation level of the HTML pre tag is being added to the indentation of the code. I'm using nanoc as a

Indenting entire file in Vim without leaving current cursor location

孤街醉人 提交于 2019-11-27 18:26:07
问题 I already know that gg=G can indent the entire file on Vim. But this will make me go to the beginning of the file after indent. How can I indent the entire file and maintain the cursor at the same position? 回答1: See :h '' This will get you back to the first char on the line you start on: gg=G'' and this will get you back to the starting line and the starting column: gg=G`` I assume the second version, with the backtick, is the one you want. In practice I usually just use the double apostrophe

Tidying HTML5 Output Indentation in PHP

陌路散爱 提交于 2019-11-27 18:15:31
问题 My web application produces HTML5 output as a concatenation of a variable number of views. The end result is a mess of indentation: </div> </div> <div id="content"> <div id="question-header"> <h1> I want to indent the code to obscure the origin of individual views and to make the output easier to follow. I have looked into the Tidy PHP extension but all my attempts to make it work with HTML5 have produced improper indenting. 回答1: The closest to what you are looking for in the PHP land is

Automatic indentation for Python in Notepad++

耗尽温柔 提交于 2019-11-27 17:24:30
问题 I've been googling lots and this is getting really frustrating. It doesn't act like idle. Example: else: name = 'World' print 'Howdy', name print 'yay' but in Notepad++ else: # i press enter and this is what it does lands me here But I want to be able to do like in idle: after the : I can just press enter and keep on going. My English isn't that great. I have my filetype set to Python etc. and my format to unix. 回答1: This is what you want: Settings > Preferences > MISC. > Auto-Indent

How do I autoindent in Netbeans?

妖精的绣舞 提交于 2019-11-27 16:57:27
In eclipse you can click Ctrl + I at any line, and it'll automatically indent the line or group of lines according to the indentation scheme you chose in the settings. I'm really missing this feature in Netbeans. Is there any equivalent feature? I'm aware of Alt + Shift + F but it's not good enough. I want to indent a group of lines, and not all the file. varad Open Tools -> Options -> Keymap , then look for the action called "Re-indent current line or selection" and set whatever shortcut you want. Pressing Alt + Shift + F indents your selection. If nothing's selected, it indents the whole