Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Page Up/Down Issues With Emacs in Terminal

238 views
Skip to first unread message

Brandeis King

unread,
Jul 5, 2016, 4:57:51 PM7/5/16
to
Hi,

When I launch emacs in a (zsh) terminal with the no window system option, pressing the keys "page-up" and "page-down" results in emacs writing "5~" and "6~" respectively to the buffer and then changing to the previous/next buffer depending on which button is pressed.

How can I configure emacs and/or the (zsh) terminal to scroll the page when page up/down is pressed as emacs does in a non-terminal instance? Thanks.

Best,
Brandeis

Emanuel Berg

unread,
Jul 5, 2016, 5:44:03 PM7/5/16
to
Brandeis King <brandei...@gmail.com>
writes:
This sounds like an issue with your terminal
emulator rather than the "command interpreter"
which is zsh - so are you using xterm, urxvt,
something like that?

--
underground experts united .... http://user.it.uu.se/~embe8573
Emacs Gnus Blogomatic ......... http://user.it.uu.se/~embe8573/blogomatic
- so far: 56 Blogomatic articles -

Emanuel Berg

unread,
Jul 5, 2016, 5:48:12 PM7/5/16
to
Brandeis King <brandei...@gmail.com>
writes:
Look, I don't use Emacs in X, and I NEVER use
the PageUp/PageDown keys - actually I didn't
know they existed until now! Ahem...

Nonetheless, with xterm as the terminal
emulator, zsh as the command interpreter or
shell, with tmux there as well, and Emacs 24
invoked with -Q, those buttons behaved
like expected!

I mean, like I think them to expect to
behave... eh, nevermind.

Dmitry Alexandrov

unread,
Jul 5, 2016, 6:23:31 PM7/5/16
to Brandeis King, help-gn...@gnu.org
Brandeis King <brandei...@gmail.com> writes:

> When I launch emacs in a (zsh) terminal with the no window system
> option,

What is ‘(zsh) terminal’? I only know that there is a free Bourne
compatible shell named ‘zsh’. Examples of terminals are: VT-100, Linux®
Console, FreeBSD Console.

$ echo "$TERM"

Emanuel Berg

unread,
Jul 5, 2016, 6:39:52 PM7/5/16
to
Dmitry Alexandrov <321...@gmail.com> writes:

> What is ‘(zsh) terminal’? I only know that
> there is a free Bourne compatible shell named
> ‘zsh’. Examples of terminals are: VT-100,
> Linux® Console, FreeBSD Console.

C'mon, don't be patronizing - it is a common
and natural mix-up.

VT100: introduced in 1978 by DEC. It has been
emulated ever since tho.

The OP is not using the Linux VTs because those
keys don't even work there!

> $ echo "$TERM"

Here, TERM can be a false friend. For example,
I run tmux so it says "screen" in the Linux VTs
as well as in xterm!

It is better to just think "what program am
I using?"

Dmitry Alexandrov

unread,
Jul 5, 2016, 6:56:56 PM7/5/16
to help-gn...@gnu.org
Emanuel Berg <embe...@student.uu.se> writes:

> Dmitry Alexandrov <321...@gmail.com> writes:
>
>> What is ‘(zsh) terminal’? I only know that
>> there is a free Bourne compatible shell named
>> ‘zsh’. Examples of terminals are: VT-100,
>> Linux® Console, FreeBSD Console.
>
> C'mon, don't be patronizing - it is a common
> and natural mix-up.
>
> VT100: introduced in 1978 by DEC. It has been
> emulated ever since tho.
>
> The OP is not using the Linux VTs because those
> keys don't even work there!

They do. Even more: they work as expected in a modern GNU Emacs that is
running on Linux® Console (I’ve just tested it on Debian GNU/Linux
Jessie).

>> $ echo "$TERM"
>
> Here, TERM can be a false friend. For example,
> I run tmux so it says "screen" in the Linux VTs
> as well as in xterm!
>
> It is better to just think "what program am
> I using?"

Why the false friend? If OP is using some terminal multiplexer that’s
exactly what we have to know. That is the most probable cause,
actually, since: a) I strongly guess, he is using Linux® Console;
b) PgUp / PgDn should work out of a box there.

Emanuel Berg

unread,
Jul 5, 2016, 9:52:22 PM7/5/16
to
Dmitry Alexandrov <321...@gmail.com> writes:

> They do. Even more: they work as expected in
> a modern GNU Emacs that is running on Linux®
> Console (I’ve just tested it on Debian
> GNU/Linux Jessie).

