Page 1 of 2

copying and pasting code effectively

Posted: 20. Nov 2012, 22:51
by mimosa
Sites such as pastebin, and online code samples generally, often have a button to click to copy to the clipboard. Just paste into your favourite editor (such as gvim or geany), save, chmod +x, and run.

But all too often, there is no button like that, and I end up with tabs instead of spaces (or vice versa), the wrong newline character, or whatever other illegal or incorrect characters so the thing won't run - except possibly after some fiddly substitutions and editing.

It struck me that I must be missing something: people who post code in that way can't be expecting it to be at all tricky to turn it into an executable file.

Here's an example: ... stener.htm

This also has the related problem that at least in some browsers (including Firefox), selecting with the mouse doesn't scroll down, so if the code is too long to fit in the visible screen, you only get what you see. On the other hand, "Select all" gives you the whole page, not just the code.

I would be very grateful for any tips!

Re: copying and pasting code effectively

Posted: 20. Nov 2012, 23:44
by jayseye
Yes, have had issues when pasting into nano, such that each line gets a deeper level of indentation. IIRC my solution has been to paste into my favorite text editor, jEdit. That's a very mature, Java-based programmers' editor, which is available via slapt-get.

If you like, I could confirm that the code which you linked to gets pasted properly into jEdit. ATM I'm still recovering from a couple of power outages which zapped several hard drives here.

Hoping to be back on Salix in a couple of hours. Currently running from a Parted Magic LiveCD. Very cool to be able to run SMART drive self tests using gsmartcontrol, while browsing the web.

Re: copying and pasting code effectively

Posted: 21. Nov 2012, 00:25
by mimosa
Thanks for the recommendation. Did you think of jEdit specifically because that piece of code is java, or is it generally good for this task, irrespective of which language the code is written in?

From what you say, it sounds as though there is no easy answer, or to put it another way, there isn't anything obvious I was missing.

jEdit doesn't seem to be in the 14.0 repos, but I can try it out in Salix 13.37.


There is a Slackware package available from the jEdit website (and actually I bet the Salix 13.37 package works fine for current too). But I had the very problem with it that that code sample is meant to test: the menus don't work properly, in fact, nothing works properly, and the initial window doesn't take up all its tile (this is probably not an issue in xfce). Keyboard shortcuts don't trigger menu events either.

I am alpha testing for Wenlinux, the prospective version of the Chinese language software Wenlin for the eponymous platform, and I'm seeing just the same behaviour. Whence this test.

BTW the problem with select-and-scroll doesn't occur with Vimprobable. :D

Re: copying and pasting code effectively

Posted: 21. Nov 2012, 00:49
by jayseye
'welcome, mimosa. Short answer is: because it works, irrespective of the language. Slightly longer answer:

jEdit has been my GUI editor of choice for many years, with Java being absent from my own list of advantages. Although jEdit works fine with OpenJDK, personally I still consider Java to be a liability, in terms of overhead, security, and current stewardship. I'd switch to a C/C++ or Python-based editor in a heartbeat, if it had some of the key features I require.

Being a 100% pure Java app, the 13.37 version of jEdit should work fine under Salix 14.

Re: copying and pasting code effectively

Posted: 21. Nov 2012, 00:56
by jayseye
Our previous replies crossed. I use jEdit under Salix 13.37 Fluxbox, and have yet to see any issues. Have used both the version from the jEdit website, and the Salix repo version. Would be glad to help you troubleshoot, in a few hours.

First thing I should do, though, is to test the code sample which you linked to, pasted into jEdit. The rest would be moot if I'm wrong about that...

Re: copying and pasting code effectively

Posted: 21. Nov 2012, 10:24
by mimosa
If you could, jayseye, that would be great. I suspect there's something wrong with my java installation, otherwise this would have come up before for someone else.

Code: Select all

root[cashew]# twapake -i | grep jdk                                                               
Thanks for explaining about jEdit. If I can get it to work, I'll certainly give it a try!

