Sublime Text 2/3 - How to always have at least 10 lines under current line? - sublimetext2

Is there a way to show at least x number of lines below a current line in ST? Say my cursor is on line 55, I want Sublime to display at least 10 more lines below the current line so line 55 will never be at the bottom of the screen. Is this possible in Sublime?

You can achieve this with a simple plugin, that listens for cursor movement events.
From the Tools menu in Sublime Text, click New Plugin.
Replace the contents with the following:
import sublime, sublime_plugin
class ShowLinesUnderSelectionListener(sublime_plugin.EventListener):
def show_lines_under_selection(self, view, number_of_lines_to_show):
cursor_pos = view.sel()[0].end()
row, col = view.rowcol(cursor_pos)
desired_pos = view.text_point(row + number_of_lines_to_show, col)
if not view.visible_region().contains(desired_pos):
view.show(desired_pos, False)
def on_post_text_command(self, view, command_name, args):
if command_name in ('word_highlight_click', 'move', 'move_to', 'insert'):
self.show_lines_under_selection(view, 10)
def on_post_window_command(self, window, command_name, args): # for Vintageous support
if command_name in ('press_key'):
self.show_lines_under_selection(window.active_view(), 10)
Save it to the folder it suggests as something like show_lines_under_cursor.py.
This will ensure that there are always 10 visible lines under the cursor. Note that once you reach the bottom of the file, it won't scroll any further to show 10 non-existing-in-file lines. I'm not sure if this is possible via the API.

Related

HTML Dec Code image in Tkinter label — either text or image is doubled

I'd like to add a picture to some of my tkinter labels, and I found a page with many of them (there are, of course, many similar pages), including some that I want.
But I'm having a strange behavior with this.
The code
import tkinter as tk
from tkinter import ttk
import html
root = tk.Tk()
root.geometry("200x100")
s = html.unescape('&#127937') # chequered flag
text = "some text"
label_text = "{}{}".format(text, s)
my_label = ttk.Label(root, text=label_text)
my_label.pack()
t = chr(9917)
another = "football ball"
another_text = "{}{}".format(t, another)
another_label = ttk.Label(root, text=another_text)
another_label.pack()
root.mainloop()
produces the following window:
On the other hand, if I replace label_text = "{}{}".format(text, s) with label_text = "{}{}".format(s, text) the flag appears twice instead (once before "some text" and another after).
Apparently this only happens with html images.
For example, with the second label, I have the expected behavior.
Is there something I'm doing wrong here, or should I just avoid these images in tkinter?
i wouldnt avoid them yet i wouldnt advise them either. Because tkinter propbably uses regular images its propbably not used to emojis. My recommendation is to use regular images instead of emojis.

How to vertically align comma separated values in Notepad++?

