indentation

ANTLR What is simpliest way to realize python like indent-depending grammar?

不羁岁月 提交于 2019-11-26 17:39:14
问题 I am trying realize python like indent-depending grammar. Source example: ABC QWE CDE EFG EFG CDE ABC QWE ZXC As i see, what i need is to realize two tokens INDENT and DEDENT, so i could write something like: grammar mygrammar; text: (ID | block)+; block: INDENT (ID|block)+ DEDENT; INDENT: ????; DEDENT: ????; Is there any simple way to realize this using ANTLR? (I'd prefer, if it's possible, to use standard ANTLR lexer.) 回答1: I don't know what the easiest way to handle it is, but the

Java: How to Indent XML Generated by Transformer

◇◆丶佛笑我妖孽 提交于 2019-11-26 15:58:17
I'm using Java's built in XML transformer to take a DOM document and print out the resulting XML. The problem is that it isn't indenting the text at all despite having set the parameter "indent" explicitly. sample code public class TestXML { public static void main(String args[]) throws Exception { ByteArrayOutputStream s; Document d = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); Transformer t = TransformerFactory.newInstance().newTransformer(); Element a,b; a = d.createElement("a"); b = d.createElement("b"); a.appendChild(b); d.appendChild(a); t.setParameter

Notepad++ indentation messes up

牧云@^-^@ 提交于 2019-11-26 15:49:28
问题 I'm coding in Python and I really like Notepad++. However, off late when I use tab to indent, it seems fine in Notepad++, but when I run the program I get an indentation error, and when I check my code in Emacs or something, I find that Notepad++ actually adds more tab spaces than it shows on screen. What is happening? 回答1: There is no universal tab size, so I always make sure to replace tabs by spaces (so you know what you see is what you get everywhere else as well) Go to Settings ->

Indent multiple lines quickly in vi

为君一笑 提交于 2019-11-26 15:33:59
Should be trivial, and it might even be in the help, but I can't figure out how to navigate it. How do I indent multiple lines quickly in vi? Greg Hewgill Use the > command. To indent 5 lines, 5 > > . To mark a block of lines and indent it, V j j > to indent 3 lines (vim only). To indent a curly-braces block, put your cursor on one of the curly braces and use > % or from anywhere inside block use > i B . If you’re copying blocks of text around and need to align the indent of a block in its new location, use ] p instead of just p . This aligns the pasted block with the surrounding text. Also,

Python: using 4 spaces for indentation. Why? [closed]

末鹿安然 提交于 2019-11-26 15:25:17
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 years ago . While coding python I'm using only 2 spaces to indent, sure PEP-8 really recommend to have 4 spaces, but historically for me it's unusual. So, can anyone convince me to use 4 spaces instead of 2? What pros and cons? P.S. And finally, what's easy way to convert all existing

Changing Vim indentation behavior by file type

柔情痞子 提交于 2019-11-26 13:52:43
Could someone explain to me in simple terms the easiest way to change the indentation behavior of Vim based on the file type? For instance, if I open a Python file it should indent with 2 spaces, but if I open a Powershell script it should use 4 spaces. You can add .vim files to be executed whenever vim switches to a particular filetype. For example, I have a file ~/.vim/after/ftplugin/html.vim with this contents: setlocal shiftwidth=2 setlocal tabstop=2 Which causes vim to use tabs with a width of 2 characters for indenting (the noexpandtab option is set globally elsewhere in my configuration

Remove all arbitary spaces before a line in Vim

耗尽温柔 提交于 2019-11-26 13:04:50
问题 I\'v written a plugin where it comes to parsing a XML tag. The content inside the tag is indented and when i copy the parsed string into the file it\'s gettting like: Example line This is part of the parsed line Thats goes one End of line What I want is to remove all spaces in front of these lines, the final text should be Example line This is part of the parsed line Thats goes one End of line I\'ve tried to use = but it doesn\'t work the way I want. How can I do that with minimal key strokes

Bash continuation lines

只愿长相守 提交于 2019-11-26 12:52:36
问题 How do you use bash continuation lines? I realize that you can do this: echo \"continuation \\ lines\" >continuation lines However, if you have indented code, it doesn\'t work out so well: echo \"continuation \\ lines\" >continuation lines 回答1: This is what you may want $ echo "continuation"\ > "lines" continuation lines If this creates two arguments to echo and you only want one, then let's look at string concatenation. In bash, placing two strings next to each other concatenate: $ echo

How do I tidy up an HTML file's indentation in VI?

╄→尐↘猪︶ㄣ 提交于 2019-11-26 12:49:32
问题 How do I fix the indentation of his huge html files which was all messed up? I tried the usual \"gg=G command, which is what I use to fix the indentation of code files. However, it didn\'t seem to work right on HTML files. It simply removed all the formatting. I also tried setting :filetype = xml , to see if tricking it into thinking this was an XML file would help but it still didn\'t do it. 回答1: With filetype indent on inside my .vimrc , Vim indents HTML files quite nicely. Simple example

How to fix/convert space indentation in Sublime Text?

强颜欢笑 提交于 2019-11-26 12:49:10
问题 Example: If I have a document with 2 space indentation, and I want it to have 4 space indentation, how do I automatically convert it by using the Sublime Text editor? 回答1: Here's a neat trick in Sublime Text 2 or 3 to convert your indentation spacing in a document. TL;DR: Converting from 2 spaces to 4 spaces: Ensure tab width is set to 2. Convert your 2-space indentation to tabs, switch to tab width 4, and then convert the indentation back to spaces. The detailed description: Go to: View ->