PDA

View Full Version : Arrow keys & Page Up/Down


0rthodontist
12-01-2006, 10:42 AM
I am using a MacBook and I can't use Page Up/Page Down on manual pages. So I have to just arrow up and arrow down one line at a time which is really tedious. Can I get around this? I tried plugging in another keyboard but it still doesn't work.

Also, in the command-line Python, I can't use any of the arrow keys--so I can't even arrow back on one line to correct something I typed, I have to delete it and type it all again. Also I can't use the up-key to get a previous line. Instead of accepting arrow key input, it says things like ^[[D^[[A^[[C^[[B (in this case, that is the output if I press the keys left, up, right, down in that order). Plugging in another keyboard does not fix this problem either.

Can these problems be fixed?

hayne
12-01-2006, 12:43 PM
I don't know about the use of page up/down on man pages but the behaviour is dependent on what "pager" you have installed for use with 'man'.
I have set the environment variable:
export LESS="-X -e"
so that man pages will exit via the spacebar and stay visible after exit.
I can use 'vi' type commands while in the pager - e.g. control-F and control-B for paging forward & back.

As to command-line editing in python, I googled for that phrase and found several hits, including this page:
http://www.pycs.net/bbum/2004/1/21/
which explains that the problem is that python on OS X does not include the 'readline' module by default. That page (which seems to be currently unavailable but is accessible via Google's cache) gives a one line python command which brings in the 'readline' module, after which command-line editing seems to work fine (on 10.4.8):


python `python -c "import pimp; print pimp.__file__"` -i readline

0rthodontist
12-01-2006, 01:07 PM
Thanks, ctrl-f and ctrl-b work to page up/down.

That one-liner doesn't work on my system. Here's the error:

$ python `python -c "import pimp; print pimp.__file__"` -i readline
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/plat-mac/pimp.py", line 1177, in ?
main()
File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/plat-mac/pimp.py", line 1157, in main
_run(mode, verbose, force, args, prefargs, watcher)
File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/plat-mac/pimp.py", line 1016, in _run
db.appendURL(prefs.pimpDatabase)
File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/plat-mac/pimp.py", line 387, in appendURL
fp = urllib2.urlopen(url).fp
File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/urllib2.py", line 129, in urlopen
return _opener.open(url, data)
File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/urllib2.py", line 326, in open
'_open', req)
File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/urllib2.py", line 306, in _call_chain
result = func(*args)
File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/urllib2.py", line 901, in http_open
return self.do_open(httplib.HTTP, req)
File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/urllib2.py", line 895, in do_open
return self.parent.error('http', req, fp, code, msg, hdrs)
File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/urllib2.py", line 352, in error
return self._call_chain(*args)
File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/urllib2.py", line 306, in _call_chain
result = func(*args)
File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/urllib2.py", line 412, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 404: Not Found
I don't know what it's trying to access.

hayne
12-01-2006, 01:40 PM
I don't use python, so I don't know what is going wrong.
My system is an iBook G4, while yours is a MacBook, so maybe the PowerPC vs Intel is the difference.
You should look for help on python-oriented forums.

0rthodontist
12-01-2006, 07:06 PM
Also, at the command prompt, I can't do cmd-left (the shortcut for "home") to go to the start of the line. Workaround?

hayne
12-01-2006, 08:14 PM
I assume you mean in Terminal.app
This is a Cocoa text area and so can be configured as explained in an article on the main macosxhints site: http://www.macosxhints.com/article.php?story=20060317045211408

The default is Control-A for start of line, Control-E for end of line.


Oh - I see that you meant in the python interpreter.
The above Control keys seem to work there too. Probably because (I think) they are emacs-bindings.

0rthodontist
12-01-2006, 08:20 PM
Thanks, that works for the terminal. Not for python though, ctrl-a outputs as ^A.

hayne
12-01-2006, 08:37 PM
Thanks, that works for the terminal. Not for python though, ctrl-a outputs as ^A.

This is probably something that comes along with that 'readline' module that you failed to load earlier. Without it, I recall reading some python tutorial saying that the only way to edit is with the backspace key.

0rthodontist
12-01-2006, 09:45 PM
Oh yes, that's what it must be. I can do "import readline" on command line python on Ubuntu, and I can edit python on the command line too, but I can't do either on the Mac. Funny that python must have come with readline prepackaged for Ubuntu, and also for Windows since I can text edit there too even though I downloaded it myself and didn't need to do any particular preparation, but the build for the mac does not have it. I wonder what other modules the mac doesn't have by default. Maybe it has something to do with the fact that the default python on the mac is 2.3.5 and the newer versions are 2.4 and 2.5.

hayne
12-01-2006, 10:28 PM
I think I recall some mumblings about an issue with the GPL preventing Apple from bundling it. I don't really understand the issue but I note that Python is under a (more permissive) BSD-style license. The 'readline' stuff is under the GPL.

But since I had no problem in importing the readline module into my python environment with that one-line command on my iBook G4 running 10.4.8, you should investigate (at python-specific forums as suggested above) why it is failing on your MacBook.