As shown in the picture "Before" below, each column separated by comma is not aligned neatedly. Is there any method to align each column vertically like the display effect in Excel?
The effect I wish is shown in the picture "After".
Thanks to #Martin S , I can align the file like the picture "Method_1". As he has mentioned, some characters still cannot align well. I was wondering if this method could be improved?
You can use the TextFX plugin:
TextFX > TextFX Edit > Line up multiple lines by ...
Note: This doesn't work if the file is read only.
http://tomaslind.net/2016/02/18/how-to-align-columns-in-notepad/
Update 2019: Download link from SourceForge
Maybe not exactly what you're looking for, but I recently added a CSV Lint plug-in to Notepad++ which also adds syntax highlighting for csv and fixed width data files, meaning each column gets a different color so it's easier to see.
You can use this python plugin script which utilizes the csv library which takes care of quoted csv and many other variants.
Setup:
Use the plugin manager in Notepad++ to install the "Python script" plugin.
Plugins->Python Script->New Script (name it something like CSVtoTable.py)
Paste the following python script into the new file and save:
CSVtoTable.py
import csv
inputlines = editor.getText().split('\n')
# Get rid of empty lines
inputlines = [line.strip() for line in inputlines if line.strip()]
reader = csv.reader(inputlines, delimiter=',')
csvlist = [line for line in reader]
# transpose to calculate the column widths and create a format string which left aligns each row
t_csvlist = zip(*csvlist)
col_widths = [max([len(x) for x in t_csvlist[y]]) for y in range(len(t_csvlist))]
# To right align - change < to >
fmt_str = ' '.join(['{{:<{0}}}'.format(x) for x in col_widths]) + '\r\n'
text = []
for line in csvlist:
text.append(fmt_str.format(*line))
# open a new document and put the results in there.
notepad.new()
editor.addText(''.join(text))
Open your CSV file in notepad++
Click on Plugins->Python Script->Scripts->(The name you used in step 2)
A new tab with the formatted data should open.
Update (right aligned numbers & left aligned strings):
Use the following python script if you want to right align number fields from the CSV - it looks at the second line of the csv to determine the types of the fields.
import csv
import re
num_re = re.compile('[-\+]?\d+(\.\d+)?')
inputlines = editor.getText().split('\n')
# Get rid of empty lines
inputlines = [line.strip() for line in inputlines if line.strip()]
reader = csv.reader(inputlines, delimiter=',')
csvlist = [line for line in reader]
# Transpose to calculate the column widths and create a format string which left aligns each row
t_csvlist = zip(*csvlist)
col_widths = [max([len(x) for x in t_csvlist[y]]) for y in range(len(t_csvlist))]
# Numbers get right aligned
type_eval_line = csvlist[1 if len(csvlist)>1 else 0]
alignment = ['>' if num_re.match(item) else '<' for item in type_eval_line]
# Compute the format string
fmt_str = ' '.join(['{{:{0}{1}}}'.format(a,x) for x,a in zip(col_widths,alignment)]) + '\r\n'
text = []
for line in csvlist:
text.append(fmt_str.format(*line))
# open a new document and put the results in there.
notepad.new()
editor.addText(''.join(text))
Notepad++ CSVLint
Install CSVLint Plugin
Open CSV file. Or manually set Language > CSVLint. This will give you nicely colored output.
To reformat do this:
Open lower pane: Plugins > CSV Lint > CSV Lint Window.
Click the Reformat button. Check the box Align vertically (not recommended). -- This may screw up your data, so think twice before clicking OK.
Reformatted output:
If you want to try this yourself: Here is my sample input:
TIMESTAMP_START,TIMESTAMP_END,TA_ERA,TA_ERA_NIGHT,TA_ERA_NIGHT_SD,TA_ERA_DAY,DA_ERA_DAY_SD,SW_IN_ERA,HH,DD,WW-YY,SW_IN_F,HH
19890101,19890107,3.436,1.509,2.165,6.134,2.889,100.233,283.946,1.373,99.852,2.748,1.188
19890108,19890114,3.814,2.446,2.014,5.728,2.526,91.708,286.451,1.575,100,100.841,0.742
You could use Search&Replace to change all occurrences of , to ,\t. This will add a tab after each ,.
This method has however some drawbacks:
you effectively add white-space characters to your document (in case you need to edit and save it).
This works well only if the difference (in terms of number of characters) between the longest and the shortest numbers is less than 1 tab-size (usually 4 characters).

How to avoid sikuli creating a png file when using "with Region"

