I've set textmate to use softtabs 2 spaces on my file. But when I try to reformat the entire document, it uses 2 hard tabs as the indents.
Regular indents work as I want it to, just the document format doesn't. Anyway to get textmate to be obedient?
Thanks.
The JavaScript bundle's "Reformat Document / Selection" command is passing the document's text to the js_beautify function in the bundle's beautify.php file (found on my system and probably by default at /Applications/TextMate.app/Contents/SharedSupport/Bundles/JavaScript.tmbundle/Support/lib/beautify.php). If you take a look at the function definition you'll see that there's a second parameter, $tab_size, with a default value of 4. There's a line in the bundle that reads print js_beautify($input);. Change this to print js_beautify($input, 2); and you should, I expect, get tab stops with two spaces.
To make it a bit more flexible, use the TextMate environment variable TM_TAB_SIZE, as in print js_beautify( $input, getenv('TM_TAB_SIZE' ) );, which should update how the command operates if you ever change your tab size.
Note, I've tested none of this. :) Just took a look at the bundle and tracked down what seems to be necessary.
So, I tried chuck's suggestion and it gave me an error. I did this to "fix it". I'm sure it could be done more elegantly, but this worked for me.
Open up the same file Chuck says to open up, line 50 (or so) should look like this:
function js_beautify($js_source_text, $tab_size = 4)
change $tab_size to 1
function js_beautify($js_source_text, $tab_size = 1)
Now, around line 56 where it says:
$tab_string = str_repeat(' ', $tab_size);
change the space to a tab like so:
$tab_string = str_repeat("\t", $tab_size);
That worked for me.
Related
I've used microsoft's vscode for some months, but since 2 updates the indentation is broken for me, without a way to fix it. I therefore consider switching to atom. I was working with atom before, and never had this problem, but now it seems to have the same (wrong for me) behaviour as vscode:
if (xxx) // press enter here and type 'something();'
should result in
if (xxx)
something();
but it results in
if (xxx)
something();
It will work completely finde if you add { }, but without them its like the above.
How can I fix this in atom? The basic identation settings don't seem to cover this.
My way of doing this si to always use {} (also because I'm using linter-standard-js) That way, you type
if (myCondition) {}
When you return between the accolades, you get the following
if (myCondition) {
// indented and here you go
}
You can add extra conditions for Atom to change the indent level in your config.cson file, following the lead of the packages that define those conditions in the first place. Add the following to the top level of config.cson and Atom will automatically add a level of indentation after a line that matches the regular expression if\s*\(.*\)$. If you already have a .source.js entry, make sure to change that instead of just pasting this bit in.
'.source.js':
editor:
increaseIndentPattern: '(?x)
\\{ [^}"\']* $
| \\[ [^\\]"\']* $
| \\( [^)"\']* $
| if\\s*\\(.*\\)$
'
I have a CKEDITOR instance (version 4.5.7) into which users input content. This content posts to a database field with the collation SQL_Latin1_General_CP1_CI_AS.
The problem comes when a user pastes text from Word or a similar rich-text editor. Two characters in particular get malformed when they hit the database: ” (”) and – (–).
I have already set config.entities to false to prevent the characters from being converted into their HTML equivalents. Now I'm looking for a place where I can intercept the process to find/replace any offending characters. Although the javascript for this sort of thing is easy enough ( text = text.replace('”', '"') ), I'm not sure where to put it in order to make this happen. I've tried placing it in various places within the CKEDITOR.htmlParser.basicWriter function, but nothing so far has worked.
This seems like it would be a fairly common problem - is there perhaps a way to set collation on the editor so it matches the database?
Thank you for any advice.
I kept plunking away in the basicWriter function until eventually I was surprised to find one place that actually does work. Basically, this is the process I used to solve this problem without editing ckeditor.js
Download and open an uncompressed version of the ckeditor.js file.
Locate and copy the entire CKEDITOR.htmlParser.basicWriter function into the bottom of your config.js file. This basically redefines the function, overriding the real one but allowing us to make customizations to it without necessarily breaking future updates.
In the copied function within config.js, locate the getHtml section and customize the html variable before it gets returned. Below is a template to help you locate this section
getHtml: function( reset ) {
var html = this._.output.join( '' );
// this is where we can replace individual characters or make other
// customizations
html = html.replace('”', '"');
html = html.replace('–', '-');
if ( reset )
this.reset();
return html;
}
I have a problem with Indesign.
I have a document, where I want to add a picture programmatically.
This is easy, when I use a picture on my localdrive. But I want to add a picture from a server path like \myserver\pictures\pic.jpg
I tried it like I add a picture from localdrive
var f = new File("\\myserver\pictures\pic.jpg");
imgPicture.place(f, false);
Then the value in f is
//myserver/pictures/pic.jpg
I build a try catch around it. The errorMessage is undefined.
I get the same error, when i use the networkdrive letter, like
/x/pictures/pic.jpg
As i saw in the documentation for the file-object, there is only one string-parameter for the path.
Is there a solution?
On an other forum, I found a thread where someone had the same problem. But he did a dirty way to solved it. He did a fileOpenDialog and pasted the link to the file and then it downloads the file to the temp directory.
I can't do this, because I have on my server about 100,000 pictures.
Thanks for help.
Another issue of yours may be that backslash may be interpreted as escaping character thus resulting in something like : \myserverpicturespic.jpg" So you may need to escape the escaping character like : "\\myserver\pictures\pic.jpg" and then pass this string. Finally, when I have a doubt about a file path, I usually use this bit of code :
var f = File.openDialog();
if ( f ) $.writeln ( f.fsName );
FWIW
Loic
I can not get the value of f with the forward slashes as you do. I tried your code and it works fine for me if I pass the file-path as
var f = new File("//myserver/pictures/pic.jpg");
You could convert you path with .toString().replace(/\/g, '/')
Also try to replace spaces in the filepath with
CS 5.5 OSX 10.9
This music site shows the dreamweaver function MM_timelinePlay as undefined in chrome and firebug, but it is clearly defined in the header. The header is pulled in dynamically, but this should not matter as it has loaded by the time triggers it. The function is called on the hover state of a button labeled "more."
The code on line 62 is the following (within the function body for MM_initTimelines ):
px", "4px");
This is triggering a JavaScript error when the JS is being parsed, which seeing as the MM_timelinePlay is after the parse error, that function is not actually available to the page for use. Not sure what is supposed to be on line 62, but it appears that the line got munched somewhere in the process (perhaps as part of a bad copy and paste, or as part of at bad edit).
You may be able to recover the line by using the else branch of the if statement that line 62 is part of, here it is:
document.MM_Time[0][0].values[0] = new Array(-141,-131,-120,-110,-100,-89,-79,-69,-58,-48,-37,-27,-17,-6,4);
Change line 62 to something like the following:
document.MM_Time[0][0].values[0] = new Array("-141px","-131px","-120px","-110px","-100px","-89px","-79px","-69px","-58px","-48px","-37px","-27px","-17px","-6px","4px");
Make sure it's all on one line. The edits made were to simply wrap each value of the array with " and then include px. Based on searches for the MM_initTimelines function, the matching line of code (which differs based on the specific movements defined, the true branch of the if statement in your code should match the else except that the values are strings with the px unit added.
As timelines are no longer part of Dreamweaver (removed as of CS5 I think, but maybe earilier), you won't be able to restore or edit the timelines if you are using a newer version of Dreamweaver, so keep the old one around.
This might be a noob question, but I have tried to find an answere here and on other sites and I have still not find the answere. At least not so that I understand enough to fix the problem.
This is used in a userscript for chrome.
I'm trying to select a date from a string. The string is the innerHTML from a tag that I have managed to select. The html structure, and also the string, is something like this: (the div is the selected tag so everything within is the content of the string)
<div id="the_selected_tag">
link
" 2011-02-18 23:02"
thing
</div>
If you have a solution that helps me select the date without this fuzz, it would also be great.
The javascript:
var pattern = /\"\s[\d\s:-]*\"/i;
var tag = document.querySelector('div.the_selected_tag');
var date_str = tag.innerHTML.match(pattern)[0]
When I use this script as ordinary javascript on a html document to test it, it works perfectly, but when I install it as a userscript in chrome, it doesn't find the pattern.
I can't figure out how to get around this problem.
Dump innerHTML into console. If it looks fine then start building regexp from more generic (/\d+/) to more specific ones and output everything into a console. There is a bunch of different quote characters in different encodings, many different types of dashes.
[\d\s:-]* is not a very good choice because it would match " 1", " ". I would rather write something as specific as possible:
/" \d{4}-\d{2}-\d{2} \d{2}:\d{2}"/
(Also document.querySelector('div.the_selected_tag') would return null on your sample but you probably wanted to write class instead of id)
It's much more likely that tag.innerHTML doesn't contain what you think it contains.