How do I change CapsLock to QwertyLock in X11? - x11

I type with the dvorak keyboard layout. It would be handy if I could change CapsLock (which I never use) to be QwertyLock. Using xkbcomp, I was able to get an xkb file that almost works:
type "QWERTYCAPS" {
modifiers= Shift+Lock;
map[Shift]= Level2;
map[Lock]= Level3;
map[Shift+Lock]= Level4;
level_name[Level1]= "Base";
level_name[Level2]= "Caps";
level_name[Level3]= "Qwerty";
level_name[Level4]= "QwertyCaps";
};
...
key <AC01> {
type= "QWERTYCAPS",
symbols[Group1]= [ a, A, a, A ]
};
key <AC02> {
type= "QWERTYCAPS",
symbols[Group1]= [ o, O, s, S ]
};
This works except for the two letters 'a' and 'm', which are in the same position in qwerty and dvorak. Apparently there is some special magic in xkb that changes the interpretation if the letter is the same with and without CapsLock.
So, despite what I asked, I got:
Mod normal, shift, caps, shift+caps
Ask a, A, a, A
Got a, A, A, A
So, the CapsLock case is uppercase despite asking for lowercase. In fact, changing letter from either the normal or caps case makes it give the requested character.
Is there a way to override this behavior so I get a lowercase 'a'? Failing that, what is the right approach? I see that there are groups, so I could make qwerty group2. But, then I'd have to change CapsLock into GroupLock. I tried that briefly as an experiment, but it didn't work, and the CapsLock indicator didn't turn on either.
So, what is the easiest way to get QwertyLock?

setxkbmap -layout us,us -variant ,dvorak -option grp:caps_toggle
Or the same thing in the config file (/etc/X11/xorg.conf.d/10-keyboard.conf):
Section "InputClass"
Identifier "system-keyboard"
MatchIsKeyboard "on"
Option "XkbLayout" "us,us"
Option "XkbModel" "pc104"
Option "XkbVariant" ",dvorak"
Option "XkbOptions" "grp:caps_toggle"
EndSection

Related

What is %P in Tcl?

I saw this code en Tcl:
entry .amount -validate key -validatecommand {
expr {[string is int %P] || [string length %P]==0}
}
I know that it's an entry validation but, what does "%P" in that code? I was looking in the Tcl's doc but I didn't find nothing.
I think this is another way to do it but it has the same symbols:
proc check_the_input_only_allows_digits_only {P} {
expr {[string is int P] || [string length P] == 0}
}
entry .amount \
-validate key \
-validatecommand {check_the_input_only_allows_digits_only %P}
The tcl-tk page for entry says
%P
The value of the entry if the edit is allowed. If you are configuring the entry widget to have a new textvariable, this will be the value of that textvariable.
https://www.tcl.tk/man/tcl8.4/TkCmd/entry.html#M25
I think this is another way to do it but it has the same symbols:
You're close. You just have to use $ in a few places because you're just running a procedure and that's as normal for using parameters to procedures.
proc check_the_input_only_allows_digits_only {P} {
expr {[string is int $P] || [string length $P] == 0}
}
entry .amount \
-validate key \
-validatecommand {check_the_input_only_allows_digits_only %P}
It's recommended that you write things like that using a procedure for anything other than the most trivial of validations (or other callbacks); putting the complexity directly in the callback gets confusing quickly.
I recommend keeping validation loose during the input phase, and only making stuff strictly validated on form submission (or pressing the OK/Apply button, or whatever it is that makes sense in the GUI) precisely because it's really convenient to have invalid states there for a while in many forms while the input is being inputted. Per-key validation therefore probably should be used to only indicate whether it's believed that form submission will work, not to outright stop even transients from existing.
The string is int command returns true for zero-length input precisely because it was originally put in to work with that validation mechanism. It grinds my gears that actual validation of an integer needs string is int -strict. Can't change it now though; it's just a wrong default…
entry .amount -validate key -validatecommand {string is int %P}

Verilog, using enum with don't cares

