indentation

Can a line of Python code know its indentation nesting level?

半腔热情 提交于 2019-12-03 01:23:40
问题 From something like this: print(get_indentation_level()) print(get_indentation_level()) print(get_indentation_level()) I would like to get something like this: 1 2 3 Can the code read itself in this way? All I want is the output from the more nested parts of the code to be more nested. In the same way that this makes code easier to read, it would make the output easier to read. Of course I could implement this manually, using e.g. .format() , but what I had in mind was a custom print function

Indentation not working on Custom UITableViewCell

ε祈祈猫儿з 提交于 2019-12-03 00:34:22
I have a simple Custom UITableViewCell in my project, and just added an Edit action to the table. Everything seems fine, but indentation is not working when editing, and edit Icons overlap the content. (Not to mention the delete button) The custom cell is created in interface builder, with the standard constraints as usual and I have already tried to ovverride the layoutSubviews method in the class, as mentioned in other places with no luck as follows; (void)layoutSubviews { [super layoutSubviews]; float indentPoints = self.indentationLevel * self.indentationWidth; self.contentView.frame =

Indentation inconsistency [PYTHON] TabError [Different Editors]

强颜欢笑 提交于 2019-12-03 00:31:45
问题 I wrote a few python programs on Idle in Windows. I later shifted to gedit on Ubuntu 14.04. Both have python3 working. I edited these files in gedit. When I run these files, I get 'TabError: inconsistent use of tabs and spaces in indentation' error, even when VISUALLY , there is no inconsistent tabbing or indentation done. [Seemingly, on Windows' Idle the tabs are 4-spaces wide , whereas in gedit, the tabs currently are 8-spaces wide . So, I couldn't use TAB directly.] How to resolve this

Javascript indentation in VIM

天涯浪子 提交于 2019-12-02 23:02:33
I'm trying to get VIM to indent Javascript with the '=' and related commands. When I try to auto indent the following, for example: new function($) { $.fn.setCursorPosition = function(pos) { if ($(this).setSelectionRange) { $(this).setSelectionRange(pos, pos); } else if ($(this).createTextRange) { var range = $(this).createTextRange(); range.collapse(true); range.moveEnd('character', pos); range.moveStart('character', pos); range.select(); } The result is the rather absurd: new function($) { $.fn.setCursorPosition = function(pos) { if ($(this).setSelectionRange) { $(this).setSelectionRange(pos

Why is indentation in empty lines bad?

烂漫一生 提交于 2019-12-02 21:48:10
Every FOSS project I know has rules against trailing whitespace in code. But I think it's very natural to continue the current indentation on the next line: int main() { ....int a = 42; .... ....return a; } But git for instance throws warnings anyway. So my question is: Why are those tabs inside the current indentation bad? I'm not looking for answers like "It's always done this way". Let's assume indentation is done consistently in the whole project in question. It is probably because merging patches with useless whitespace is harder than it should be. diff(1) and patch(1) treat spaces and

CSS - successive indenting of siblings after headings

∥☆過路亽.° 提交于 2019-12-02 21:06:12
问题 I am needing to indent all elements after headings to give a visual structured layout. I have seen that this is possible in the this question : Indent all tags following h2 until next h2 is hit using CSS However, I am unable to "reset" when going back a level. To be more clear, I need to have progressive indents which cancel when moving back. So H1 H2 ..... H2 ..... H3 .... H2 ..... H1 .... If possible, I would prefer to not use enclosing DIV's but rather pure CSS. Is this possible ? 回答1:

Shift a region or line in emacs

蹲街弑〆低调 提交于 2019-12-02 21:01:14
I'm looking for a way in emacs to shift text to the right or to the left by n spaces. A similar functionality that it in vim << or >> . It should work on a region or if no region is selected on a current line and not move the cursor from its current location. The solution from EmacsWiki does not work very well as the M-x indent-rigidly since it somewhat remembers the last region used and shifts that one instead. The closest seems to be the one here but I did not managed to make it work. I'm not a lisp developer so it's difficult to modify the code. I will appreciate any help. Thanks! Maybe

How to change brace indentation levels in Emacs?

本小妞迷上赌 提交于 2019-12-02 20:37:58
I can't for the life of me find any answer to this through conventional Internet means, so I'm hoping for some help. Emacs for me right now tends to do indentation on braces as follows: if( ... ) { } Which I find incredibly irritating; I've never even seen this behaviour anywhere else. At any rate, the behaviour I'm expecting is, if( ... ) { } If anyone knows how to modify this, it'd be greatly appreciated. Basically you want: (setq c-default-style "bsd" c-basic-offset 4) For more indentation commands: M-x c-set-style RET style RET Select predefined indentation style style. Type ? when

Indenting heredocs with spaces [duplicate]

China☆狼群 提交于 2019-12-02 20:13:14
This question already has answers here : here-document gives 'unexpected end of file' error (5 answers) For personal development and projects I work on, we use four spaces instead of tabs. However, I need to use a heredoc, and I can't do so without breaking the indention flow. The only working way to do this I can think of would be this: usage() { cat << ' EOF' | sed -e 's/^ //'; Hello, this is a cool program. This should get unindented. This code should stay indented: something() { echo It works, yo!; } That's all. EOF } Is there a better way to do this? Let me know if this belongs on the

Indentation in Go: tabs or spaces?

…衆ロ難τιáo~ 提交于 2019-12-02 19:52:41
Is there a standard Google Go coding conventions document somewhere that sets whether tabs or spaces are preferred for indentation in Go source code? If not, what is the (statistically) more popular option? What is the official recommendation? (if any) What is the more popular choice? The official recommendation is formatting your code with go fmt or using the gofmt command directly gofmt -w . You can read more about it here on the golang.org blog, or from the Effective go document: Indentation We use tabs for indentation and gofmt emits them by default. Use spaces only if you must. According