I can report exactly the same behaviour in Salix 13.37 (with Ratpoison): jEdit's menus don't work, and the initial window is small (whereas the expected behaviour in Ratpoison would be to fill the whole screen). In 13.37, the jdk version is 6:

Code: Select all

root[vanilla]# twapake -i | grep jdk

Re: copying and pasting code effectively

Posted: 21. Nov 2012, 23:45
by jayseye
You're welcome mimosa, I've found a Firefox command to facilitate selecting just the code: Temporarily turn on Caret Browsing (F7) to get a text cursor. A confirmation dialog pops up, with a checkbox which can suppress that in the future. Then you can place the cursor at the start of the code, and click the mouse at the end of the code to select it. Keyboard selection commands also work, including Shift+PageUp, Shift+UpArrow, etc.

I'll test pasting your linked example code into jEdit later on, before calling it day (night). Had to reboot my laptop out of its Parted Magic LiveCD session, in order to finish up hard drive diagnostics, following a couple of power outages. Should be all recovered in a few hours.

Currently I'm on a borrowed Windows laptop, just to catch up with e-mail, Google Plus, and a little software development project for Zim-Wiki. Interestingly, pasting the example code into Windows Notepad works fine, though in WordPad it gets double-spaced.

Pasting also works fine into the Windows version of Zim-Wiki, a lightweight organizer written in Python, included with Salix 14 beta1 (so also likely in the RCs). It's not a code editor, but if pasting there also works under Linux, then Zim might work as an intermediate program to straighten out tabs. spaces, and line endings.

I may boot up a Salix 13.37 LiveCD in a while, to test installing jEdit there. IIRC I've got both XFCE and Fluxbox LiveCDs.

Re: copying and pasting code effectively

Posted: 22. Nov 2012, 00:31
by mimosa
Thanks very much jayseye; I'll experiment with your suggestions.

It seems this thread has now expanded to two problems: the original one of how to copy and paste online code samples robustly (for which jEdit may be the solution, besides others you've suggested); and whether the problem I've been experiencing with both jEdit and another java app (menus don't work) is specific to my setup, or reproducible on other Salix systems.

Regarding the second problem, an intermediate possibility would be that there's some basic, obvious housekeeping that any knowledgeable and experienced java user does after first installing jdk, but whatever it was, I didn't do it.

By the way, I'm beginning to get the impression that the power supply in Oregon isn't much better than it is here in Brazil ;)

Re: copying and pasting code effectively

Posted: 22. Nov 2012, 01:07
by jayseye
Yes, if anyone else shows up here, you might split this into two separate topics. I've installed a JDK on every Slackware version since 9, and am trying to recall any housekeeping which might have been necessary:

Worst case might be a need to reboot, or at least to restart X, in order to have changes take effect for PATH and environment variables. At least it might be wise to close and reopen any shell sessions, for the same reason, if you start java programs from the command line.

Have you checked for entries under /var/log right after opening a java program and seeing the menu issue?

Power had been solid here since the big storm of 2007, which knocked down many thousands of trees. During the two-week recovery before we got power back, they trimmed many trees far back from the power lines. Some trees may have grown back by now; in any case, we had winds well over 100 miles per hour here just the other day. The crews were out working during the worst of that storm, and amazingly we got power back around 1:30 AM. Then it went out again the next day. Unfortunately two out of our 3 UPSs (Uninterruptible Power Supply) failed, and our remaining one is the oldest. The local big box warehouse store is out of stock until the weekend, so we're limping along. LiveCDs rule for protecting hard drives!

Re: copying and pasting code effectively

Posted: 22. Nov 2012, 05:56
by jayseye
OK, my laptop drive is recovered and back running Salix Fluxbox 13.37. Pasting your code example into nano produces the symptom which we might call "marching indents."

It pastes fine into jEdit; however it also pastes fine into geany. So I'm suspecting that I've turned off an "auto indent" setting in each of those GUI editors.

Might even find a similar setting for nano, though it's time for a late dinner here. I'll check back for a reply to this, and/or to my previous message.