Question

I'm writing javascript using Geany IDE. My indentation is all messed up and I'd like to make it look nice. When I write Java in Eclipse I can do ctrl + i to make all the spacing in order.

What is the indentation option available in Geany?

Was it helpful?

Solution

The document formatting option is on the Geany's plugin wishlist (ref. Auto Correct Indentation section in Geany's Plugin Wishlist).

However, Geany allows to send text using custom commands.

As you may suspect this opens a pretty wide selection of new "doors" behind which lies the solution of your problem, e.g. Artistic Style is a cross-platform code auto-formatter for C, C++, C#, and Java. So the solution is:

  • get a copy of any code formatting tool that accepts text from standard input and returns the resulting text to standard output,
  • in Geany go to Send Selection to->Set Custom Commands and add an appropriate command for your tool

I am not an agitator for Artistic Style, you can just use any tool that formats Java code. It has been done this way with HTML Tidy or PHP Beautifier, results look like this:

enter image description here

OTHER TIPS

command for html simple smart indentation that finaly work in geany :

bash -c "tidy --indent auto --indent-spaces 2 --char-encoding utf8 --quiet yes 2>/dev/null; true" 

PHPFormatter is a php script found here -- https://github.com/NathanWong/phpformatter It can be run via the command line and does an awesome job of formatting PHP,HTML,and Javascript. From the authors description:

"This PHP script will format another PHP script using my arbitrarily set formatting rules (real tabs, 97 chars per line, brackets on their own line, indentation based on operator hierarchy not alignment, spaces around most operators but not commas or brackets, space after if, etc.). It will also format inline HTML, and if JS Beautify is available, it'll use that for inline Javascript in inline HTML too."

I simply unzipped the 2 files : format.php and jsbeautify.php to my home directory and then added the following custom command in Geany:

php /home/myusername/format.php -

(Note the dash at the end. This tells the script to accept input from the standard input stream which is where Geany sends the text.) Now all you have to do is a quick Ctrl+a (SelectAll) then Ctrl+1 (or whichever number you put the command on) and ...

Voila...

Beautifully formatted code!! Thanks Nathan!

Based on geany documentation type of auto-indentation are like below:

Geany knows four types of auto-indentation:

None: Disables auto-indentation completely.

Basic: Adds the same amount of whitespace on a new line as on the last line.

Current chars: Does the same as Basic but also indents a new line after an opening brace '{', and de-indents when typing a closing brace '}'. For Python, a new line will be indented after typing ':' at the end of the previous line.

Match braces: Similar to Current chars but the closing brace will be aligned to match the indentation of the line with the opening brace.

You have just following options. You may improve and extend these options using Scintilla.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top