How to format file or selection in ZeroBrane - zerobrane

Is there a menu command or a plugin to format the whole file or the selection?
I tried Correct Indentation, but it did nothing to the following code.
local x = 'Hello' y = 'world' if y..x == 'worldHello'then print('OK') end

ZeroBrane Studio will adjust the indentation, but it will not break the lines to do a complete formatting (this is why you don't see any difference on your line of code). You may have to use something like LuaFormatter for this.

Related

Intellij Idea Code wrapping when formatted

I am new to Intellij Idea. I didn't find any information on how to wrap the code after certain characters (ex: 150 characters, break the line)
I want to break the code after the vertical line, the following code must come in next line.
Note: I used Reformat code option, but it did just realigned the code with some white spaces etc, but not wrapping up the code. It's difficult to see the end of the code.
You go to Settings (alt+ctrl+s) then select Code Style - General
Here you can configure your margins and if you want the code to wrap after it reaches the end of it

VB.NET IDE: Refresh code lines

I am using the Find & Replace function frequently, and I don't care about the case.
So I am replacing e. g.
"Dim s As String = SomeFunc(SomeArg)"
with
"dim s as string = somenewfunc(somearg)"
The IDE replaces it fine, but it uses my lower case typing.
Only when I change something in that line (for example by adding a space at the end of the line)
"dim s as string = somenewfunc(somearg)"
, it becomes
"Dim s As String = SomeNewFunc(SomeArg)"
as it should be.
Does anybody know some magic way to refresh all my lines of code?
Clean and Rebuild did not help me.
Thank you!
A few options:
When you do your replace use the proper case.
You could also do Format Document. Edit --> Advanced --> Format Document or Ctrl E, D But this will only do the current document. Not sure if this will fix your case in the document. Maybe there is a way to do this to all documents, I am not sure. I imagine resharper can do this with code cleanup.
You might want to look at the advice from this link:
How to format all files in Visual Studio 2012?
See Jay Bazuzi's answer.
You will want to tweak his code to use .vb instead of .cs

How to remove unnecessary blank line on code formatting in IntelliJ?

Is it possible to remove empty/blank lines using code formatting in Intellij IDEA?
Yes. It is possible to configure the number of blank lines in the settings menu (CTRL+ATL+S): File -> Settings -> Editor -> Code Style -> Java(or Scala or whatever your language is) -> Blank Lines
File >> Setting >> Editor >> Code style java >>Blank lines tab
You should change to 0 in code label(as picture), It would remove all unnecessary blank line when press format shortcut: ctrl + alt + L
You can find and replace with regex option also ^(?:[\t ]*(?:\r?\n|\r))+. It searches all empty lines in file. You need to just replace it with empty
I use regular expressions to remove extra blank lines from the code. Here are the instructions.
Open Find and Replace dialog. Use shortcut CTRL+SHIFT+R.
In the search box type ^(?:[\t ]*(?:\r?\n|\r)){2,}. This will search for two ore more blank lines.
In a replace box type \n. This will replace with one blank line.
Open Reformat Code dialog and click Run. Use shortcut CTRL+ALT+L.
This works on all JetBrains IDEs. Use the screenshot as referece.
Just in case it helps someone using newer versions of Intellij, in Intellij IDEA 2016.2.4 it is File -> Other Settings -> Default Settings -> Editor -> Code Style -> Java(or Scala or whatever your language is) -> Blank Lines
For those trying to remove blank lines at the end of the file, this became a feature as of August 2020.
The proper place to configure this action is under Settings|Editor|General|On Save. Check "Remove trailing blank lines"

How to preserve formatting from rstudio when copy/pasting to Word?

I want to reproduce my code in Word 2010. The scripts were written in rstudio, and I would like to preserve rstudio's formatting when pasting into Word. Principally, I like the font colors and spacing that rstudio uses. I find that when I paste from SAS to Word, the formatting is preserved, but no dice here.
I would usually look for copy special / paste special options to do this, but I can't find any. When I try to paste special into word, only unformatted text options are presented. I would rather not reformat the text line-by-line, because I think it looks pretty nice in rstudio.
I thought of trying to save the script in rstudio to some format that would preserve its formatting, but I couldn't find any way to do this. How can it be done?
It's not totally clear whether you are pasting from RStudio's script editor (which has some 4 or 5 colors) or from the R console (script + output) within RStudio (which only has 2 colors).
If you are pasting from the console--please check "Paste special" again. There should be an option for "HTML Format" that will do what you need (though you may need to resize the font to make everything fit properly depending on your page margins).
If you are pasting from the script editor, then you're out of luck with a direct copy-and-paste solution. But there is a copy-and-paste-and-copy-and-paste solution...
One solution could be to use Notepad++. From RStudio, save your script (with a ".R" extension) then open the script in Notepad++. (Or copy and paste from RStudio to Notepad++, but make sure you set the file's language--from the "Language" menu--to R). When your script is correctly highlighted in Notepad++ go to the "Plugins > NppExport > Copy HTML to clipboard" menu to copy the open file. This can then be pasted into MS Word with HTML format.
Just in case someone else looks for this question...
Another way to have all the source code in a word document with a good-looking format using RStudio is to use the File/Compile Notebook option, choosing MS Word as the output format.
Using this option, a .docx document will be generated with the output of your script as well as the original source code. The script will be executed, though.
If you don't want your code to be evaluated (you just want a simple copy-paste), you can add #+eval=FALSE at the beginning of your script and then the source code will be reproduced in the word document without being evaluated.
This approach relies on knitr. Here is an example if anyone wants to start playing with this.
#' ---
#' title: "My homework"
#' author: John Doe
#' date: June 15, 2015
#' output: word_document
#' ---
# The header above sets some metadata used in the knitr output
# Conventional comments are formatted as regular comments
# Comments starting with "#+" control different knitr options.
#+echo=FALSE,message=FALSE,warning=FALSE
library(ggplot2)
#+echo=TRUE
#' Comments with a "+" sign are used to tell knitr what should be
#' done with the chunk of code:
#'
#' - echo: Show the original code or not
#' - eval: Run the original code or not
#' - message: Print messages
#' - warning: Print warnings
#' - error: Print errors
#' ...
#' Comments with an apostrophe "'" will be printed as regular text.
#' This is very useful to explain what you are actually doing!
# Regular comments can be used to document the code as usual
# Figures are printed:
ggplot(mpg, aes(x=cty, y=hwy)) + geom_point(aes(color=class))
#' Formatting **options** are possible.
#' Even [links](http://stackoverflow.com/questions/10128702/how-to-preserve-formatting-from-rstudio-when-copy-pasting-to-word)
#'
#' This will show all the packages and versions used to generate this document.
#' It can be used to make sure that your teacher has all he needs to run your script
#' if he/she wants to.
sessionInfo()
Assuming you have internet access
Copy and paste to gist.gisthub.com
Select 'R' as the language - this should provide colours
Hit create (secret or public) gist
Copy and paste from the gist to your word processor.
Compared with the notepad++ solution:
An online backup to your code, with a recording of the time when you clipped it.
You don't have to install any other software, useful if you're a student using a public computer.
If you just need the code as formatted:
Step1: Just add #+eval=FALSE at the beginning of your code.
Step2: Then go to File -> Knit Document. Compile the file in msword/PDF/Html.
OR
Just add #+eval=FALSE at the beginning of your code.
Press CTRL+SHIFT+K and then compile the file in msword/PDF/Html.
If you need the code with output do not enter add #+eval=FALSE at the beginning of your code and perform step 2 directly.
I agree with zeehio that using Knitr is probably the best option. But another way is to use the Pretty R tool and the "open document text" steps here. Basically just copy and paste your code into pretty R, and copy and paste the output (not the html) into the open document.
After you copy from the Rstudio Console window and paste into a Word document, you need to highlight all the the just copied text and change the font into Courier New. This will give you the same spacing and lineup as you had in the Rstudio Console window.
Copy paste the code from Rstudio editor to 'visual studio code' & then again copy from there into a word processor.
For this to happen you must first install R extension in visual studio code.
'Visual studio code' is itself an IDE which can potentially be used for R language as well, but right now I'm emphasizing on using it to answer the above question.
In R I use the Monaco editor font. To copy paste the output of the R consol in Microsoft Word, I select the output of the consol, right click and copy and paste in my Word document. Once I have pasted the output in word, I select it and put it in Word's Monaco font and reduce the size of the font if necessary.
This does the job very nicely and perfectly preserves the output style from the R consol, as well as written chunks of code.
If you want to retain the formatting when coping a selection from the R Console you will need to install an older version of R Studio. Version 1.2.5042. it will not work in the newer versions

Control Indentation Hanging in PowerPoint 2010 VSTO

I have a paragraph and after executing :
paragraph.ParagraphFormat.FirstLineIndent = 18;
paragraph.ParagraphFormat.LeftIndent = 18;
when I check Paragraph dialog box, I get:
Indentation Before Text 0.25" - OK, this is what I wanted
Special First line 0.25" - it's not what I want.
Instead of First line I want to have Special set to Hanging. Is it possible to control it with code?
Instead of First line I want to have Special set to Hanging. Is it possible to control it with code?
Yes it is possible :)
Just remember the thumb rule
For FirstLine use a positive value and
For Hanging use a negative value
Change your code to
paragraph.ParagraphFormat.FirstLineIndent = -18;