How to display m[,n] lines around current line in pdb? - python-2.7

The Python 2.7 debugger pdb allows to display lines o to p with l [o[,p]], but one has to figure out which line the debugger stand on and then substract and add. Is there a way to display an m lines before and n lines after the current line without arithmetics?

As far as I know, no. The l(ist) command will display 11 lines around the current line, but you can't display m lines before and n after the current line.
https://docs.python.org/2/library/pdb.html
l(ist) [first[, last]]
List source code for the current file. Without arguments, list 11 lines around the current line or continue the previous listing. With one argument, list 11 lines around at that line. With two arguments, list the given range; if the second argument is less than the first, it is interpreted as a count.

Related

Delete every other line in Visual Studio Code regardless of content

A colleague has inserted duplicates for ~1200 entries into our database. They have sent me a text file containing both the originals and copies in alternating lines of CSV text. I've opened that up in VS Code with the goal of converting the lines representing duplicates into DELETE statements targeting our database. No line is truly identical to another—every two is a pair in which the data is the same other than the row ID.
I have found Stack Overflow entries for removing every other line when the line is empty, or when every other line is an exact copy of the previous line. I have not found an entry this scenario in which the lines have a difference. E.g. I tried using (.*)\n\1 w/ $1\n from another SO entry, which seems to target truly duplicate lines.
So how do I use VS Code to delete every other line regardless of content?
You can achieve this using Replace-All UI in regex mode.
Press command-F or control-F
Expand the arrow on the left of the Find display
Press the ".*" so that it's highlighted
Enter this for Find (top text field in the Find UI): (.*\n)(.*)\n (basically select two lines but save the contents of the first line in the regex system)
Enter this for Replace (following text field in the find UI): $1 (take the line saved from the Find regex and re-insert it)
Hit the Replace All button
Here's a similar SO question

How do I print all lines of current file with list command in gdb?

How do I print all lines of current file with list command in gdb?
list command show only 10 lines by default, so I want to show all lines of current file.
How do I do it?
You can use list 1,10000 where 10000 is large enough number so that the size of a file you debugging is less than this large enough number. See builtin gdb help:
(gdb) help list
List specified function or line.
With no argument, lists ten more lines after or around previous listing.
"list -" lists the ten lines before a previous ten-line listing.
One argument specifies a line, and ten lines are listed around that line.
Two arguments with comma between specify starting and ending lines to list.
Lines can be specified in these ways:
LINENUM, to list around that line in current file,
FILE:LINENUM, to list around that line in that file,
FUNCTION, to list around beginning of that function,
FILE:FUNCTION, to distinguish among like-named static functions.
*ADDRESS, to list around the line containing that address.
With two args, if one is empty, it stands for ten lines away from
the other arg.
By default, when a single location is given, display ten lines.
This can be changed using "set listsize", and the current value
can be shown using "show listsize".

Automatic list making?

There are bunch of pages of a same website.
the first one is
http://www.theeuropeanlibrary.org/tel4/search?classification-cerif=H000&iyear=[2000%20TO%202010]&offset=20
the next one is almost like the firt,but differs in the number at the last,and is 2 times 20 which is 40.so,the number for the 2000th address would be 2000 times 20.Now hw can i make a txt file containing the 2000 addresses which made out of the first one by
the rule i said above?
I don't have any programming experience,but
i have notepad ++ installed.
Copy the constant string in the first line of the new file in Notepad++
http://www.theeuropeanlibrary.org/tel4/search?classification-cerif=H000&iyear=[2000%20TO%202010]&offset=
duplicate this line (Ctrl+D) as many times you want
position the cursor at the end of the first line
Alt+Shift+Arrow down until the last line
enter the column mode Alt+C
in the popup window, enter the first number (i.e. 20) and the incremant (i.e. 20)
click OK
That's it.

How to get first displayed document line number if line wrapping is enabled?

I use SCI_GETFIRSTVISIBLELINE of Scintilla in order to get the first displayed line of the document.
Now, I enabled word wrapping mode by setting SCI_SETWRAPMODE to SC_WRAP_WORD. But SCI_GETFIRSTVISIBLELINE does not match the document line any more.
Is there a way to get the first displayed document line (also, how to know if the displayed line is part of a wrapped line)? Scintilla itself knows it, as the correct line number is displayed before the text (when enabling SC_MARGIN_NUMBER).
Update: The first document line of the visible line can be get by calling SCI_DOCLINEFROMVISIBLE with the result of SCI_GETFIRSTVISIBLELINE. However, detecting partial lines is still a problem.
The corresponding document line of first visible line can be get by calling SCI_DOCLINEFROMVISIBLE with the result of SCI_GETFIRSTVISIBLELINE: DOCLINEFROMVISIBLE(GETFIRSTVISIBLELINE())
The second part is a bit more tricky and seems a bit hacky to me:
First, I call SCI_WRAPCOUNT with the document line number of the first line and get the number of rows this line uses. If SCI_WRAPCOUNT()>1 it's a candidate for a partial line. The number of skipped lines can be calculated with SCI_DOCLINEFROMVISIBLE(SCI_GETFIRSTVISIBLELINE() + SCI_WRAPCOUNT() - 1) - SCI_DOCLINEFROMVISIBLE(SCI_GETFIRSTVISIBLELINE()).

Deleting the last 2 lines of the buffer in vi

I am currently using vi on a file called Nick. I want to delete the last 2 lines in the buffer. How would I do this? I tried using y and /d however I am not sure of the correct syntax.
If you are doing this interactively:
:$-1 (to go to the second to last line)
dG (to delete everything from where the cursor is now)
Gdk will do it, followed by Ctrl-O if you want to return to where you were before you did it.
(That's G to move to the end of the document, dk to delete the lines between the current location and the result of the motion k i.e. up one line, and Ctrl-O just returns you to your previous location.)
If I was actually doing this and didn't have time to think about it, I'd probably use G to go to the end of the file, Shift-V to enter Visual Line mode, k to select the previous line in addition to the current one, then d to delete them both.
Shortest way I know of is
:$;-d
which says 'delete lines in the range $;-'. The range is given in reverse, from the last line $ to one before the last line - (same as -1).