8

There's some weird stuff I encounter when running Emacs under KDE.

Here's how it looks when I run it normally, via the emacs command:

normal emacs

If I run it as a daemon, here's what I see:

emacsclient

And if I run customize-face cursor in the emacsclient, here's what I see:

emacsclient customize face

The face is changed outside customize. What could've changed it? How can I prevent it?

I need to say that under Xfce I don't get anything of sorts.

P. S. Apparently, --no-init-file solves the problem. Here's my .emacs. The rest of the files are located here.

P. P. S. This recipe worked for me. In fact, it worked so well that even removing these lines from ~/.Xresources and restarting the PC didn't bring back the errors. I can set the cursor face with customize-face and it'll start in the daemon keeping that setting. So that's nice.

art-solopov
  • 235
  • 1
  • 11
  • 2
    Can you reproduce it when running `emacs -Q`? I've had a similiar issue that arose from a `.Xresources` file which happened to have a cursor color set and thus affected the Emacs daemon. – wasamasa Jun 19 '15 at 21:59
  • @wasamasa huh. The 'changed outside Customize' stuff did disappear in the `-Q` mode. Thank you very much! I'll try looking into my `.X` files. – art-solopov Jun 19 '15 at 22:10
  • 1
    The problem is in your emacs config. Gradually comment out stuff from your .emacs till the problem goes away. – Kaushal Modi Jun 20 '15 at 12:12
  • @wasamasa [This recipe](http://ftp.gnu.org/old-gnu/Manuals/emacs-lisp-intro/html_node/X11-Colors.html) actually work for me, even if it looks hacky. – art-solopov Jun 20 '15 at 12:53
  • @kaushalmodi Thanks, will try to do so. – art-solopov Jun 20 '15 at 12:53

4 Answers4

5

try to add this code in init.el and restart the daemon:

(require 'frame)
(defun set-cursor-hook (frame)
(modify-frame-parameters
  frame (list (cons 'cursor-color "DeepSkyBlue"))))

(add-hook 'after-make-frame-functions 'set-cursor-hook)
zarkone
  • 166
  • 1
  • 5
2

In addition to zarkone's answer, there's a variable that controls whether Emacs should infer X resources: inhibit-x-resources. Setting it to t would disallow Emacs to use any X resources, relying on its own colors.

art-solopov
  • 235
  • 1
  • 11
  • 1
    seems like i have another reason of my cursor misbehaving, still have white cursor in new frame ='( – zarkone Aug 10 '15 at 03:03
2

The hypothesis

The problem should come from Xressources.

The Xressources are set via xrdb calls. The user-space place to store Xressources settings is ~/.Xressources (that usually are read and applicated via xrdb -merge ~/.Xressources on login). But other than that, there are plenty of mechanisms that can call xrdb (xinit, XSession, display-manager, desktop-environment). KDE for instance does set a lot of Xressources on login (still trying to figure out where these settings all come from).

Test the hypothesis

  • Check the output of xrdb -query -all (e.g. see if you have some 'Emacs*' stuff in there).
  • Save your current Xressource settings: xrdb -query -all >~/.Xressources.backup
  • Try to run xrdb -remove (to clear all Xressources settings)
  • Now try running emacs. If this works, then check the Xressources you might want to keep (I only kept Xft.dpi: 168 because of my hires screen).
  • For now restore the Xressources running: xrdb -merge ~/.Xressources.backup

Also once you logout and login again your Xressources will be back to how they were before this test!

Permanent solution:

If you have no problems with emacs any after above Test the hypothesis, then you probably want to figure out what Xressources to keep. Look through ~/.Xressources.backup.

At this point there are plenty of possibilities. For example you can: * Fix the Xressources before you run emacs. * Fix the Xressources on login.

I decided to always on login make sure only a minimal set of Xressources is applied by creating (or adding to) ~/.xinitrd:

# Clean XressourcesDatabase xrdb
xrdb -remove
# Set only value NECESSARY for DPI zooming of applications
echo "Xft.dpi:        168"|xrdb -merge

Alternatively you may store the necessary Xressources in ~/.Xressources.minimal for instance and then add this to your .xinitrc:

# Clean XressourcesDatabase xrdb
xrdb -remove
# Apply the minimal set of Xressources
xrdb -merge ~/.Xressources.minmal

I hope this is clear and helpful.

Tormen
  • 21
  • 1
1

You said you were on KDE, I have the same issue, which this post was helpful to find the root cause.

First xrdb -query -all | grep -i emacs, revealed some entries for Emacs which I didn't set myself:

$ xrdb -query -all | grep -i emacs
Emacs*Background:   #fcfcfc
Emacs*Dialog*background:    #eff0f1
Emacs*Dialog*foreground:    #31363b
Emacs*Foreground:   #31363b
...

Searching the disk for the files defining these entries I found:

$ grep -Fnr 'Emacs*XlwScrollBar' /etc /usr/share 2>/dev/null
/usr/share/kdisplay/app-defaults/Emacs.ad:12:Emacs*XlwScrollBar.Foreground: FOREGROUND
/usr/share/kdisplay/app-defaults/Emacs.ad:13:Emacs*XlwScrollBar.Background: BACKGROUND

By searching about this file /usr/share/kdisplay/app-defaults/Emacs.ad, I found this old but relevant thread on the Emacs mailing list:

Apparently KDE sets some X resources for applications like Emacs, so that the application look'n'feel matches the KDE theme.

This thread suggests to remove only the attributes that aren't desired but to keep others so the look'n'feel stays close to the KDE theme:

In this way, KDE still changes the colors/fonts of other applications AND also some things in Emacs (like the Menubar for example, which matches the KDE-menus colors/font).

Note: I could not find a difference in the look'n'feel after commenting the whole file, so it's possible that this is no longer needed even for Menubar and other graphical elements that the resource file sets.

My issue was just the cursor color, which is solved by commenting Emacs*Foreground:

Emacs.default.attributeForeground:  WINDOW_FOREGROUND
Emacs.default.attributeBackground:  WINDOW_BACKGROUND

! breaks Emacs cursor color
! Emacs*Foreground:     WINDOW_FOREGROUND
Emacs*Background:       WINDOW_BACKGROUND
Emacs*menubar*foreground:   FOREGROUND
Emacs*menubar*background:   BACKGROUND
...
Guillaume Papin
  • 886
  • 6
  • 7