Is the Linux "R" Console something I haven't
heard of or is it the old Linux virtual
terminals (VTs), i.e. the ttys (teletypewriters)
you get for example after

$ sudo chvt 1 # or 2 etc.

?

Because here the keys do work in the console
(verify this with showkey(1)) but in Emacs they
don't - however one can get them as described
in this tutorial [1] to assign them Emacs
defuns - tho why anyone would want to use those
keys beats me...

> Why the false friend? If OP is using some
> terminal multiplexer that’s exactly what we
> have to know. That is the most probable
> cause, actually, since: a) I strongly guess,
> he is using Linux® Console; b) PgUp / PgDn
> should work out of a box there.

It is a false friend because it gives the same
answer in X as in the Linux VTs if tmux is used
in both places, however setting up the
terminal and in particular the keys are not
the same despite TERM being the same...

[1] http://user.it.uu.se/~embe8573/tty-emacs-keys.txt

Brandeis King

unread,
Jul 5, 2016, 10:14:43 PM7/5/16
to
On Tuesday, July 5, 2016 at 5:44:03 PM UTC-4, Emanuel Berg wrote:
> This sounds like an issue with your terminal
> emulator rather than the "command interpreter"
> which is zsh - so are you using xterm, urxvt,
> something like that?

To clarify, I'm experiencing this issue with xterm and gnome-terminal, both with and without tmux. And yes, I'm using z-shell.

@Emanuel: Thanks for the suggestion of using "-Q". Unfortunately, however, even with this option the original issue persists.

@Dmitry: By '(zsh) terminal' I meant a terminal running zsh. Since the issue occurred in both xterm and gnome-terminal, I thought the root issue was independent of the terminal, and hence did not specify.

Emanuel Berg

unread,
Jul 5, 2016, 10:59:41 PM7/5/16
to
Brandeis King <brandei...@gmail.com>
writes:

> @Emanuel: Thanks for the suggestion of using
> "-Q". Unfortunately, however, even with this
> option the original issue persists.

Try xev(1) and see if there are events at all!

> @Dmitry: By '(zsh) terminal' I meant
> a terminal running zsh. Since the issue
> occurred in both xterm and gnome-terminal,
> I thought the root issue was independent of
> the terminal, and hence did not specify.

It is a good idea to isolate/minimize the
problem. See if you have any keys set up at the
zsh, tmux, xterm or otherwise X level (e.g.,
xbindkeys) that might interfere.

Yuri Khan

unread,
Jul 6, 2016, 3:37:35 AM7/6/16
to Brandeis King, help-gn...@gnu.org
On Wed, Jul 6, 2016 at 8:14 AM, Brandeis King <brandei...@gmail.com> wrote:

> To clarify, I'm experiencing this issue with xterm and gnome-terminal, both with and without tmux. And yes, I'm using z-shell.