I have the following code in sikulix (version 2015-01-06)
...
t = wait("total_power.png")
area = Region(t.x+t.w, t.y, 80, 31)
with Region(area):
wait("num_1.png")
....
I find that "with Region" will create a png file in the same directory of the python file. And the png file is the region that I want.
How can I avoid it?
What is is it that you are trying to do here?
Is it that you would like to wait until a window appears, and then look inside that window for another picture to appear?
In that case you alreay have defined the region when you found "t".
"t" is the location of the picture "total_power.png"
For example:
# Wait until the window appears.
p1 = wait("image1.png")
# Find another picture inside the window.
p2 = p1.wait("image2.png")
Edit:
You should have a look here: Link
I think you could use the .right(), if you leave the () empty you take everything.
If fill in a a value you take a part of the screen.
I use .hightlight() when programming to show me what region I am looking at.
You can also use region1.union(region2) to merge 2 region to a new one.
An example:
Image1 = ("image1.png")
class Blue():
def __init__(self):
# Find an image.
LocImage1 = find(Image1)
# Too show the user the region we selected, we can highlight if for 5 seconds.
LocImage1.highlight(5)
# Grab the region to the right of this image.
LocImage1RightSide = LocImage1.right()
# Highlight the region again.
LocImage1RightSide.highlight(5)
# Run class
Blue()

Fold / Collapse the except code section in sublime text 2

Is there any plugin or shortcut to hide all except code section in sublime text 2?
I need to fold all except section at a time , Not fold one section at a time.
Thanks~
If you'll hover with the mouse over the line numbers you'll see arrows - clicking on any of them will fold/collapse the code
If you want to collapse/expand all - you can do so by going to edit->code folding and choose "fold all" or "unfold all":
In addition to the other answers it is also possible to fold based on level as well. So for example looking at the default key bindings for fold.
Searching for fold key bindings.
So for example a foldall, or folding level 1 would be to hold Ctrl followed by pressing the sequence k and then 1:
Or folding level 2 would be to hold Ctrl followed by pressing the sequence k and then 2:
Or unfolding all would be would be to hold Ctrl followed by pressing the sequence k and then 0 or in my defaults I also seem to have it bound to the letter j:
Warning.
Pressing Ctrl+k twice will remove a line or a count of lines.
But not really cause you can put them back one by one by Ctrl+u
One thing you can do is select the Except code bloc using a regular expression, for instance using except(.|\n)*?raise.* in your case. You can then select "Find all" in the search bar, then Edit->Code Folding -> Fold .
Windows shortcut : Ctrl-Shift-[
Mac shortcut: Cmd-Alt-[
All the Except bloc will then be collapsed.
I know this is an old question, but it still comes up high in search results and none of the answers quite do what the OP wanted.
select the code you don't want to be hidden
use "Selection" -> "Invert Selection" to select the code you do want to be hidden instead
use ctrl + shift + [ or Command + Option + ] to collapse the selection(s)
This will leave you with just the code you originally had selected visible.
Fold and UnFold function or class base only for MAC:
* Fold: command + K, command + 1
* UnFold: command + K, command + J

Select all and multiple cursors using SublimeText2

I have a text file with 100's of news articles.
I need to Select All > Take cursor to the beginning of each line and have the 'multiple cursors' open so I can add some data.
Since the new articles do not have the same begging character, I can not use CTRL+F3.
Is there a way to [CTRL] + [A] (Select All) then > Go to the begging of each line with 'multiple cursors' open ?
You should select all with ctrl+A.
Then split the selection into one selection per line with ctrl+shift+L.
Then press the left arrow key.
Now you should be able to type data at the beginning of each line.
Let me add some answer, ( work in sublime 2 / sublime 3 )
i try with #Riccardo Marotti step
, but when the article have tab it will lead to the very far first line
So I make some fix , To make cursor in every front line or every end of line :
ctrl+A // select all
ctrl+Shift+L // Add cursor to all line
Shift+Home // put cursor to first word in the line
to get the end of line no need to do the first step again if you are in the first line, just do this one :
Shift+End // put cursor to end of line, then
click "right arrow" to remove the drag
or you can try this one (really an experimental works)
Just use you center of mouse, click it (the center roll of your
mouse), then drag, this will lead to add more cursor
, then just press left/right
or try to seek more here :
sublime-text-multiple-cursor-shortcut
override-shortcut-for-multiple-cursors
hope this help
I think ctrl+alt+down (or up) when your cursor is at the beginning of a line might be what you're looking for. It will put the cursor on multiple lines, and what you type will be duplicated on each.