How do I sort lines semi-lexiographically in emacs -- i.e., lexiographically, except that 3 gets sorted above 11? - emacs

How do I sort lines semi-lexiographically in emacs -- i.e., lexiographically, except that 3 gets sorted above 11? For example, I have a large collection of data, each entry of which looks like
[ 5, 3, 21, 1600000 ],
[ 3, 11, 21, 6400000 ],
[ 3, 3, 102, 1600000 ],
etc...
M-x sort-lines sorts this as
[ 3, 11, 21, 6400000 ],
[ 3, 3, 102, 1600000 ],
[ 5, 3, 21, 1600000 ],
but I would really like this sorted as
[ 3, 3, 102, 1600000 ],
[ 3, 11, 21, 6400000 ],
[ 5, 3, 21, 1600000 ],
Thanks!

sehe gives a good solution. Here it is in Emacs:
C-u M-| sort -k2n -k3n
Run that with your region selected and it will be replaced with the sort ouput!

I don't use emacs, but in vim I'd do:
%!sort -k2n -k3n
(possibly using the other key columns as well, I can't tell form the sample)
I'm not starting the editor war here... I'm just pretty sure that emacs allows you to filter through a shell command as well, so this will help!

With your data, the following will do what you want, though it is a bit laborious:
C-u 3 M-x sort-numeric-fields
C-u 2 M-x sort-numeric-fields
I don't know for sure that sort-numeric-fields is a stable sort, so it may not always work. And, obviously the above only sorts 2 numbers "deep" and you'll need to add C-u 4 M-x sort... if you want to sort by the 3rd number. The prefix argument starts with 2 because the first field is the [, and counting begins with 1.
You could also roll your own by calling sort-subr with the appropriate, lexographic, predicate. See the documentation for sort-subr for more details.

Related

Modify Flutter CupertinoPicker scroll to not continuously scroll?

Is there a way to modify CupertinoPicker scroll so that it's not possible to continuously scroll through a range. For example, right now if the range of values is 1-7, a user is able to continuously scroll 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, ... Is there a way to modify CupertinoPicker to have the scroll stop at the 1 and 7 (in this use case), so that there isn't a continuous scroll?
Update: found it; there's a property called "looping" (boolean)

What is the file identifier for Fortran 90 in VS code?

I was trying to add vertical rules for Fortran code in VS code, with the following lines
{
"[fortran]":
{
"editor.rulers": [0, 1, 5, 6, 79, 120]
},
}
in settings.json, I was able to make it work for .f files. However, the .f90 files do not get any vertical lines. It seems to me that the language identifier [fortran] is only for Fortran 77 code, but I can not find any clue of such an identifier for Fortran 90 code. Could someone point it out to me?
By the way, I would need a separate vertical rule setting for Fortran 90 anyway, because the four leading vertical rules are only needed for Fortran 77 code.
Thanks in advance!
If you use the extension Modern Fortran, then the ID for fortran language is changed, as shown in the contribution page of the extension.
ID Name file extension
FortranFreeForm Fortran90 .f90 .F90 .f95 .F95 .f08 .F08
fortran_fixed-form Fortran .f .F .f77 .F77 .for .FOR .fpp .FPP
So if you want to set rulers for fixed form files, use
"[fortran_fixed-form]": {
"editor.rulers": [1,5,6,72,80]
}
for f90, use
"[FortranFreeForm]": {
"editor.rulers": [0, 1, 5, 6, 79, 120]
}
I am unable to test this but possibly one of these settings helps:
"files.associations": {
"*.f90": "fortran", // or the next
// "fortran90": "fortran"
},
if just using fortran90 doesn't work as in
{
"[fortran90]": {
"editor.rulers":
[0, 1, 5, 6, 79, 120]
},
}
With v1.63 (and later version) of vscode, the fortran_fixed-form is already changed to FortranFixedForm instead.
So you (and for others newly-started searching for the answer) probably should use
"[FortranFixedForm]": {
"editor.rulers": [1,5,6,72,80]
}
instead.

Changing icon offset based on zoom level

I am trying to offset symbols of a symbol layer so that they don't interfere with a previous symbol layer (i.e. they don't overlap). I need to offset them as in both cases icon-allow-overlap needs to be set to true, as the symbols need to be viewable at all zoom levels. Ideally I'd like to do something like this:
"icon-offset": [
["zoom"],
12, [-16, 0],
22, [0, 0]
]
but that gives me an error:
array length 2 expected, length 5 found
Is there a way I can do what I want similar to what I was trying above? I know that icon-offset is not transitionable so that is why the above is failing.
Any help would be appreciated.
Thanks for your time.
The answer was to use a function:
"icon-offset": {
"stops": [
[12, [-16, 0]],
[22, [0, 0]]
]
}
More info on this can be found here

Swift: Is there an alternative to using nested dictionaries

I'm not a swift developer, sorry if this is a silly question, but is there a clean alternative to using nested dictionaries in swift or would this be the way to go? I've been trying different data structures for a while now, but I can't replicate something like this:
let locations = [
"west": [
"california": [
[ 3, 0, 1]
],
"oregon": [
[2, 0, 1]
]
],
"east": [
"new york": [
[ 3, 0, 2]
],
"florida": [
[2, 0, 2]
]
]
]
What I'm trying to achieve is a clean way to store this data, AND access it later.
I really like the way I can access it, but I can see how this dictionary can get lengthy and hard to read. I'm just looking for an alternative that will let me access the data just as easily as below, but maybe will look less ugly & be more scalable.
let oregonLocation = locations["west"]["oregon"]
Thanks!

Break from within a oneliner

Is it possible to simplify the second line keeping the code in three lines at the same time? current should have the "error" value.
for item in [ 1, 2, 3, undefined, 5, 6]
break if (current = if item? then item else "error") is "error"
console.dir current
I was trying to make something like that with no luck:
for item in [ 1, 2, 3, undefined, 5, 6]
current = if item? then item else "error", break
console.dir current
Here is a one liner, that's the best way I found to write it in coffee, but wouldn't in production, so my colleagues won't kill me while reading it.
break for item in [ 1, 2, 3, undefined, 5, 6] when (current = item ? 'error') is 'error'
console.dir current
There are actually many way to write this, with exactly the same output in Javascript.
Regards,