When you press Page Down in xterm or gnome-terminal, it generates four
characters: ESC [ 6 ~. Upon receiving this sequence, Emacs should
translate it back to a [next] key vector.

In order for this to happen, Emacs has to know you’re using an
xterm-compatible terminal. It does that by looking at your TERM
variable.

Your symptoms suggest that the value of the TERM environment variable
does not match your terminal type.

To debug the problem further, you need to list, for each distinct case:

* the complete stack of terminal emulators;
* what the value of TERM is at each layer of that stack.

The shell you are using is mostly irrelevant; the only thing it will
affect is whether and how you set the TERM variable.


For xterm and gnome-terminal, the expected result is:

$ echo $TERM
xterm

or a variation thereof (e.g. xterm-256color).

When you use tmux with xterm or gnome-terminal, TERM should be "xterm"
(or xterm-*) before you start tmux, and "screen" (or screen-*) within
tmux.

(Newer systems, e.g. Ubuntu 16.04, also support a separate "tmux" (and
tmux-*) terminal type. As far as I can tell, Emacs does not yet have
such support.)

Emanuel Berg

unread,
Jul 6, 2016, 10:28:52 AM7/6/16
to
Yuri Khan <yuri....@gmail.com> writes:

> For xterm and gnome-terminal, the expected
> result is:
>
> $ echo $TERM xterm
>
> or a variation thereof (e.g. xterm-256color).
>
> When you use tmux with xterm or gnome-terminal,
> TERM should be "xterm" (or xterm-*) before you
> start tmux, and "screen" (or screen-*)
> within tmux.

Good idea, however if the OP has broken the
buttons by having a wierd TERM, it'll sure be
interesting to know what that is because I just
now tried

$ TERM=x emacs -Q

with x being "linux", "vt100", "xterm" and
"screen" without quotes, and equally without
being able to break the PageUp and PageDown
buttons. (The colors and fonts changed tho.)

Yuri Khan

unread,
Jul 6, 2016, 11:28:18 AM7/6/16
to Emanuel Berg, help-gn...@gnu.org
On Wed, Jul 6, 2016 at 8:28 PM, Emanuel Berg <embe...@student.uu.se> wrote:

> Good idea, however if the OP has broken the
> buttons by having a wierd TERM, it'll sure be
> interesting to know what that is because I just
> now tried
>
> $ TERM=x emacs -Q
>
> with x being "linux", "vt100", "xterm" and
> "screen" without quotes, and equally without
> being able to break the PageUp and PageDown
> buttons. (The colors and fonts changed tho.)

Neither could I. Moreover, when I start "TERM=tmux emacs -Q -nw", the
variable input-decode-map still contains a sequence for ESC [ 5 ~. I
presumed it were added by xterm.el and that by setting a TERM which
Emacs doesn’t know about would prevent that, but it seems at least one
of those assumptions is false.

@Brandeis: Please also show us what you get when you press Ctrl+V PgUp
at the zsh prompt, and what you have in the input-decode-map variable
in emacs -Q -nw.

Brandeis King

unread,
Jul 6, 2016, 3:41:01 PM7/6/16
to
On Wednesday, July 6, 2016 at 11:28:18 AM UTC-4, Yuri Khan wrote:
> Neither could I. Moreover, when I start "TERM=tmux emacs -Q -nw", the
> variable input-decode-map still contains a sequence for ESC [ 5 ~. I
> presumed it were added by xterm.el and that by setting a TERM which
> Emacs doesn’t know about would prevent that, but it seems at least one
> of those assumptions is false.
>
> @Brandeis: Please also show us what you get when you press Ctrl+V PgUp
> at the zsh prompt, and what you have in the input-decode-map variable
> in emacs -Q -nw.

I tried "emacs -Q -nw" again today, and the page up/down buttons do work as expected.

In answer to previously asked questions, term is "screen-256color" -- this is set in my Xresources file -- Ctrl+V PgUp prints ^[[5~

Input-Decode Map variable holds:
Value: (keymap
(27 keymap
(79 keymap
(83 .
[f4])
(82 .
[f3])
(81 .
[f2])
(80 .
[f1])
(66 .
[down])
(67 .
[right])
(65 .
[up])
(68 .
[left]))
(91 keymap
(53 keymap
(126 .
[prior]))
(54 keymap
(126 .
[next]))
(90 .
[backtab])
(51 keymap
(126 .
[deletechar]))
(50 keymap
(52 keymap
(126 .
[f12]))
(51 keymap
(126 .
[f11]))
(49 keymap
(126 .
[f10]))
(48 keymap
(126 .
[f9]))
(126 .
[insertchar]))
(52 keymap
(126 .
[end]))
(49 keymap
(57 keymap
(126 .
[f8]))
(56 keymap
(126 .
[f7]))
(55 keymap
(126 .
[f6]))
(53 keymap
(126 .
[f5]))
(126 .
[home])))))

Yuri Khan

unread,
Jul 7, 2016, 12:48:13 AM7/7/16
to Brandeis King, help-gn...@gnu.org
On Thu, Jul 7, 2016 at 1:40 AM, Brandeis King <brandei...@gmail.com> wrote:

> I tried "emacs -Q -nw" again today, and the page up/down buttons do work as expected.

So then the problem is in most probably in your init file.

> In answer to previously asked questions, term is "screen-256color" -- this is set in my Xresources file

That’s a bad idea. You are lying to tmux that its underlying terminal
is screen-like, while it is in fact xterm-like. Additionally, other
programs, if you run them outside tmux, will misbehave.

Normally, tmux sets the TERM variable for processes running within its
session. It uses "screen" by default, but you can control it with this
line in your .tmux.conf:

set -g default-terminal "screen-256color"

> Input-Decode Map variable holds:
> Value: (keymap
> (27 keymap
[…]
> (91 keymap
> (53 keymap
> (126 .
> [prior]))
> (54 keymap
> (126 .
> [next]))

These are the decoding sequences for Page Up and Page Down. When you
start Emacs with your customizations, you can look for these. If they
are not there, find what deletes them.

Also, see if you are binding M-[ or ESC [ to anything. If you do, many
function keys, including Page Up and Page Down, will probably stop
working.

0 new messages