Is it possible to use enum with don't cares? I've tried the following
typedef enum reg [31:0] {
BLTZ = 32'b000001_?????_00000_????????????????,
BGEZ = 32'b000001_?????_00001_????????????????,
BEQ = 32'b000100_?????_?????_????????????????,
BNE = 32'b000101_?????_?????_????????????????,
.
.
.
Then using the syntax given by doulos.com, I tried the following to see if I can get an "ADD" instruction to be displayed on the waveform viewer
op_mne_e op_mnemonic;
assign op_mnemonic = op_mne_e'(32'b000000_?????_?????_?????_?????_10000);
but what I see is
000000zzzzzzzzzzzzzzzzzzzz10000
Is it possible to have something similar to a casez for enum?
I have edited the tags to this question, because you are asking about System-Verilog, not Verilog. What we call Verilog is now a subset of the System-Verilog standard, IEEE-1800.
In System-Verilog, enumeration types have an underlying base type. By default this type is int, which is a 2-state type (each bit can only take the values 0 or 1). You can specify other base types if you wish. Each member of the enumeration type is represented by a different value of the type of the base type.
You have specified a 4-state, 32-bit base type: reg [31:0]*. Those 4 states are 0, 1, Z (or ?) and X. So, each member of the enumeration type is represented by a 4-state value, ie some combination of 0, 1, Z (or ?) and X. But, when you display the value with a "%b" format specifier, that's what you get: you get the underlying 4-state value (using Zs, not ?s).
http://www.edaplayground.com/x/3khr
In a casez statement, a Z or a ? represents a don't care. So, you can use an such an enum with a 4-state base type in a casez statement if you wish:
casez (op_mnemonic)
BLTZ : $display("BLTZ");
BGEZ : $display("BGEZ");
BEQ : $display("BEQ");
BNE : $display("BNE");
endcase
but, as we're speaking System-Verilog here, why not use case ... inside instead?
case (op_mnemonic) inside
BLTZ : $display("BLTZ");
BGEZ : $display("BGEZ");
BEQ : $display("BEQ");
BNE : $display("BNE");
endcase
http://www.edaplayground.com/x/4g3J
case ... inside is usually considered safer than the old casez, because it exhibits asymmetrical wildcard matching. In other words, unlike in a casez, in a case ... inside an X or Z (or ?) in the test expression (op_mnemonic in this case) does not act like a don't care (but does in the branch expression, of course).
*It would be more usual in System-Verilog to specify logic [31:0], which is identical, but logic is usually used in System-Verilog in preference to reg.
If you want the labels of your enum variable displayed in the waveform, you will need to set the radix to display it. Most tools default to displaying in binary. SystemVerilog has a number of operators that treat 'z' as a don't care (casez is one of them) so '?' is allowed as part of a numeric literal in place of a 'z'. However, that '?' gets immediately converted over to a 'z' and you will never see a '?' printed out.
If you are trying to assign a value to an enum and have it decode the instruction and pick a matching label, that won't work. You would need to loop the the enum values and use the wildcard equality operator ==? to find a match.
But if you are only doing this to get a label in the waveform, Modelsim/Questa has a radix define command that will decode the instruction for you.

How to reference variables for the co-ordinates used by the dragFromToForDuration method

I have a simple routine to delete a number of records from a screen by swiping left on them. It only deletes records in a certain state, i.e. ready to submit. The top record might not necessarily be in that state, so I cannot use a fixed y co-ordinate. Instead, I use the y co-ordinate of the first record that I find in that state.
Here is the code I am trying to execute:
while query("* marked:'SUBMIT'").count > 0
y = query("UIButtonLabel marked:'SUBMIT'")[0]["rect"]["center_y"]
uia('target.dragFromToForDuration({x:"481.5", y:"#{y}"}, {x:"350", y:"#{y}"}, "1")')
touch("* marked:'Delete'")
touch("view:'_UIAlertControllerActionView' marked:'Delete'")
end
The problem is that the variable y seems to be inaccessible buried within all those quote marks. The method succeeds, but the UI does not respond as expected. I tried the method in the console. When I substitute the variable for an integer, it works as expected, but the variable does not. I tried making it a global variable with no difference. I tried using a tap command instead to tap the button, which again failed silently.
irb(main):006:0> y = query("UIButtonLabel marked:'SUBMIT'")[0]["rect"]["center_y"]
218.5
irb(main):007:0> y
218.5
irb(main):008:0> uia('target.dragFromToForDuration({x:"481.5", y:"#{y}"}, {x:"350", y:"#{y}"}, "1")')
{
"status" => "success",
"index" => 1
}
Is there a way to reference a variable within this method in this way?
Strings created with '' will not perform interpolation. So your '...#{y}...' is literally going to have that text in it.
You can use double quotes (""), but then you'd have to escape everything:
uia("target.dragFromToForDuration({x:\"481.5\", y:\"#{y}\"}, {x:\"350\", y:\"#{y}\"}, \"1\")")
You can use %Q to avoid the escaping:
uia(%Q(target.dragFromToForDuration({x:"481.5", y:"#{y}"}, {x:"350", y:"#{y}"}, "1")))
I don't know this library, but it may also work like this:
uia("target.dragFromToForDuration({x:'481.5', y:'#{y}'}, {x:'350', y:'#{y}'}, '1')")

