Emacs, toggle a specific window - windows

I have a buffer that I want to "toggle" opening in a window in emacs on a keypress.
For example:
________________ ________________ ________________
| | | | | | |
| | | | | | |
| | | | | | |
| W | -> | S | W | -> | W |
| | <f3> | | | <f3> | |
| | | | | | |
---------------- ---------------- ----------------
Where S in the left hand side window is a specific buffer.
The problem arises that this should happen regardless of what the window structure of W is. If W has a couple of different windows in it, pressing <F3> should still create a new window at the edge of the screen, and put the specific buffer in it, and then it should take it away.
I'm not really sure how to do this is emacs however.

Try this as the starting point, it needs package popwin.
(require 'popwin)
(popwin-mode 1)
(generate-new-buffer "special-buffer")
(setq eab/special-buffer-displaedp nil)
(setq eab/special-buffer "special-buffer")
(add-to-list 'popwin:special-display-config
`(,eab/special-buffer :width 20 :position left :stick t))
(defun eab/special-buffer-toggle ()
(interactive)
(if eab/special-buffer-displaedp
(progn
(popwin:close-popup-window)
(setq eab/special-buffer-displaedp nil))
(progn
(ignore-errors (popwin:display-buffer eab/special-buffer))
(setq eab/special-buffer-displaedp 't))))
(global-set-key (kbd "<f3>") 'eab/special-buffer-toggle)

Related

how to use pywinauto to get checkbox in treeview

some UI list like this have some button or check box in treeview
| | GroupBox - '' (L807, T366, R1257, B746)
| | ['GroupBox']
| |
| | TreeView - '' (L815, T382, R1249, B732)
| | ['TreeView']
| | child_window(auto_id="1176", control_type="Tree")
| | |
| | | CheckBox - 'Intrusion Prevention' (L839, T384, R957, B402)
| | | ['CheckBox', 'Intrusion PreventionCheckBox', 'Intrusion Prevention', 'CheckBox0', 'CheckBox1']
| | | child_window(title="Intrusion Prevention", control_type="CheckBox")
| | |
| | | CheckBox - 'USB Malware Protection' (L874, T402, R1010, B420)
| | | ['USB Malware ProtectionCheckBox', 'CheckBox2', 'USB Malware Protection']
| | | child_window(title="USB Malware Protection", control_type="CheckBox")
| | |
| | | TreeItem - 'Network Virus Protection' (L858, T420, R996, B438)
| | | ['Network Virus Protection', 'Network Virus ProtectionTreeItem', 'TreeItem', 'TreeItem0', 'TreeItem1']
| | | child_window(title="Network Virus Protection", control_type="TreeItem")
I can use TreeView to see Treeitems like this
dlg = app.top_window()
a = dlg.TreeView
b = a.print_items()
i can see b have tree item (ex:Network Virus Protection) but no checkbox (ex:Intrusion Prevention) so how can i get checkbox ele from treeview?
i know can use child_window("title") to get check box , but i need get this ele and check it text, so use title are not better
you can try this extension,
https://marketplace.visualstudio.com/items?itemName=ClickCorp.clicknium
it includes one automation library, and can recorde the checkbox and do check or uncheck operation:
ui(locator.notepad.checkbox).check()

Use AWK with delimiter to print specific columns

My file looks as follows:
+------------------------------------------+---------------+----------------+------------------+------------------+-----------------+
| Message | Status | Adress | Changes | Test | Calibration |
|------------------------------------------+---------------+----------------+------------------+------------------+-----------------|
| Hello World | Active | up | 1 | up | done |
| Hello Everyone Here | Passive | up | 2 | down | none |
| Hi there. My name is Eric. How are you? | Down | up | 3 | inactive | done |
+------------------------------------------+---------------+----------------+------------------+------------------+-----------------+
+----------------------------+---------------+----------------+------------------+------------------+-----------------+
| Message | Status | Adress | Changes | Test | Calibration |
|----------------------------+---------------+----------------+------------------+------------------+-----------------|
| What's up? | Active | up | 1 | up | done |
| Hi. I'm Otilia | Passive | up | 2 | down | none |
| Hi there. This is Marcus | Up | up | 3 | inactive | done |
+----------------------------+---------------+----------------+------------------+------------------+-----------------+
I want to extract a specific column using AWK.
I can use CUT to do it; however when the length of each table varies depending on how many characters are present in each column, I'm not getting the desired output.
cat File.txt | cut -c -44
+------------------------------------------+
| Message |
|------------------------------------------+
| Hello World |
| Hello Everyone Here |
| Hi there. My name is Eric. How are you? |
+------------------------------------------+
+----------------------------+--------------
| Message | Status
|----------------------------+--------------
| What's up? | Active
| Hi. I'm Otilia | Passive
| Hi there. This is Marcus | Up
+----------------------------+--------------
or
cat File.txt | cut -c 44-60
+---------------+
| Status |
+---------------+
| Active |
| Passive |
| Down |
+---------------+
--+--------------
| Adress
--+--------------
| up
| up
| up
--+--------------
I tried using AWK but I don't know how to add 2 different delimiters which would take care of all the lines.
cat File.txt | awk 'BEGIN {FS="|";}{print $2,$3}'
Message Status
------------------------------------------+---------------+----------------+------------------+------------------+-----------------
Hello World Active
Hello Everyone Here Passive
Hi there. My name is Eric. How are you? Down
Message Status
----------------------------+---------------+----------------+------------------+------------------+-----------------
What's up? Active
Hi. I'm Otilia Passive
Hi there. This is Marcus Up
The output I'm looking for:
+------------------------------------------+
| Message |
|------------------------------------------+
| Hello World |
| Hello Everyone Here |
| Hi there. My name is Eric. How are you? |
+------------------------------------------+
+----------------------------+
| Message |
|----------------------------+
| What's up? |
| Hi. I'm Otilia |
| Hi there. This is Marcus |
+----------------------------+
or
+------------------------------------------+---------------+
| Message | Status |
|------------------------------------------+---------------+
| Hello World | Active |
| Hello Everyone Here | Passive |
| Hi there. My name is Eric. How are you? | Down |
+------------------------------------------+---------------+
+----------------------------+---------------+
| Message | Status |
|----------------------------+---------------+
| What's up? | Active |
| Hi. I'm Otilia | Passive |
| Hi there. This is Marcus | Up |
+----------------------------+---------------+
or random other columns
+------------------------------------------+----------------+------------------+
| Message | Adress | Test |
|------------------------------------------+----------------+------------------+
| Hello World | up | up |
| Hello Everyone Here | up | down |
| Hi there. My name is Eric. How are you? | up | inactive |
+------------------------------------------+----------------+------------------+
+----------------------------+---------------+------------------+
| Message |Adress | Test |
|----------------------------+---------------+------------------+
| What's up? |up | up |
| Hi. I'm Otilia |up | down |
| Hi there. This is Marcus |up | inactive |
+----------------------------+---------------+------------------+
Thanks in advance.
One idea using GNU awk:
awk -v fldlist="2,3" '
BEGIN { fldcnt=split(fldlist,fields,",") } # split fldlist into array fields[]
{ split($0,arr,/[|+]/,seps) # split current line on dual delimiters "|" and "+"
for (i=1;i<=fldcnt;i++) # loop through our array of fields (fldlist)
printf "%s%s", seps[fields[i]-1], arr[fields[i]] # print leading separator/delimiter and field
printf "%s\n", seps[fields[fldcnt]] # print trailing separator/delimiter and terminate line
}
' File.txt
NOTES:
requires GNU awk for the 4th argument to the split() function (seps == array of separators; see gawk string functions for details)
assumes our field delimiters (|, +) do not show up as part of the data
the input variable fldlist is a comma-delimited list of columns that mimics what would be passed to cut (eg, when a line starts with a delimiter then field #1 is blank)
For fldlist="2,3" this generates:
+------------------------------------------+---------------+
| Message | Status |
|------------------------------------------+---------------+
| Hello World | Active |
| Hello Everyone Here | Passive |
| Hi there. My name is Eric. How are you? | Down |
+------------------------------------------+---------------+
+----------------------------+---------------+
| Message | Status |
|----------------------------+---------------+
| What's up? | Active |
| Hi. I'm Otilia | Passive |
| Hi there. This is Marcus | Up |
+----------------------------+---------------+
For fldlist="2,4,6" this generates:
+------------------------------------------+----------------+------------------+
| Message | Adress | Test |
|------------------------------------------+----------------+------------------+
| Hello World | up | up |
| Hello Everyone Here | up | down |
| Hi there. My name is Eric. How are you? | up | inactive |
+------------------------------------------+----------------+------------------+
+----------------------------+----------------+------------------+
| Message | Adress | Test |
|----------------------------+----------------+------------------+
| What's up? | up | up |
| Hi. I'm Otilia | up | down |
| Hi there. This is Marcus | up | inactive |
+----------------------------+----------------+------------------+
For fldlist="4,3,2" this generates:
+----------------+---------------+------------------------------------------+
| Adress | Status | Message |
+----------------+---------------|------------------------------------------+
| up | Active | Hello World |
| up | Passive | Hello Everyone Here |
| up | Down | Hi there. My name is Eric. How are you? |
+----------------+---------------+------------------------------------------+
+----------------+---------------+----------------------------+
| Adress | Status | Message |
+----------------+---------------|----------------------------+
| up | Active | What's up? |
| up | Passive | Hi. I'm Otilia |
| up | Up | Hi there. This is Marcus |
+----------------+---------------+----------------------------+
Say that again? (fldlist="3,3,3"):
+---------------+---------------+---------------+
| Status | Status | Status |
+---------------+---------------+---------------+
| Active | Active | Active |
| Passive | Passive | Passive |
| Down | Down | Down |
+---------------+---------------+---------------+
+---------------+---------------+---------------+
| Status | Status | Status |
+---------------+---------------+---------------+
| Active | Active | Active |
| Passive | Passive | Passive |
| Up | Up | Up |
+---------------+---------------+---------------+
And if you make the mistake of trying to print the '1st' column, ie, fldlist="1":
+
|
|
|
|
|
+
+
|
|
|
|
|
+
If GNU awk is available, please try markp-fuso's nice solution.
If not, here is a posix-compliant alternative:
#!/bin/bash
# define bash variables
cols=(2 3 6) # bash array of desired columns
col_list=$(IFS=,; echo "${cols[*]}") # create a csv string
awk -v cols="$col_list" '
NR==FNR {
if (match($0, /^[|+]/)) { # the record contains a table
if (match($0, /^[|+]-/)) # horizontally ruled line
n = split($0, a, /[|+]/) # split into columns
else # "cell" line
n = split($0, a, /\|/)
len = 0
for (i = 1; i < n; i++) {
len += length(a[i]) + 1 # accumulated column position
pos[FNR, i] = len
}
}
next
}
{
n = split(cols, a, /,/) # split the variable `cols` on comma into an array
for (i = 1; i <= n; i++) {
col = a[i]
if (pos[FNR, col] && pos[FNR, col+1]) {
printf("%s", substr($0, pos[FNR, col], pos[FNR, col + 1] - pos[FNR, col]))
}
}
print(substr($0, pos[FNR, col + 1], 1))
}
' file.txt file.txt
Result with cols=(2 3 6) as shown above:
+---------------+----------------+-----------------+
| Status | Adress | Calibration |
+---------------+----------------+-----------------|
| Active | up | done |
| Passive | up | none |
| Down | up | done |
+---------------+----------------+-----------------+
+---------------+----------------+-----------------+
| Status | Adress | Calibration |
+---------------+----------------+-----------------|
| Active | up | done |
| Passive | up | none |
| Up | up | done |
+---------------+----------------+-----------------+
It detects the column width in the 1st pass then splits the line on the column position in the 2nd pass.
You can control the columns to print with the bash array cols which is assigned at the beginning of the script. Please assign the array to the list of desired column numbers in increasing order. If you want to use the bash variable in different way, please let me know.

Find the fonts with the best UTF-8 coverage in my Emacs

I'd like to be able to find the fonts which will have the best coverage in (Windows) Emacs for those UTF-8 chars:
| 0x0000B7 | MIDDLE DOT |
| 0x00229E | SQUARED PLUS |
| 0x00229F | SQUARED MINUS |
| 0x0022A0 | SQUARED TIMES |
| 0x0022A1 | SQUARED DOT OPERATOR |
| 0x002423 | OPEN BOX (wider in Consolas!) |
| 0x002502 | BOX DRAWINGS LIGHT VERTICAL |
| 0x00250C | BOX DRAWINGS LIGHT DOWN AND RIGHT |
| 0x002514 | BOX DRAWINGS LIGHT UP AND RIGHT |
| 0x0025A0 | BLACK SQUARE |
| 0x0025A1 | WHITE SQUARE |
| 0x0025AA | BLACK SMALL SQUARE |
| 0x0025AB | WHITE SMALL SQUARE |
| 0x0025B8 | BLACK RIGHT-POINTING SMALL TRIANGLE |
| 0x0025B9 | WHITE RIGHT POINTING SMALL TRIANGLE |
| 0x0025BA | BLACK RIGHT-POINTING POINTER |
| 0x0025BB | WHITE RIGHT POINTING POINTER |
| 0x0025BC | BLACK DOWN-POINTING TRIANGLE |
| 0x0025BE | BLACK DOWN POINTING SMALL TRIANGLE |
| 0x0025BF | WHITE DOWN-POINTING SMALL TRIANGLE |
| 0x0025CB | WHITE CIRCLE |
| 0x0025CC | DOTTED CIRCLE |
| 0x0025CF | BLACK CIRCLE |
| 0x0025E7 | SQUARE WITH LEFT HALF BLACK |
| 0x0025E8 | SQUARE WITH RIGHT HALF BLACK |
| 0x0025E9 | SQUARE WITH UPPER LEFT DIAGONAL HALF BLACK |
| 0x0025EA | SQUARE WITH LOWER RIGHT DIAGONAL HALF BLACK |
| 0x0025EB | WHITE SQUARE WITH VERTICAL BISECTING LINE |
| 0x002702 | BLACK SCISSORS |
| 0x002704 | WHITE SCISSORS |
| 0x002691 | BLACK FLAG |
| 0x002690 | WHITE FLAG |
| 0x002709 | ENVELOPE |
| 0x002717 | BALLOT X |
| 0x002713 | CHECK MARK |
| 0x002620 | SKULL AND CROSSBONES |
| 0x002197 | NORTH EAST ARROW |
| 0x002191 | UPWARDS ARROW |
| 0x002193 | DOWNWARDS ARROW |
| 0x0021BA | ANTICLOCKWISE OPEN CIRCLE ARROW |
| 0x0021AA | RIGHTWARDS ARROW WITH HOOK |
| 0x00260D | OPPOSITION |
| 0x002729 | STRESS OUTLINED WHITE STAR |
| 0x002605 | BLACK STAR |
| 0x002699 | GEAR |
| 0x00267B | BLACK UNIVERSAL RECYCLING SYMBOL |
(These are signs which could typically be used for Org-mode or Gnus marks, among others).
How can I do that without testing fonts one by one?
Is there a way, as well, to ensure that those fonts are non-proportional?
Step one: don't tie this question to emacs; as a question about "which fonts do I have with maximum coverage", your want a utility that tells you about coverage.
With that covered: be less specific in the coverage you need. Instead of saying "I need these glyphs", look at what that means in terms of "these are the Unicode Blocks I need". Then you can use something like babelmap to see which fonts you have installed with support for specific Unicode blocks by opening it, navigating to the block(s) you need, and hitting F7 to see the list of fonts you have installed that support it.

dbg:tracer visualizing recursive functions e.g. by indenting

I have the problem debugging an complicated recursive function I'm using the idiom:
dbg:tracer(),dbg:p(all,c),dbg:tpl(Mod,Fun1,x),dbg:tpl(Mod,Fun2,x)...
This gives me a flat list of calls to all functions where it is very hard to find out which return belongs to which call.
Is there a easy way to make this more readable e.g. by indenting.
I could just post process the text produced and indent for each call, and outdent for each return, but this sounds not very elegant to me.
In the meantime I figured it out how to do this, its actually not too hard. To have a process handling the trace message output you just have to use dbg:trace/2,3 and write one function that does the formatting.
We write a small module containing the function to pass to dbg:trace:
-module(trtool).
-export([nested/2]).
nested({trace, _Pid, call, {Mod, Fun, Param}}, Level) ->
io:format("~s~p:~p ~p\n",
[lists:duplicate(Level, "| "), Mod, Fun, Param]),
Level + 1;
nested({trace, _Pid, return_from, {Mod, Fun, Arity}, Rval}, Level) ->
L = Level - 1,
io:format("~s~p:~p/~b -> ~p\n",
[lists:duplicate(L, "| "), Mod, Fun, Arity, Rval]),
L;
nested(Any, Level) ->
io:format("trace_msg: ~p\n", [Any]),
Level.
The function takes two arguments, in the first it gets passed the trace message which is a tuple with convenient fields. To find out how the messages you want to format are structured just start with a simple function that prints everything like the last clause of the example function.
The second format is a kind of state that could contain any data. We pass the initial value when calling dbg:trace and return the next value from our function.
In the nested example we just pass the indent level which will be incremented and decremented in the call and return_from clauses.
Now lets try this out, first calling dbg:tracer/2, first parameter must be the atom process, second parameter a tuple containing our newly written fun and the initial value for the state param.
1> dbg:tracer(process, {fun trtool:nested/2, 0}).
{ok,<0.70.0>}
Then we set up tracing as before:
2> dbg:p(all, c), dbg:tpl(user_default,hop,x),dbg:tpl(user_default,rec,x).
{ok,[{matched,nonode#nohost,2},{saved,x}]}
Then we start our function call to trace and the nesting can be easily followed:
3> rec(3).
user_default:rec [3]
| user_default:rec [3,1,3]
| | user_default:rec [3,1,2]
| | | user_default:rec [3,1,1]
| | | | user_default:rec [3,1,0]
| | | | | user_default:hop [3,1,0]
| | | | | user_default:hop/3 -> {3,21}
| | | | user_default:rec/3 -> {3,21,1}
| | | | user_default:rec [6,2,-1]
| | | | | user_default:hop [6,2,1]
| | | | | user_default:hop/3 -> {2,46}
| | | | user_default:rec/3 -> {2,46,1}
| | | user_default:rec/3 -> {5,67,2}
| | | user_default:rec [8,3,0]
| | | | user_default:hop [8,3,0]
| | | | user_default:hop/3 -> {3,144}
| | | user_default:rec/3 -> {3,144,1}
| | user_default:rec/3 -> {8,211,3}
| | user_default:rec [11,4,1]
| | | user_default:rec [11,4,0]
| | | | user_default:hop [11,4,0]
| | | | user_default:hop/3 -> {3,258}
| | | user_default:rec/3 -> {3,258,1}
| | | user_default:rec [14,5,-1]
| | | | user_default:hop [14,5,1]
| | | | user_default:hop/3 -> {2,260}
| | | user_default:rec/3 -> {2,260,1}
| | user_default:rec/3 -> {5,518,2}
| user_default:rec/3 -> {13,729,5}
user_default:rec/1 -> {15,729}
{15,729}
4>
There is not way you can do that with the current dbg tracer process, you would have to write your own. If you start dbg:tracer/2 and use a process or port to capture the data and print it the way you want it to be.
It is probably faster and easier though to (as you say) parse the data post tracing and format it then.

Visual studio 2010 IDE layout

My current visual studio panel layout looks similar to the drawing below:
-----------------
| | | |
| | | |
| | | |
| | |--|
| | | |
| |---------| |
| | | |
-----------------
I really don't need the full height of the screen for the toolbox or server explorer and was wondering if there was a way to change the layout so that the bottom section extended all the way to the left edge of the screen like in this drawing:
-----------------
| | | |
| | | |
| | | |
| | |--|
| | | |
|------------| |
| | |
-----------------
I am space constrained on the right side, so a symetric layout with the bottom section running full width wouldn't be acceptable. I've tried dragging stuff around but haven't had any luck in getting VS to position the panels as I want. Is my desired layout not possible or am I missing the right way to coax the layout into fitting?
Yes, you can do this. When you are dragging the toolbox, note the little "targets" in the center of the screen. Drop the toolbox onto the target that corresponds with the area where you want it docked.
See here for more detail and pics.
Drag the bottom panel off and make sure to mouse over the icon that appears all the way at the bottom center of the screen, although this will cause it to take up the whole bottom portion of the IDE,
That's an easy process.
Drag the window docked in the bottom to middle of the VS window so that it floats in the middle.
Now when you drag it, a helper would apper to doc it.
You'll have some dynamic docking helpers like below.
↑
↑
← ← → →
↓
↓
if you chose the downarrow in the dock helper in the middle, you'll get the layout like this.
| | | |
| | | |
| | | |
| | |--|
| | | |
| |---------| |
| | | |
-----------------
If you chose the downarrow all the way at the bottom, you'll get the layout like this.
| | | |
| | | |
| | | |
| | |--|
| | | |
|---------------|
| |
-----------------

Resources