12

I get this graphical error with linum-mode in my Emacs. I tried upgrading from 23 to 24 (via git) and I've tried both with various supplied binaries online and with my home-compiled version. What I'm really interested in is where to start diagnosing the problem.

"Tearing" of numbers in linum-mode

The problem goes away if I scroll the torn line numbers off screen and back in.

Sarah
  • 6,565
  • 1
  • 33
  • 44

5 Answers5

11

I have experienced the same problem and spent quite some time trying to resolve it. The graphical error is a result of a clash between linum-mode and how the fringe is rendered. Unfortunately, I was unable to resolve the problem in linum.el, and the fringe display code is part of the C-source.

It can still be done! The easiest way to fix it is to just turn off the fringe.

M-x fringe-mode RET none RET

To make the fringe permanently stay off, I recommend customizing the settings with M-x customize-group RET fringe because some compiled versions of Emacs for Mac OS X have their own fringe settings that can override parts of your .emacs file.

I don't really need those line wrap indicators, so not having a fringe doesn't bother me. However, I did miss a slight separation between the line numbers and the buffer text. I followed the advice of a post on the Emacs Wiki to get that spacing back. In version 0.9x of linum, change line 160 from

(setq width (max width (length str)))

to

(setq width (max width (+ (length str) 1)))

The inspiration for this change is here: http://www.emacswiki.org/emacs/LineNumbers

There are arguments at the source link to set the linum-format variable instead of modifying linum.el. While I understand where they are coming from, most color-themes these days would color the extra space and not provide what I am looking for (a separation of about a space that is the background color). If you do edit linum.el, make sure to run

M-x emacs-lisp-byte-compile-and-load

to make the changes persistent. You can see the result of this by looking at the space before the cursor in the picture found here: https://i.stack.imgur.com/TxyMr.png (I don't have enough reputation to embed images).

No more graphical artifacts!

Pat O'Keefe
  • 146
  • 1
  • 5
8

I had the same problem and I figured out a solution and while it's not the prettiest, due to an extra space to the left of the line number, it's much more elegant than changing the linum.el. Here is the pertinent part of my ~/.emacs:

;; Linum mode                                                                                                                                                                                                                           
(global-linum-mode t)                                                                                                                                                                                                                   
;; Offset the number by two spaces to work around some weird fringe glitch                                                                                                                                                                     
(setq linum-format "  %d ")

This removes the fringe overlay issue and does not have any other impact other than offsetting the line number.

Jeremy Whitlock
  • 3,808
  • 26
  • 16
1

to make a separation between the line numbers and the buffer text, the follow change will be better:

In version 0.9x of linum, change line 150 from

(concat "%" (number-to-string w) "d")))))

to

(concat "%" (number-to-string w) "d ")))))

This make the separation have the same background color with line numbers'.

jessex
  • 201
  • 1
  • 4
  • Editing the original code isn't a great idea, though. I would suggest adopting the code at the following answer, and making the change to that instead: http://stackoverflow.com/a/11496199/324105 – phils Jul 17 '12 at 03:30
0

The problem was still here on emacs 24.4, OS X 10.10.1. The solution I worked out: after loading the theme of your choice:

(load-theme 'whatever)
(set-face-attribute 'fringe nil :background (face-background 'default))
D A Vincent
  • 364
  • 2
  • 21
wangii
  • 2,570
  • 1
  • 22
  • 29
0

This is how I have it setup in my .emacs and I don't have the problem, although I also don't use emacs with gtk or any other gui.

(linum-mode +1)

(setq linum-format "%d ")

You might want to hack around with (setq linum-format) to see if you can get good results. Also don't forget to browse emacswiki on linum.

Community
  • 1
  • 1