help on formatting my notebook back as it was. From 'code' style to Input style

I did something silly I think.
I changed my cell style to 'code' and starting changing indentation and moving code around the way I like to, (since it is easier to do that in 'code' cell style, as the notebook interface does not get in the way). But after trying it for a while, I find other issues with this with this style.
Now I changed the style back to 'input'. But now all the code has all these extra spaces in them, and code does not look good any more as it was in the original 'input' style.
I made too many edits and manual formatting to the code.
Is there a way to tell Mathematica to 'auto-format' the code back to the default input style? i.e. remove all the extra space where needed, realign things the way they were, etc...
If I have to do this by hand, will take me forever. I could not find such as option. I tried many options there on the menues, and nothing helps.
ps. in Matlab, this is trivial to do, just select all code, then select 'smart-ident' from a menu, and it will do that.
ps. I tried emacs Mathematica mode, and they have no prety-print either.
EDIT
I tried these: Select cell, then Cell->Convert To, and selected 'InputForm' and also selected 'input Form Display'.
This seems to have removed all the extra white spaces. Which is good. Now I only need to go and just hit returns in all the right places to get it back to the original form.
At least this is much better than having to delete spaces by hand. So, disaster seems to be contained for now.
EDIT
screen shot after converting 'code' style back to 'standard form'. very hard to read.
thanks,
EDIT
To make sure what the question is, given some Mathematica code, which is 'mangled' up, and formatted by hand with manual space inserting and manual inserting of returns all over, and now if I just put it in a notebook with default style, I want it to smart-indent back to the default setting, and have all the line-wrapping, etc... as if it was originally written in the default style. i.e. pretty-print to what it would be if it was written using the 'input' code style.
here is a small function as an example that I formatted by hand. It will look not well formatted even more when I paste it here. If you copy this code to your notebook, default style, then how to auto-format it back to the default settings without doing it by hand?
If[Abs#omega <= $MachineEpsilon,
(
data = {{0, 0}};
p = ListPlot[data, Sequence#plotOptions]
),
(
driverPeriod = 2. Pi/Abs#omega;
valuesOfDriverAmplitude =
Range[aStart, aStart + aLen, aLen/aIntervals];
timeValues =
Range[initialDriverPeriod*driverPeriod,
finalDriverPeriod*driverPeriod, driverPeriod ];
data =
Table[0, {Length[valuesOfDriverAmplitude]}, {Length[timeValues ]}];
total = Length[timeValues]*Length[valuesOfDriverAmplitude];
bifurcationProgress = 0.;
count = 0.;
Do[
(
{x1, x2, x3} =
solve[q, valuesOfDriverAmplitude [[i]], omega, phase,
initialDriverPeriod*driverPeriod,
(finalDriverPeriod)*driverPeriod, x10,
x20, isDamped, 4, 4];
currentTorqueAmplitude = valuesOfDriverAmplitude[[i]];
Do[
(
data[[i, j]] = {currentTorqueAmplitude, x2[timeValues[[j]] ]};
count += 1;
bifurcationProgress = count/total;
),
{j, 1, Length[timeValues]}
]
),
{i, 1, Length[valuesOfDriverAmplitude]}
];
p = ListPlot[Flatten[data, 1], Sequence#plotOptions]
)
];
EDIT
6 PM
1) Saved the notebook as m file (mathematica package) called aclFix.m
2) then I did the following
str=Import["aclFix.m")
also tried
str=Get["aclFix.m"];
but in both cases, all what I get is the actual Manipulate on the screen showing up. And the command shown below (StringReplace etc....) does not work on it as it is not a string. I get lots of errors, such as
StringReplace::strse: String or list of strings expected at position 1 in
StringReplace[Manipulate[<<1>>,
{{aStart,0.9,},0,2,0.01,ImageSize->Tiny,ImagePadding->0,ControlPlacement->1},
{{aLen,0.2,},0.01,2,0.01,ImageSize->Tiny,ImagePadding->0,ControlPlacement->2},
<<45>>,SynchronousUpdating->False,ContinuousAction->False,<<6>>],
{(x_/;x==FromCharacterCode[32])..->,(x_/;x==<<17>>[9])..->}]. >>
may be I misunderstood the solution..
EDIT
1 AM
I exported the notebook as "m" file, Imported it back as
str = Import["aclFix.m", "Text"];
then
code=StringReplace[str, {(x_ /; x == FromCharacterCode[32]) .. ->
"", (x_ /; x == FromCharacterCode[9]) .. -> ""}]
then
Export["fix.m", code]
But it is still a string. When I import it back, it is still a string. I tried
ToExpression[code] but it did nothing. How do convert it to actual code? This is an example looking at the .m using text editor. I used the above code to test it on. May be we are getting close here?
Will look more at it.
(* Created by Wolfram Mathematica 8.0 for Students - Personal Use Only : www.wolfram.com *)
"If[Abs#omega<=$MachineEpsilon,\n(\ndata={{0,0}};\np=ListPlot[data,Sequence#p\
lotOptions]\n),\n(\ndriverPeriod=2.Pi/Abs#omega;\nvaluesOfDriverAmplitude=\nR\
ange[aStart,aStart+aLen,aLen/aIntervals];\ntimeValues=\nRange[initialDriverPe\
riod*driverPeriod,\nfinalDriverPeriod*driverPeriod,driverPeriod];\n\ndata=\nT\
able[0,{Length[valuesOfDriverAmplitude]},{Length[timeValues]}];\ntotal=Length\
[timeValues]*Length[valuesOfDriverAmplitude];\nbifurcationProgress=0.;\ncount\
=0.;\n\nDo[\n(\n{x1,x2,x3}=\nsolve[q,valuesOfDriverAmplitude[[i]],omega,phase\
,\ninitialDriverPeriod*driverPeriod,\n(finalDriverPeriod)*driverPeriod,x10,\n\
x20,isDamped,4,4];\ncurrentTorqueAmplitude=valuesOfDriverAmplitude[[i]];\nDo[\
\n(\n\ndata[[i,j]]={currentTorqueAmplitude,x2[timeValues[[j]]]};\ncount+=1;\n\
bifurcationProgress=count/total;\n),\n{j,1,Length[timeValues]}\n]\n),\n{i,1,L\
ength[valuesOfDriverAmplitude]}\n];\n\np=ListPlot[Flatten[data,1],Sequence#pl\
otOptions]\n)\n];"
It would be useful to have a sample of the code (not just visual). In the meantime, maybe this will work:
Save your code in an m-file. Then import it into the variable str, then run this
StringReplace[str,
{
(x_ /; x == FromCharacterCode[32]) .. -> "",
(x_ /; x == FromCharacterCode[9]) .. -> ""
}
]
and save the result into another m-file. What this does is to remove all series of one or more spaces or tabs. Thus, if for instance
str =
"f[
g[
u ]]"
(which contains both spaces and tabs) then running the code I gave gives
f[
g[
u]]
and you can save this back into an m-file.
If this doesn't do what you want then maybe if you provide a piece of code that is formatted the wrong way would help.
(or you could try with the interactive regexp-builder in emacs: m-x re-builder, but if you're not familiar with regexps it's probably not worth it)
How about something like
nb = EvaluationNotebook[];
NotebookFind[nb, "Code", All, CellStyle]
FrontEndExecute[{FrontEndToken[nb, "Style", "Input"]}]
FrontEndExecute[{FrontEndToken[nb, "SelectionConvert", "StandardForm"]}]
This will convert all "Code" cells to "Input" cells and convert their contents to "StandardForm".
For a list of all FrontEndTokens see belisarius' answer here.
Another option that follows from the recent comment of Rolf Mertig and Alt-Click (or Ctrl-Alt-Click in linux) on a "Code" cell to select all "Code" cells. Then use the Format menu to convert to "Input" style cells and then the Cell menu to Convert To StandardForm. (Alternatively that is Alt-Click on a "Code cell" followed by Alt-9 and then Ctrl-Shift-N)

