I have found Sublime Text's Reindent Lines feature to not being very reliable or helpful, especially when dealing with JSON files. Does anyone know of a way to make it work better? I know of plugins like "HTML-CSS-JS Prettify" but they only (and quite correctly, I might add) strive to work with HTML, CSS and JS respectively. I'd love to know if there is better way to indent/reindent all kinds of files.
Bonus points for any hint regarding converting from tabs to spaces (or vice versa) and reindenting correctly in one go.
pretty JSON package works perfectly for me.
You can specify the style of indentation from the package setting also. (which solves your second problem)
Related
When building applications, especially when using static linking and having a lot of dependences, I often feel that most of this 50-megabyte executable is just unused bloat, especially if consider only the mode I want.
Is there something that lets you run the program in various scenarious, collect data and build the program again (or tinker already compiled code) to remove the unvisited code (replacing things with abort)? If yes, how is it correctly called and where is it implemented?
I'm perfectly willing to use techniques, rather than tools.
What I've done for your problem is get a map file and just look through it.
There may well be a lot of methods for classes you doubt you need. Find out what references put them in there. Chances are it's just because somewhere something fancy was coded, like a bells-and-whistles container class, when something simple would do. Or a whole math library when all you needed was max.
After fixing that, the map file is smaller, and something else is the biggest thing in it, so you can do it all again.
And again...
This can cut out gobs of bloated binary.
I've searched high and low, but I can't seem to find a plugin that makes Sublime work similar to how Visual Studio formats my code as I type it.
For example, when I write a for loop, it looks something like this:
for(int i=0;i<value.length;i++) {
//loop body
}
As soon as I complete the loop body, Visual Studio will format it to be much more readable:
for (int i = 0; i < value.length; i++)
{
//loop body
}
Basically, it's just adding spaces around operators in this case, but it does much more. If I write horribly indented HTML/XML code, it corrects the indentation. Arrays and multiline conditionals become much more readable.
Are there any Sublime Text 3 plugins out there that do something similar to this? Everybody seems to highly recommend the "Reindent" command, which works for the HTML/XML formatting, but it doesn't space everything out in a consistent way. JsParen looks good, but it won't work for any other language that I use, namely PHP, and it's for ST2.
CodeFormatter is one possible option for PHP. It uses the PEAR PHP_Beautifier, which you'll need to install separately. There are a bunch of configuration options detailed in the README, so you should be able to find something that suits your needs.
For C/C++/C#/Java code, you can't go wrong with SublimeAStyleFormatter, a formatter that uses the popular AStyle rules. Again, there are many options available, check the .sublime-settings file for details.
HTML-CSS-JS Prettify is what I'm using currently for those languages. It requires node.js to work, so make sure you read through the instructions carefully.
Finally, you may think I'm being facetious, but I'm really not: pay attention to style when you're coding. I work a lot in Python, where the visual presentation of the code is actually part of the syntax. Code is meant to be read, by other developers as well as by machines, and it does no one any good to try and pound out poorly-formatted, unindented code while thinking "I'll just prettify it later." Maybe your formatter doesn't fix all your mistakes, or maybe you forget, or get lazy. If you focus on the look and structure of the code, you can more easily see how the different parts fit together, and perhaps catch some bugs before they can do any harm. Set a clear style guide for yourself, and stick with it. You'll be glad you did.
Open Sublime Text editor.
Press Ctrl + Shift + P.
In the menu select Package Control : install Package
Now select SublimeAStyleFormatter.
After installing the above extension, you may press Ctrl + Alt + F to format your current file.
I'm looking for a syntax in Sublime Text that highlights my Flex and Bison files (or lex/yacc) in a way that makes them readable... Sublime Text automatically chooses Lisp for Flex files, but that doesn't do the trick all that well. Any suggestions to try another syntax? Or is there a plugin somewhere that's useful (haven't found anything so far)?.
I haven't found one built specifically for Sublime, but I've found one for TextMate, which Sublime is compatible with.
Therefore, for Flex highlight, all you need to do is git clone the TextMate's syntax files to your Packages folder.
Regarding Bison, I've found a syntax for TextMate, but it didn't work very well for me. The one Vaklarados posted worked nicer with my source files.
The one thalesmello posted works well for Flex. For Bison, I've found this one - it's pretty minimal but it's a start:
https://github.com/Jackneill/sublime-text-packages/tree/master/Packages/Bison
Please let me know if you find something better!
edit: I take it back - the Flex one highlights start states & C/C++ code in pink and it looks quite terrible. For basic lex files it looks okay, but it needs work. :)
edit again: as sonu kumar pointed out, the project has been removed from github. For an alternative you could try the built-in OCamlyacc highlighting (pretty decent), or another alternative: https://bitbucket.org/artyom_smirnov/sublime-text-bison-highlighter (needs some work)
I'm using Sublime a lot more & do a fair bit of work in Flex/Bison, so I might get around to writing one... one day. :D
Indeed there are:
Flex
Bison
It's not so hard to write your own packages for non-typical languages. Just browse the source of other language syntax files and copy-paste-change what you need. Also raises your regex skills to a better level.
Install Package Control for Sublime Text.
I found this there:
https://sublime.wbond.net/packages/Bison
Do try it, I found it good enough for my use.
https://github.com/m-happy/Packages/blob/master/Flex/Flex.sublime-syntax
You can add this file to your sublime package.
In my Delphi program I want to display some information generated by the application. Nothing fancy, just 2 columns of text with parts of words color-coded.
I think I basically have two options:
HTML in a TWebbrowser
RTF in a TRichEdit.
HTML is more standard, but seems to load slower, and I had to deal with The Annoying Click Sound.
Is RTF still a good alternative these days?
Note: The documents will be discarded after viewing.
I would vote for HTML.
I think it is more future oriented. The speed would not concern me.
The question of HTML or RTF may be irrelevant. If they are just used for display purposes, then the file format doesn't matter. It's really just an internal representation. (Are any files even being saved to disk?) I think the question to ask is which one solves the problem with the least amount of work.
I would be slightly concerned that the browser control is changing all the time. I doubt the richedit control will change much. I would lean towards the richedit control because I think there is less that could go wrong with it. But it's probably not a big deal either way.
Have you considered doing an ownerdraw TListView?
I'd also use HTML. Besides, you just got an answer for the clicking sound in TWebBrowser.
If you'd rather not use TWebBrowser, take a look at Dave Baldwin's free HTML Display Components.
I would vote for HTML, too.
We started an app a while ago...
We wanted to
display some information generated by the application. Nothing fancy, just...
(do you hear the bells ring???)
Then we wanted to display more information and style it even more....
...someone decided, that RTF isn't enough anymore, but for backwards compatibility we moved on to MS Word over OLE-Server. That was the end of talking about performance anymore.
I think if we would have done that in HTML it would be much faster now.
RTF is much easier to deal with, as the TRichEdit control is part of every single Windows installation, and has much less overhead than TWebBrowser (which is basically embedding an ActiveX version of Internet Explorer into your app).
TRichEdit is also much easier to use to programmatically add text and formatting. Using the SelStart and SelLength, along with the text Attributes, makes adding bolding and italics, setting different fonts, etc. simple. And, as Re0sless said, TRichEdit can easily be printed while TWebBrowser makes it more complicated to do so.
I would vote RTF as I dont like the fact TWebBrowser uses Internet explorer, as we have had trouble with this in the past on tightly locked down computers.
Also TRichEdit has a print method build in, where as you have to do all sorts of messing about to get the TWebBrowser to print.
Nobody seems to have mentioned a reporting component yet. Yes, it is overkill right now, but if you use it anyway (and maybe you already have got some reporting to do in your app, so the component is already included) you can just display the preview and allow to print / export to pdf later, if it makes any sense. Also if you later decide that you want to have a fancier display there is nothing holding you back.
If both HTML and RTF won't satisfy your need, you could also use an open source text/edit component that supports coloring words or create your own edit component based on a Delphi component.
Another alternative to the HTML browser is the "Embedded Web Browser" components which I used a few projects for displaying html documents to the user. You have complete control over the embedded browser, and I don't recall any clicks when a page is loaded.
I vote for HTML also
RTF is good only for its editor, else then you'd better go standard.
RTF offers some useful text editing options like horizontal tabulator which are not available in HTML. Automatic hyperlink detection is also a nice extra. But I think I would prefer HTML, if these features are not required.
I vote for HTML.
Easier to generate programmatically.
Widely supported.
Since you don't need WYSIWYG capabilities I think HTML advantages trump RTF. Moreover, should the need to export generated data for further, WP-like editing arise, remember that major word processor can open and convert HTML files.
Use HTML, but with 'Delphi Wrapper for Chromium Embedded' by Henri Gourvest , Chromium embedded uses the core that powers Google Chrome.
Don't use TWebBrowser, I'm suffering from all programs that use IE's web control - the font is too small on my 22' monitor with a 1920x1080 resolution, I use Windows 7 and my system's DPI is 150% (XP mode), I tried everything to tweak trying to fix that, no luck...
I am looking for a tool to display/track changes in text a little bit like it is done on stackoverflow when a question is edited. Does anybody know of a tool to achieve that?
You may want to use diff for that.
If you can use PHP on your server there's a handy pear package to perform the task you require. Here's an example :
https://web.archive.org/web/1/http://articles.techrepublic%2ecom%2ecom/5100-10878_11-6174867.html
There's actually a actually Javascript implementations outhere as well, not tested though:
http://ejohn.org/projects/javascript-diff-algorithm/
http://aignes.net/
Commercial tool though. I have no idea of a F/OSS alternative.
A copy of my own answer from here.
What about DaisyDiff (Java and PHP vesions available).
Following features are really nice:
Works with badly formed HTML that can be found "in the wild".
The diffing is more specialized in HTML than XML tree differs. Changing part of a text node will not cause the entire node to be changed.
In addition to the default visual diff, HTML source can be diffed coherently.
Provides easy to understand descriptions of the changes.
The default GUI allows easy browsing of the modifications through keyboard shortcuts and links.