Selecting text with keyboard.send_keys from within an autokey script? - autokey

Rather than selecting text and then triggering the script, I'd like my script to select the text. I thought I could select text with keyboard navigation (e.g., "<shift>+<ctrl>+<left>" to select the word to the left of the cursor. I can do that and the word appears to be getting highlighted in gedit, but if I follow that with clipboard.get_selection(), I get an exception that no text is selected.
# Select the word to the left of the cursor:
keyboard.send_keys("<shift>+<ctrl>+<left>")
# Try to get the current selection (fails with "No text found in X selection"):
try:
name = clipboard.get_selection()
except BaseException as err:
dialog.info_dialog('error', 'autokey script exception: {0}'.format(err))
Am I doing something wrong? Or is what I'm trying to do not possible with autokey?

Related

RichEdit20A line selection mode similar to Notepad

I'm trying to change the way RichEdit20A Windows control selects line so it's similar to how it works in Notepad.
By default, if I select a line (e.g. Shift-End), then all the characters and the end of line is selected:
Sample text
^^^^^^^^^^^^ <- this is the selection
In Notepad it selects just the text:
Sample text
^^^^^^^^^^^
As a result, pressing delete (or backspace) in RichEdit20A control removes the line while in Notepad it just removes the text and keeps the line empty.
Is there any simple way (other than handling selection on my own) to configure the RichEdit20A control to keep formatting but make the line selection to work like in Notepad?
I don't know such a setting to influence the RTF control. But pressing Shift+End is a key input that is possible to trap with a WM_KEYDOWN handler, when you subclass the control.
You can use EM_LINEINDEX with -1 to get the current line start index.
Now with this index you can use EM_LINELENGTH.
Get the current selection (EM_GESTEL) and now you are free to use EM_SETSEL with the values you like to extend it.

How to make Sublime Text - Command L select only current line (not move down)

This is kind of an obscure question but a lot of times I use Command+L to quickly highlight text and then immediately start typing over it. This doesn't work because when you use Command+L Sublime will highlight the current line,but it will also place the cursor on the line below the current line in the process. Then, if you start immediately typing, you will pull the following line up and adjacent to what you are typing.
Is there a known way to stop the "place cursor on following line" behavior of Command+L?

How to Add tab space to multilple line at the same time in any text editor

If you select a text you can add multiple tab spaces to the all lines simultaneously.
For that you must select the n lines of the code and press the key tab. If you want
remove the tab spaces should select the text and press shift+tab.
I was programming in my job and I accidentally discovered this in the IDE eclipse. I test the same process
in the Sublime Text and Geany and it works too.
Y suposse and pressume that works for the most of text editor
I can confirm the answer from kelgwiin for sublime text.
Depending on your platform you could also do the following in sublime text:
Linux: Hold shift and the right mouse button, then move the mouse up or down to make a column selection.
Windows + OS X: Simply hold down the mousewheel and move your mouse up and and down to select the columns.
Hope this helps!
On Geany you can create by using Alt+Shift+Mouse (Windows) or Ctrl-Shift-Mouse (*x) a multiline cursor or an rectange selection, where you can work on many lines at the same time. This is only working for lines 'in row' so you cannot choose line 9 and lines 12-16 and lines 23-44 to be edited at the same time.

Deleting Line of Text Using Xcode Find and Replace

I'm wondering if it's possible to search for a certain line of a text using Xcode's Find & Replace feature, and fully delete the line so not even blank space is left over. Is this possible and if so how?
Copy the line you want to delete, including the newline character at the end of the line by triple-clicking on it (the selection should go all the way to the far right side of the editor pane). Perform a find and replace; paste the line into the the top field, and leave the replace field blank. Click Replace All.
On the latest Xcode you can just insert line break in the search field. Click on magnifying glass icon -> insert pattern -> Line Break

How to indent a selection in gVim (Win32)

I'd like to indent a block of text.
I am able to do this in the Linux build of gVim.
I do this in the state of gVim where I'm not in the insert or visual mode. The bar at the bottom is blank on the left, and the line number and percentage are showing on the right hand side.
Then I perform the following procedure: I select a block of text via click and drag. Then I hit Shift + .. After that, I hit Esc and the block of text will move over a tab.
If I do this in Windows however, it just replaces the block with >.
I am just running the stock Windows rc file and version 7.1 of gVim.
If you first enter SHIFT-V, and than shift+arrows to select the text, it will indent.
You can also use SHIFT-V, and use 'hjkl' to select the block.
If you use shift+arrows or the mouse to select a block of text, it does not work and the selection will be replaced with a '>'. This can be changed when you change selectmode;
set selectmode=mouse,key
default setting after behave mswin
set selectmode=key
now you can select with the mouse and press '>' to indent
set selectmode=
now you can select both with the mouse and shifted arrow keys and press '>' to indent
If you add this to your vimrc, do it after behave mswin
Related to this, I use a handy remap for visual mode that allows indenting the text multiple times while keeping your text selected. Similar to how visual studio lets you select and hit tab (or shift-tab) to indent.
Add the following to your .vimrc
" Pressing < or > will let you indent/unident selected lines
vnoremap < <gv
vnoremap > >gv
Also you can use == to have vim try and determine the correct indenting automatically. It will work on any line buy just placing the cursor there and pressing == or you can do fancy stuff like select the entire file and press == to fix all the indenting (works wonders on html generated by wysiwyg editors).
Esc -> Shift+V -> Select Lines -> > >
You need to change behave mswin to behave xterm in your vimrc file.
You can use text objects if you want to avoid visual mode entirely. For example >ap in Normal mode indents one paragraph, >aB indents one curly-brace block, etc. See :h text-objects.

Resources