What is the advantage of this peculiar formatting?

I've seen this format used for comma-delimited lists in some C++ code (although this could apply to any language):
void function( int a
, int b
, int c
)
I was wondering why would someone use that over a more common format such as:
void function (int a,
int b,
int c
)
That's a pretty common coding style when writing SQL statements:
SELECT field1
, field2
, field3
-- , field4
, field5
FROM tablename
Advantages:
Lets you add, remove, or rearrange fields easily without having to worry about that final trailing comma.
Lets you easily comment out a row (TSQL uses "--") without messing up the rest of the statement.
I wouldn't think you'd want to rearrange parameter order in a function as frequent as you do in SQL, so maybe its just somebody's habit.
The ability to comment one of them out will depend on the specific language being used. Not sure about C++. I know that VB.Net wouldn't allow it, but that's because it requires a continuation character ( _ ) to split statements across lines.
It is easier to add a parameter at the end starting by duplicating previous parameter (line).
Make sense when you are sure that first parameter will never change, which is often the case.
Malice?
Seriously though, it's hard to account for formatting style sometimes. It's largely a matter of personal taste. Personally, I think that both forms are a little nasty unless you're seriously restricted in terms of line-length.
Another advantage is that in the first example you could comment-out either the B or C lines, and it will stay syntactically correct. In the second example, if you tried to comment out the C line, you'd have a syntax error.
Not really worth making it that ugly, if you ask me.
The only benefit I would see, is when you add a parameter, you just have to copy and paste the last line, saving you the extra couple key strokes of editing comma position and such.
Seems to me like a personal choice.
No reason, I suspect it's just a matter of personal preference.
I'd personally prefer the second one.
void function (int a,
int b,
int c
)
The only benefit I would see, is when you add a parameter, you just have to copy and paste the last line, saving you the extra couple key strokes of editing comma position and such.
The same goes for if you are removing the last parameter.
When scanning the file quicky, it's clear that each line that begins with a comma is a continuation of the line above it (compared to a line that's simply indented further than the one above). It's a generalization of the following style:
std::cout << "some info "
<< "some more info " << 4
+ 5 << std::endl;
(Please note, in this case, breaking up 4 + 5 is stupid, but if you have a complex math statement it may be necessary).
I use this a lot, especially when dealing with conditionals such as if, for, and while statements. Because it's also common for one-line conditionals to omit the curlies.
std::vector<int> v = ...;
std::vector<int> w = ...;
for (std::vector<int>::iterator i = v.begin()
, std::vector<int>::iterator j = w.begin()
; i != v.end() && j != w.end()
; ++i, ++j)
std::cout << *i + *j << std::endl;
When you add another field to the end, the single line you add contains the new comma, producing a diff of a single line addition, making it slightly easier to see what has changed when viewing change logs some time in the future.
It seems like most of the answers center around the ability to comment out or add new parameters easily. But it seems that you get the same effect with putting the comma at the end of the line rather than the beginning:
function(
int a,
int b,
// int c,
int d
)
You might say that you can't do that to the last parameter, and you would be right, but with the other form, you can't do it to the first parameter:
function (
// int a
, int b
, int c
, int d
)
So the tradeoff is being able to comment out the first parameter vs. being able to comment out the last parameter + being able to add new parameters without adding a comma to the previous last parameter.
I know when I wrap and's in a sql or if statement I try to make sure the and is the start of the next line.
If A and B
and C
I think it makes it clear the the C is still part of the if. The first format you show may be that. But as with most style questions the simple matter is that if the team decides on one style then it should be adhered to.

Resources