Change indentation unit for CodeMirror Python - javascript

I don't see a way to change indentation unit to two-space or best, make it automatically detect the unit: http://codemirror.net/mode/python/index.html
As you can see, the if showed read since it got cm-error class. It has two-space indent. But the print is fine. Although this code block works fine.
So:
Is there a way to make the code using two-space indentation?
Is it possible to make automatic indentation unit?
I tried to play around with http://codemirror.net/mode/python/python.js and cannot come up with any conclusion.

See the indentUnit option. There's no auto-detection in the library, but you might be able to write a little script that finds the first line that's indented more than the one above it, and take the difference as a likely guess.

Related

Split lines to make the code more comprehensible in notepad++

I am trying to modify a js file (It's the first time I try it) and I got something very difficult to understand for me, a mess of inline code with no breaks.
I need it to be clean to be able to understand it, so I've been looking for a solution to break up the text into lines that represents something. I tried to split the lines where the semicolon are, but it didn't solved much.
I remember there where a program that was able to do something similar with css (I can't remember it's name).
Is it possible to do it with notepad++? if not, do you know which program can actually do it?
Thank you
Try using a code beautifier for your javascript, it is currently in 'minified' version.
Example: https://beautifier.io/

What's a good i18n plugin for Cordova/Phonegap?

I'm looking to set up internationalization for an app I'm developing. I've found a good number of bower packages that seem to do what I'm looking for, but only partially.
All of them seem to either be able to set a text programatically in the HTML to an appropriately translated string OR handle certain tags in the HTML and automatically set the value to the translated version of the string.
Unfortunately, I can't find something that does both. There is text in my UI that just never changes and I basically feel like it's wrong to have to write code to set those strings that I never touch otherwise. There is also text that appears dynamically so being able to set it whenever I need to is absolutely necessary.
Don't get me wrong, I don't have a problem with setting text myself but I feel like that would result in some pretty ugly and difficult to maintain code...
If I somehow missed a plugin or a package, or if you have a different solution that can do what I need, I'd appreciate the help.

What's the best practice when modifying twitter bootstrap javascript for your project

In this particular case some of the popover functionality needs to be adapted to our particular needs.
The change itself is quite trivial, it's a modification to this function.
I just need to add another placement, but now I'm not exactly sure how to approach this.
One way would be adding a line to the bootstrap.js file in my repository, that works that has the serious disadvantage of having trouble when updating, I may remember now, but the next one to come after me might generate a hard bug to fix.
Another way I've thought of is extending the function but it might not be easy the way bootstrap is setup. As far as I understand since bootstrap functions are preceded with a plus (+function(){}), they're executed immediately and so I can't get in the way of that.
I've tried modifying this function $.fn.tooltip.prototype.getCalculatedOffset but while it does modify it correctly, the modified one never gets called since it's only called once.
It might be possible but I think the complications of this, outweighs how trivial the fix is (Unless I'm missing a more obvious approach).
Another idea would be forking bootstrap, but I'm not sure what would that accomplish, in the end I'm back with the same problem.
What's the most normal way to approach this? What are the best practices?
Similar to the other answer but using the pop over function, just had to catch the right function!
$.fn.popover.Constructor.prototype.getCalculatedOffse
http://jsfiddle.net/59Er7/3/
A reference is saved to Tooltip as $.fn.tooltip.Constructor in line 1472:
$.fn.tooltip.Constructor = Tooltip
Modifying $.fn.tooltip.Constructor.prototype.getCalculatedOffset (of course not in the original file, but somewhere in your code) should affect the original Tooltip, which is "instantiated" in $.fn.tooltip.
I don't know whether this is best practice, but should work.
jsFiddle Demo

HTML Formatter in Javascript

I have been looking around for a HTML formatter to incorporate with a project I am doing. I need it to be written in Javascript since I want the formatting done on the client side.
The problem is, the few that I have tried don't work very well... For example:
http://www.davidpirek.com/blog/html-beautifier-jquery-plugin : Has a problem with one of the For loops (in the cleanAsync function). Chrome says "unexpected token ILLEGAL"
JS Beautifier on GitHub : When I have links in the HTML it will put a newline character after it. The problem is, I have a period directly after the link in some cases and it will add a space between the link text and the period in the sentence. I tried poking around to fix it but I could not.
Are there any others, or does anyone have recommendations to fix the above two?
EDIT:
This is for editing code, so I just need something to tab in the lines, etc. The code output will go in a textarea.
A few to look at, all have working demos:
http://alexgorbatchev.com/SyntaxHighlighter/
http://shjs.sourceforge.net/
http://jush.sourceforge.net/
http://dojotoolkit.org/reference-guide/dojox/highlight.html
use https://github.com/beautify-web/js-beautify and pass your code to html_beautify() method.

Javascript syntax highlighting in vim

Has anyone else found VIM's syntax highlighting of Javascript sub-optimal? I'm finding that sometimes I need to scroll around in order to get the syntax highlighting adjusted, as sometimes it mysteriously drops all highlighting.
Are there any work-arounds or ways to fix this? I'm using vim 7.1.
You might like to try this improved Javascript syntax highlighter rather than the one that ships with VIMRUNTIME.
Well, I've modified Yi Zhao's Javascript Syntax, and added Ajax Keywords support, also highlight DOM Methods and others.
Here it is, it is far from being perfect as I'm still new to Vim, but so far it has work for me. My Javascript Syntax. If you can fix, add features, please do.
UPDATE: I forgot these syntax highlights are only shown if you included them in your own colorscheme, as I did in my Nazca colorscheme. I'll test if I could add these line into my modified syntax file.
Follow the new version of the javascript syntax file in github, for it is no longer required to modify your current colorscheme.
Syntax coloring synchronization probably needs adjustment. I've found in certain contexts that I need to change it.
Syntax synchronization (":help syn-sync") controls how vim keeps track of and refreshes its parse of the code for coloring, so that it can start drawing anywhere in the file.
The defaults don't always work for me, so sometimes I find myself issuing
:syn sync fromstart
I suggest reading through the documentation under
:help syn-sync
or just check
:help syntax
and find the section on synchronization.
to make an informed decision among the four available basic options.
I maintain mappings to function keys to switch between "fromstart" and "ccomment" modes and for just clearing the sync settings.
This is a really old post, but I was experiencing the same thing: sometimes syntax highlight would just stop working when looking at the javascript section in an .html file. As the OP mentions, a quick workaround was to scroll up and then magically things would start highlighting again.
Today I found the underlying problem and a good solution. In Vim, syntax highlighting uses a context to derive the correct highlight, where context is defined by the previous lines. It is possible to specify how many lines before the current line are used by issuing :syntax sync minlines=200. In this case, it will use up to 200 previous lines as context. It is possible to use the whole file (which can be slow for long files) by running :syntax sync fromstart.
Once I found that, I added this line to my .vimrc:
autocmd BufEnter *.html :syntax sync fromstart
By doing so, .html files will use the whole file as context. Thus, the javascript section will always by highlighted properly, regardless of how long the JS section is. Hope this helps someone else out there!
For a quick and dirty fix, sometimes I just scroll up and down and the highlighting readjusts. Ctrl+L for a screen redraw can also fix it.

Categories