简体   繁体   中英

What causes this graphical error in emacs with linum-mode on OS X?

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.

在linum模式中“撕裂”数字

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

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 Mx 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: http://i.stack.imgur.com/TxyMr.png (I don't have enough reputation to embed images).

No more graphical artifacts!

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.

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'.

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))

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM