I know how to sort lines in Sublime (ctrl+p "sort"). The problem is it doesn't sort some characters as I want, namely åäö.
Is there some way to change how sublime orders the text? Perhaps by a specific locale? It would also be interesting to be able to sort V and W as being equal.
Example: I want the following words to be sorted in this order:
bår
bär
bör
but Sublime sorts it like this:
bär
bår
bör
There has been a similar request logged on ST's issue tracker: https://github.com/SublimeTextIssues/Core/issues/1324
One of the ST developers replied:
Sorting in Python 3 uses Unicode code points as the basis for sorting. Sublime Text doesn't know what language your encoding represents, so it doesn't use locale-based sorting rules.
This seems like it is probably best solved by a package dedicated to providing locale-based collation rules.
Using https://packagecontrol.io/packages/PackageResourceViewer, we can see that the case_sensitive_sort method in Packages/Default/sort.py uses Python's built in list.sort method. Typing the following into ST's Python console (View menu -> Show Console), we get the same result as you have shown:
>>> a = ['bår', 'bär', 'bör']
>>> a.sort()
>>> a
['bär', 'bår', 'bör']
So the answer is that there is no setting to configure the sorting behavior, and nor is there likely to be in future. However, according to https://docs.python.org/3/howto/sorting.html#odd-and-ends, it is possible to use a locale-aware sort using locale.strxfrm as a key function.
Let's try. On Windows, I had to use
>>> import locale
>>> locale.setlocale(locale.LC_COLLATE, 'sve')
'Swedish_Sweden.1252'
to get Python to use a Swedish locale - as per https://stackoverflow.com/a/956084/4473405
>>> a.sort(key=locale.strxfrm)
>>> a
['bår', 'bär', 'bör']
Using this knowledge, you might choose to change the case_sensitive_sort method, so that ST's built in sort functionality (Edit menu -> Sort Lines (Case Sensitive)) will use the locale aware sort key. Note that saving the sort.py file opened from PackageResourceViewer will create an override, so that if future builds of ST include changes to sort.py, you won't see them until you delete the override (which you can do by finding the file using the Preferences menu -> Browse Packages -> Default. You can reapply your changes afterwards, if appropriate, using the exact same steps.)
You can also change the case_insensitive_sort method from
txt.sort(key=lambda x: x.lower())
to
txt.sort(key=lambda x: locale.strxfrm(x.lower()))
Note that, if your correct locale isn't picked up automatically (it probably defaults to C), then setting the locale in this (case_sensitive_sort) method isn't recommended, even if, immediately afterwards, you restore it back to what it was beforehand - so use at your own risk.
It is generally a bad idea to call setlocale() in some library routine, since as a side effect it affects the entire program. Saving and restoring it is almost as bad: it is expensive and affects other threads that happen to run before the settings have been restored.
You could instead add the following to the end of the sort.py file:
def plugin_loaded():
import locale
locale.setlocale(locale.LC_COLLATE, '')
which will, when the plugin is loaded, allow Python to infer the locale from your LANG env var, as per https://docs.python.org/3/library/locale.html#locale.setlocale. The advantage being you only set it once, and hopefully won't introduce any problems with other plugin code executing at the same time.
Happy sorting!
Related
As u can see on the image, after every line, an automatic output appears. I want do disable this. I do not intend to use it as a workaround editor, the problem is that on some functions this output is more than some screens big and is hard to look at the expected result.
The default CLI, IIRC, uses the standard Node REPL, but does not provide a trivial way to customize it.
You could start your own REPL and provide options as described in the REPL docs, specifically focusing on:
eval
ignoreUndefined
The easiest solution is to append something to whatever is returning the long value, e.g., if there's a function called foo that returns an object that spans pages, like:
> foo()
// countless lines of output
Tack on something to the command, like:
> foo(); null
null
How does one convert an ASTNode (or at least a CompilationUnit) into a valid piece of source code?
The documentation says that one shouldn't use toString, but doesn't mention any alternatives:
Returns a string representation of this node suitable for debugging purposes only.
CompilationUnits have rewrite, but that one does not work for ASTs created by hand.
Formatting options would be nice to have, but I'd basically be satisfied with anything that turns arbitrary ASTNodes into semantically equivalent source code.
In JDT the normal way for AST manipulation is to start with a basic CompilationUnit and then use a rewriter to add content. Then ASTRewriteAnalyzer / ASTRewriteFormatter should take care of creating formatted source code. Creating a CU just containing a stub type declaration shouldn't be hard, so that's one option.
If that doesn't suite your needs, you may want to experiement with directly calling the internal org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteFlattener.asString(ASTNode, RewriteEventStore). If not editing existing files, you may probably ignore the events collected in the RewriteEventStore, just use the returned String.
I'm using PHPStorm EAP version PS-138.940.
I have code as follows:
Config(__NAMESPACE__."\ObjectsToIdentifiers")->oldTables = array('Modules\Old\Model\DeviceStock','Modules\Old\Model\ProductPack','Modules\Old\Model\SpareStock','Modules\Old\Model\ConsumStock');
The functionality is irrelevant in this case. Important are the entries in the array. These are fully qualified class names - the leading / is omitted, but adding it doesn't solve my problem. I want to be able to click inside one of the string literals, press Ctrl+B and be redirected to the class definition.
Note that this works in ExtJS (javascript framework) where a string literal like
"MyApp.namespace.view.MyComponent"
will take me there.
Is there any way to manually configure this or do I have to submit a feature request. If so, how can I do that?
Update 1:
I created a feature request on JetBrains Youtrack: http://youtrack.jetbrains.com/issue/WI-24262
Came across this question looking for something in Storm that would let me quickly convert "\Some\ClassName" to Some\ClassName::class like an Intention or plugin, but so far have found nothing.
i'm surprised the ::class static property hasn't been mentioned. It produces the FQN of the Class, and resolves from import aliases.
The following should be a legit rewrite that the IDE can resolve:
// Same __NAMESPACE__, so no prefix needed
Config(ObjectsToIdentifiers::class)
->oldTables = [
Modules\Old\Model\DeviceStock::class,
Modules\Old\Model\ProductPack::class,
Modules\Old\Model\SpareStock::class,
Modules\Old\Model\ConsumStock::class
];
// or, if you import the classes:
use Modules\Old\Model\DeviceStock as OldDeviceStock;
// you can refer to
OldDeviceStock::class;
Unfortunately, right now if you jump-to-definition of the alias, Storm won't take you to the actual class, but where the alias is defined. Not terribly helpful, but gets you halfway since the actual class is right there.
I have a LaTeX document where I'd like the numbering of floats (tables and figures) to be in one numeric sequence from 1 to x rather than two sequences according to their type. I'm not using lists of figures or tables either and do not need to.
My documentclass is report and typically my floats have captions like this:
\caption{Breakdown of visualisations created.}
\label{tab:Visualisation_By_Types}
A quick way to do it is to put \addtocounter{table}{1} after each figure, and \addtocounter{figure}{1} after each table.
It's not pretty, and on a longer document you'd probably want to either include that in your style sheet or template, or go with cristobalito's solution of linking the counters.
The differences between the figure and table environments are very minor -- little more than them using different counters, and being maintained in separate sequences.
That is, there's nothing stopping you putting your {tabular} environments in a {figure}, or your graphics in a {table}, which would mean that they'd end up in the same sequence. The problem with this case (as Joseph Wright notes) is that you'd have to adjust the \caption, so that doesn't work perfectly.
Try the following, in the preamble:
\makeatletter
\newcounter{unisequence}
\def\ucaption{%
\ifx\#captype\#undefined
\#latex#error{\noexpand\ucaption outside float}\#ehd
\expandafter\#gobble
\else
\refstepcounter{unisequence}% <-- the only change from default \caption
\expandafter\#firstofone
\fi
{\#dblarg{\#caption\#captype}}%
}
\def\thetable{\#arabic\c#unisequence}
\def\thefigure{\#arabic\c#unisequence}
\makeatother
Then use \ucaption in your tables and figures, instead of \caption (change the name ad lib). If you want to use this same sequence in other environments (say, listings?), then define \the<foo> the same way.
My earlier attempt at this is in fact completely broken, as the OP spotted: the getting-the-lof-wrong is, instead of being trivial and only fiddly to fix, absolutely fundamental (ho, hum).
(For the afficionados, it comes about because \advance commands are processed in TeX's gut, but the content of the .lof, .lot, and .aux files is fixed in TeX's mouth, at expansion time, thus what was written to the files was whatever random value \#tempcnta had at the point \caption was called, ignoring the \advance calculations, which were then dutifully written to the file, and then ignored. Doh: how long have I know this but never internalised it!?)
Dutiful retention of earlier attempt (on the grounds that it may be instructively wrong):
No problem: try putting the following in the preamble:
\makeatletter
\def\tableandfigurenum{\#tempcnta=0
\advance\#tempcnta\c#figure
\advance\#tempcnta\c#table
\#arabic\#tempcnta}
\let\thetable\tableandfigurenum
\let\thefigure\tableandfigurenum
\makeatother
...and then use the {table} and {figure} environments as normal. The captions will have the correct 'Table/Figure' text, but they'll share a single numbering sequence.
Note that this example gets the numbers wrong in the listoffigures/listoftables, but (a) you say you don't care about that, (b) it's fixable, though probably mildly fiddly, and (c) life is hard!
I can't remember the syntax, but you're essentially looking for counters. Have a look here, under the custom floats section. Assign the counters for both tables and figures to the same thing and it should work.
I'd just use one type of float (let's say 'figure'), then use the caption package to remove the automatically added "Figure" text from the caption and deal with it by hand.
I always have difficulty in finding all available alternative ways to produce a specific graph, either one that I have already decided to use (looking for different variations) or one that I have not yet thought of.
The R Graphical Manual site provides a complete list of samples of R's graphics functions, however it's easier for me to search providing a package name (how else -for example- can I get a resultset including superbarplot function, when I want to look for barplots?. Let alone that the superbarplot graph does not appear in the results even if I try searching for it's package: UsingR)
The R-SAS-SPSS Add-on Module Comparison - and especially on topic Graphics, Static in the table provided - gave me the idea that it would be nice to have a place where all relevant packages are listed by topic.
Do you have any idea about something like that?
If you're interested in learning about all the possible graphics you can make, you should learn about the grammar of graphics, and (my) implementation of it in R: ggplot2.
Your question, or the general pattern anyway, was clearly a primary use case for the design of the sos package.
sos actually goes one step further that your question requires by identifying particular functions with packages; in addition, it ranks the results by relevance (by default, you can change the default behavior via the "sortby" parameter, e.g., sortby="Date")
Here's how it works:
most of this package's functionality is exposed via the "findFn" command
for instance, if you want a list of all functions and the parent package related to scatter plots:
findFn("scatter plot", maxPages=2, sortby="TotalScore")
This returns a dataframe formatted as HTML table and delivered in your default browser (if you don't want it to pop-up immediately, then just bind the function call to a variable and then call the variable when you're ready)
The right-most column of the dataframe/HTML page is "Description and Link". Clicking an entry in that column opens another tab in your browser (according to the user-set preferences set in your browser) with the complete R help page for that function.
The results from the function call above show, for instance, that the functions for plotting data in a 'scatter plot' format are found in the following packages:
ade4 (function: scatter)
IDPmisc (functions: ipairs, iplots)
GGally (function: ggally_points)
PerformanceAnalytics (function:
chart.Scatter)
mclust (function: clPairs)
Another example:
findFn("boxplot", maxPages=2, sortby="TotalScore")
identifies these (among others) packages/functions for plotting boxplots:
sfsmisc (function: boxplot.matrix)
aplpack (function: boxplot2D)
NADA (function: boxplot-methods)
StatDA (function: rg.boxplot)
plotrix (function: gap.boxplot)
gplots (function: boxplot.n)
multcompView (function:
multcompBoxplot)
oligo (function: boxplot)
Have you seen the R Graph Gallery ?
Other than that, you may have to index all the source code of CRAN packages to search efficiently...
these are good memory-joggers. I second the ggplot2 recommend, also recommend looking thru CRAN views:
http://cran.r-project.org/web/views/
http://cran.fhcrc.org/web/views/Graphics.html
(this mirror seems faster in west coast US)
http://dataspora.com/archive/2009/seminar/Survey_of_R_Graphics_by_Driscoll_Dataspora_Jun2009.pdf
http://zoonek2.free.fr/UNIX/48_R/04.html
(possibly world's longest webpage)
http://www.stat.auckland.ac.nz/~ihaka/120/lectures.html
Ihaka's lectures notes