How to move all the code on forum by four spaces? [migrated] - stack-overflow

How do I post text so that it is formatted as code?
What do I need to do so that my code shows up properly—not escaped or removed—when posted? And how to get the correct syntax highlighting?
For more information, see "How do I format my posts in HTML or Markdown?" in the Help Center.
Return to FAQ index

For inline code (that does not hold newlines), any of the following will work:
Enclose with backticks: `<html>`.
Embed within <code> tags, and manually encode HTML entities: <code><html></code>
Select the partial text and hit CtrlK (⌘K on OS X) or click the {} button above the editor (pictured below)
For blocks of code, to preserve newlines, use one of the following methods:
Use the {} button above the editor (pictured below)
Paste your code, select the full lines, and hit CtrlK (⌘K on OS X)
Use fenced code blocks, by surrounding your code with ```, or with ~~~ (opening and closing fence have to be on their own line, and can be indented with up to three spaces; more than three backticks or tildes can be used, as long as the closing fence uses the same character and is at least as long as the opening fence)
Indent everything four (4) spaces (ensure there is a blank line between the top of the block and other text)
Encase in <pre> or <pre><code> tags (in that order; using <code><pre> is invalid), and encode HTML entities (like < for <) yourself
Code copy/pasted from an IDE is often already tabbed. When rendering, tabs are replaced with spaces.
Code within a blockquote
To include code within a blockquote, make sure to include the space after the > as well as the four spaces before the code.
> Lorem ipsum dolor sit amet, consectetur adipiscing elit.
> for(;;)
echo 'badger ';
Or, put the blockquote character (and its following space) at the beginning of every blank line, including the one immediately before the code.
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
echo 'badger ';
Code within a numbered or bulleted list
If your code appears inside a list, you must indent an additional four spaces for each level of nesting.
- First bullet (is the deepest)
echo 'ow ';
- Second bullet
If you want a block of code to follow a list but not be nested under the final list item, you can use an HTML comment as a "breakpoint". If you do this, the code block only needs to be indented with the normal four spaces:
- First bullet
- Second bullet
<!-- -->
echo 'ow ';
Syntax highlighting
Prettify is used to add colour to the code, but only if the language can be uniquely determined given the tags of the question, or if manual hints have been provided.
For any code block, you can use these HTML comments to specify the language:
<!-- language: lang-or-tag-here -->
code goes here
<!-- language: lang-or-tag-here -->
code goes here
<!-- language: lang-or-tag-here -->
code goes here
<!-- language: lang-or-tag-here -->
code goes here
You can also specify the syntax for all codeblocks in your post with the language-all hint:
<!-- language-all: lang-or-tag-here -->
code goes here
More text not in code blocks
code goes here
Alternatively, if you use fenced code blocks, you can specify the language right after the first fence:
code goes here
code goes here
See the full specification and list of languages hints.
Note that:
The HTML comments must not be indented
The blank line between <!-- language: ... --> and the indented code block is required
The space between language: and the language is required
When using a tag to specify language, the tag name is case-sensitive
If you combine the fenced style with the HTML comments, the HTML comments are ignored
If no language is defined then no highlighting occurs at all. But in the preview, or if multiple language tags define very different languages and no manual definition is used, a default highlighting is used in which Prettify makes a best guess.
There is a delay before the preview text highlighting is applied after you stop editing your markdown source, of around 5 seconds.
Stack Snippets – Executable JavaScript/HTML/CSS snippets
Stack snippets can group a JavaScript, HTML and CSS code snippet and make them runnable. This feature can be accessed by the icon that looks like a page with a <> on it. Alternatively, you can press CtrlM (⌘M on OS X).
The code snippet tool allows you to format code automatically using the Tidy button on the left. You can use this option to take care of replacing tabs by spaces, correct code indentation, and general improvement of readability
Once you save your snippet, you’ll get something like this in the editor:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
// JavaScript code
<!-- language: lang-css -->
/* CSS code */
<!-- language: lang-html -->
HTML code
<!-- end snippet -->
If you delete the begin snippet and end snippet comments, you’re left with three adjacent code snippets that are not executable. You may also keep a single block of code which will have the correct formatting and indentation.
Using mobile devices
One sometimes needs to press and hold the regular single quote to get the backtick.
Backticks in text
To include a backtick without accidentally starting some inline code, escape it: \`
like \` so yields: like ` so
<kbd>Alt Gr</kbd>+<kbd>\`</kbd> gets `|` yields: Alt Gr+` gets |
Backticks within backticks
To use literal backticks within a code span, use any unique number of multiple backticks as the opening and closing delimiters: both ``literal backtick (`) here`` and, for example, ``````literal backtick (`) here`````` yield literal backtick (`) here. This works in comments too.
To use literal backticks at the start and/or end, add one space to both the opening and closing delimiters: `` `<html>` `` yields `<html>`, and `` $` `` yields the Perl $` operator. In comments, the additional space in the delimiters is not supported. Instead, escape the backtick: `\`<html>\`` and `$\`` to get `<html>` or $` in a comment.


Does anyone know the do's and don't of commenting in FireFox 3.x?

I decided to show a breaking version of what I am talking about. It is not important how it messes up the layout, only that it causes the DIV element to be null....
<!-- [ top panel ] --><div id="top_panel">
<!-- -------------------------------------- -->
<script type="text/javascript">
The above code will return the element as null, every time.... if I increase or decrease the number of dashes it still fails as long as the interior dashes end with a closing pair of dashes. For the sake of example, I will use [open] and [close] to represent pairs of "--" dashes...
So, the code ends up being interpreted this way to break:
<!-- [close][open][close][open][close][open][close][open][close] -->
In this example, it is the last [close] and the "-->" which now cause an open, hanging comment.
I only seem to run into comment-based issues in FF these days. All other browsers seem okay with anything I have thrown at them...
I KNOW that this is not considered legal commenting, but it still does not change the fact that I had to trip over this situation to become aware of the issue... I am hoping others can avoid the same simple problem and share their own twists on weird, comment-based issues in any browser... I am sure this is not the only instance of good commenting gone bad.
I also understand that leaving a space after the "<" is a no-no as well: "<" + " " + "!" + "--" = Nooooo!
Thanks for all your help, all!
You can't use -- inside comments because it ends the comment. This isn't a Firefox thing - it's defined by the standards. Any browser that doesn't treat -- as start/end of comment is doing it wrong and most likely will be bug-fixed eventually.
White space is not permitted between the markup declaration open delimiter("<!") and the comment open delimiter ("--"), but is permitted between the comment close delimiter ("--") and the markup declaration close delimiter (">"). A common error is to include a string of hyphens ("---") within a comment. Authors should avoid putting two or more adjacent hyphens inside comments.
Are you serving XHTML? According to the XML standard,
For compatibility, the string " -- " (double-hyphen) MUST NOT occur within comments.
Edit: the same restriction exists in regular HTML, too.

Doxygen parsing ampersands for ascii chars

I've been using Doxygen to document my project but I've ran into some problems.
My documentation is written in a language which apostrophes are often used. Although my language config parameter is properly set, when Doxygen generates the HTML output, it can't parse apostrophes so the code is shown instead of the correct character.
So, in the HTML documentation:
This should be the text: Vector d'Individus
But instead, it shows this: Vector d'Individus
That's strange, but searching the code in the HTML file, I found that what happens is that instead of using an ampersand to write the ' code, it uses the ampersand code. Well, seeing the code is easier to see:
<div class="ttdoc">Vector d&#39;Individus ... </div>
One other thing is to note that this only happens with the text inside tooltips...
But not on other places (same code, same class)...
What can I do to solve this?
Apostrophes in code comments must be encoded with the correct glyph for doxygen to parse it correctly. This seems particularly true for the SOURCE_TOOLTIPS popups. The correct glyph is \u2019, standing for RIGHT SINGLE QUOTATION MARK. If the keyboard you are using is not providing this glyph, you may write a temporary symbol (e.g. ') and batch replace it afterwards with an unicode capable auxiliary tool, for example: perl -pC -e "s/'/\x{2019}/g" < infile > outfile. Hope it helps.
Regarding the answer from ramkinobit, this is not necessary, doxygen can use for e.g. the Right Single quote: ’ (see doxygen documentation chapter "HTML commands").
Regarding the apostrophe the OP asks for one can use (the doxygen extension) &apos; (see also doxygen documentation chapter "HTML commands")).
There was a double 'HTML escape' in doxygen resulting in the behavior as observed for the single quote i.e. displaying '.
I've just pushed a proposed patch to github (pull request 784,
EDIT 07/07/2018 (alternative) patch has been integrated in main branch on github.

vim select {}/() plus the leading dollar

If the cursor is inside a {} or () block, select the block plus the leading dollar. If not, do nothing.
Is there an easy way without having to write a function for that?
If have to do scripting, my question is how to check if any texts are currently selected.
Assuming you want to visually select the ${bar baz} in the following sample:
lorem ipsum ${bar baz} sit amet.
One method among many
should select the whole (foo bar).
should select the whole {bar baz}.
From there, you can move the cursor to the other end of the visual selection and expend it to include that elusive leading $ with:
In one go:
Another method
should move the cursor to the first $ to the left and start selection from there to the next closing parenthesis to the right. Of course, you can do it the other way if it makes more sense for you:
Mapping it
If, somehow, you find those sentences too complicated, you can create custom mappings:
nnoremap <key> f)vF$
nnoremap <key> f}vF$
Creating a custom text-object
The downside to this is that you will need additional mappings for other modes and other operators. Unless you create a custom text-object:
xnoremap a$ /[})]<CR>o?$<CR>
onoremap a$ :<C-u>normal va$<CR>
which lets you do va$, of course, but also ca$, da$, ya$, etc. on either $(foo bar) or ${bar baz}.

How do you use a replace command in a Sublime Text 2 snippet?

I have defined a snippet in Sublime Text 2 as follows:
<cfqueryparam cfsqltype="cf_sql_${1:integer}" value="$SELECTION">
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<!-- <tabTrigger>hello</tabTrigger> -->
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<!-- <scope>source.python</scope> -->
This works correctly to create a cfQueryParam tag around the selected text, and highlights the part of the cfSqlType that I may need to change for different data types.
However, when using this for strings I need to first click on each side of the value, delete the single quotes, then select the value and hit my keybind for the snippet. This requires two mouse clicks, a double-click, and three keypresses, in addition to more precise mouse aiming. With integers I require only a double click and one keypress. As I have several thousand files to go through doing these replaces, this will make the difference of many hours of work.
Is it possible to put something in the snippet that will cause it to remove a particular character, in this case single quotes? I assume some sort of replace is possible, but I cannot find anything in the docs.
The official docs are kind of sparse, but the community-developed unofficial documentation is much more complete. Boost PCRE-style regexes are supported in snippets, see here for information. I'll leave it up to you to develop the regex for removing the quotes :)
Alternatively, there are a couple of plugins that could help you: Expand Selection to Quotes and Unquote. Each time you run the Expand Selection to Quotes command, it expands the selection to the next set of quotes:
Start with this:
run command once to select string inside quotes:
run command again to select quotes:
then run Unquote command to delete quotes, leaving selection:
I'd suggest creating a macro that runs expand_selection_to_quote twice, unquote once, and then your snippet. Bind this to a different key binding than your original snippet, so you can use the snippet just for individual words, and the macro for strings.
Good luck!

Notepad++ Syntax Highlighting: Collapse indented

I am creating a ChoiceScript ( syntax highlighting file in Notepad++. ChoiceScript is a scripting language for creating interactive fiction. Its most important tags are the *choice tag (used to denote a choice the user can make) and # (used to denote the text of that choice).
I'd like the ability to collapse all lines beneath a line that begins with *choice or # that are indentet farther than their parent. For example, in
How are you?
Glad to hear it.
I'm sorry to hear it.
I'd like the entire block beneath *choice to be collapsible, as well as the answers beneath #Good and #Bad. How can I do this?
Do the following thing Language > Define your language > folding in code 1 style
Put * # and save it .hope fully it works.