Highlighting a region in emacs is invisible because region color equals window color

Bug #1628707 reported by Daniel Barrett
32
This bug affects 7 people
Affects Status Importance Assigned to Milestone
emacs (Ubuntu)
New
Undecided
Unassigned
emacs24 (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

If you open an Emacs window in Plasma/KDE, and you try to highlight a region of text by dragging the mouse, no highlighting appears. This is because the color for highlighting a region is identical to the color for the window background. I believe this color clash occurs between Ubuntu's emacs24 package and Ubuntu's X resource settings.

To reproduce, log into Plasma, remove your $HOME/.emacs init file (so you have no personal customizations), and run emacs in an X window:

  $ emacs

The window's background color is a light gray. Then type any text, click and drag the mouse over the text (or use keystroke commands to define a region). No highlighting appears, because the "region" color is also light gray. You can see this by running the emacs command:

  M-x list-faces-display <ENTER>

I'll attach a screenshot so you can see that the "region" highlighting doesn't show up.

The problem goes away if you disable the Ubuntu-supplied emacs init files:

  $ emacs -Q

This is why I suspect the color is set badly in the Ubuntu emacs24 package.

You can see the X background color by running the "appres" command in a shell window, which proves a light gray background is set, the same color as region highlighting:

  *background: #eff0f1

I tried to find the file where this background color is set, but I was not successful.

ProblemType: Bug
DistroRelease: Ubuntu 16.04
Package: emacs24 24.5+1-6ubuntu1
ProcVersionSignature: Ubuntu 4.4.0-38.57-generic 4.4.19
Uname: Linux 4.4.0-38-generic x86_64
ApportVersion: 2.20.1-0ubuntu2.1
Architecture: amd64
CurrentDesktop: KDE
Date: Wed Sep 28 18:07:25 2016
InstallationDate: Installed on 2016-09-25 (3 days ago)
InstallationMedia: Kubuntu 16.04.1 LTS "Xenial Xerus" - Release amd64 (20160719)
SourcePackage: emacs24
UpgradeStatus: No upgrade log present (probably fresh install)

Revision history for this message
Daniel Barrett (dbarrett-m) wrote :
Revision history for this message
Daniel Barrett (dbarrett-m) wrote :

It's possible that some X resource hidden in my account is setting the background color. Can someone please tell me where to look for these resource settings?

Revision history for this message
Joachim Klaehn (chipknecht) wrote :

Hello, i have got the same problem.

emacs -q shows the error
emacs -Q doesn't

lets me assume either emacs is doing something worong when getting x configuration or x config is wrong

my work around was putting following line to my .emacs file

(set-face-attribute 'region nil :background "#666" :foreground "#ffffff")

to set back and foreground of selection manually, which solved the problem

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in emacs24 (Ubuntu):
status: New → Confirmed
Revision history for this message
Olivier Robert (novhak) wrote :

This problem has been around for a long time now...

It's probably compiled-in, and comes from the region face setup. By default, the region face background is set to gtk_selection_bg_color, which must correspond to light grey.

It's possible to change this from the X interface in Options => Customize Emacs => Top-level Customization Group, and from there going to the following subgroups : Faces => Basic Faces. Scroll down to the region face, and choose the background of your choice. Then, go back up in the buffer, click Apply and save and you're done.

You could also choose another theme instead : Options => Customize Emacs => Custom Themes. Choose your theme and click Save Theme Settings.

tags: added: hirsute
Revision history for this message
Olivier Robert (novhak) wrote :

Some more information.

It seems the problem comes from the fact that the concept of a background color has been deprecated in recent versions of GTK, and no replacement has been made in the Emacs code : https://lists.gnu.org/archive/html/bug-gnu-emacs/2017-09/msg01099.html

Emacs fails to load an appropriate bg color and seems to default to this almost invisible light grey.

Revision history for this message
Ivan Zakharyaschev (imz) wrote :
Download full text (8.7 KiB)

I experience this or a similar problem with emacs-26 on Ubuntu 20.04 (the standard Gnome DE).

Somehow having the "region" face set to having gtk_selection_bg_color makes the selected region not noticeable (or hardly noticeable?..). I have delete-selection-mode enabled.

After changing it, it is OK; to yellow in my case:

(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(region ((t (:background "yellow" :distant-foreground "gtk_selection_fg_color")))))

I wonder why the selection in Firefox is noticeable and has the standard orange-brown color whereas Emacs doesn't get it.

ProblemType: Bug
ApportVersion: 2.20.11-0ubuntu27.20
Architecture: amd64
CasperMD5CheckResult: skip
Date: Wed Oct 6 20:08:01 2021
Dependencies:
 adduser 3.118ubuntu2
 adwaita-icon-theme 3.36.1-2ubuntu0.20.04.2
 alsa-topology-conf 1.2.2-1
 alsa-ucm-conf 1.2.2-1ubuntu0.10
 apt 2.0.6
 apt-utils 2.0.6
 at-spi2-core 2.36.0-2
 ca-certificates 20210119~20.04.2
 coreutils 8.30-3ubuntu2
 dbus 1.12.16-2ubuntu2.1
 dconf-gsettings-backend 0.36.0-1
 dconf-service 0.36.0-1
 debconf 1.5.73
 debconf-i18n 1.5.73
 dpkg 1.19.7ubuntu3
 emacs-bin-common 1:26.3+1-1ubuntu2
 emacs-common 1:26.3+1-1ubuntu2
 emacs-el 1:26.3+1-1ubuntu2
 emacs-gtk 1:26.3+1-1ubuntu2
 emacsen-common 3.0.4
 fontconfig 2.13.1-2ubuntu3
 fontconfig-config 2.13.1-2ubuntu3
 fonts-dejavu-core 2.37-1
 fonts-droid-fallback 1:6.0.1r16-1.1
 fonts-noto-mono 20200323-1build1~ubuntu20.04.1
 fonts-urw-base35 20170801.1-3
 gcc-10-base 10.3.0-1ubuntu1~20.04
 ghostscript 9.50~dfsg-5ubuntu4.3
 glib-networking 2.64.2-1ubuntu0.1
 glib-networking-common 2.64.2-1ubuntu0.1
 glib-networking-services 2.64.2-1ubuntu0.1
 gpgv 2.2.19-3ubuntu2.1
 gsettings-desktop-schemas 3.36.0-1ubuntu1
 gsfonts 1:8.11+urwcyr1.0.7~pre44-4.4
 gtk-update-icon-cache 3.24.20-0ubuntu1
 hicolor-icon-theme 0.17-2
 humanity-icon-theme 0.6.15
 imagemagick-6-common 8:6.9.10.23+dfsg-2.1ubuntu11.4
 install-info 6.7.0.dfsg.2-5
 krb5-locales 1.17-6ubuntu4.1
 libacl1 2.2.53-6
 libapparmor1 2.13.3-7ubuntu5.1
 libapt-pkg6.0 2.0.6
 libasound2 1.2.2-2.1ubuntu2.4
 libasound2-data 1.2.2-2.1ubuntu2.4
 libatk-bridge2.0-0 2.34.2-0ubuntu2~20.04.1
 libatk1.0-0 2.35.1-1ubuntu2
 libatk1.0-data 2.35.1-1ubuntu2
 libatspi2.0-0 2.36.0-2
 libattr1 1:2.4.48-5
 libaudit-common 1:2.8.5-2ubuntu6
 libaudit1 1:2.8.5-2ubuntu6
 libavahi-client3 0.7-4ubuntu7.1
 libavahi-common-data 0.7-4ubuntu7.1
 libavahi-common3 0.7-4ubuntu7.1
 libblkid1 2.34-0.1ubuntu9.1
 libbrotli1 1.0.7-6ubuntu0.1
 libbsd0 0.10.0-1
 libbz2-1.0 1.0.8-2
 libc6 2.31-0ubuntu9.2
 libcairo-gobject2 1.16.0-4ubuntu1
 libcairo2 1.16.0-4ubuntu1
 libcap-ng0 0.7.9-2.1build1
 libcolord2 1.4.4-2
 libcom-err2 1.45.5-2ubuntu1
 libcrypt1 1:4.4.10-10ubuntu4
 libcups2 2.3.1-9ubuntu1.1
 libdatrie1 0.2.12-3
 libdb5.3 5.3.28+dfsg1-0.6ubuntu2
 libdbus-1-3 1.12.16-2ubuntu2.1
 libdconf1 0.36.0-1
 libepoxy0 1.5.4-1
 libexpat1 2.2.9-1build1
 libffi7 3.3-4
 libfftw3-double3 3.3.8-2ubuntu1
 libfontconfig1 2.13.1-2ubuntu3
 libfreetype6 2.10.1-2ubuntu0.1
 libfribidi0 1.0.8-2
 ...

Read more...

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.