GNU bug report logs - #4996
23.1; linum mode fails to number lines properly when just scrolling buffer

Previous Next

Package: emacs;

Reported by: mark.lillibridge <at> hp.com

Date: Sat, 21 Nov 2009 05:40:05 UTC

Severity: normal

Done: Stefan Monnier <monnier <at> IRO.UMontreal.CA>

Bug is archived. No further changes may be made.

Full log


Message #15 received at 4996 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Mark Lillibridge <mark.lillibridge <at> hp.com>
To: mark.lillibridge <at> hp.com
Cc: 4996 <at> debbugs.gnu.org
Subject: Re: problem found
Date: Fri, 20 Nov 2009 22:24:17 -0800
    Ok, I have a proposed patch for linum.el that solves the problem
with it displaying incorrect line numbers in the presence of intangible
text.

The original version of linum.el has:

linum.el:129:
(defun linum-update-window (win)
  "Update line numbers for the portion visible in window WIN."
  (goto-char (window-start win))
  (let ((line (line-number-at-pos))
        (limit (window-end win t))
        (fmt (cond ((stringp linum-format) linum-format)
                   ((eq linum-format 'dynamic)
                    (let ((w (length (number-to-string
                                      (count-lines (point-min) (point-max))))))
                      (concat "%" (number-to-string w) "d")))))
        (width 0))
    (run-hooks 'linum-before-numbering-hook)
    ;; Create an overlay (or reuse an existing one) for each
    ;; line visible in this window, if necessary.
    (while (and (not (eobp)) (<= (point) limit))
      (let* ((str (if fmt
                      (propertize (format fmt line) 'face 'linum)
                    (funcall linum-format line)))
             (visited (catch 'visited
                        (dolist (o (overlays-in (point) (point)))
                          (when (equal-including-properties
				 (overlay-get o 'linum-str) str)
                            (unless (memq o linum-overlays)
                              (push o linum-overlays))
                            (setq linum-available (delq o linum-available))
                            (throw 'visited t))))))
        (setq width (max width (length str)))
        (unless visited
          (let ((ov (if (null linum-available)
                        (make-overlay (point) (point))
                      (move-overlay (pop linum-available) (point) (point)))))
            (push ov linum-overlays)
            (overlay-put ov 'before-string
                         (propertize " " 'display `((margin left-margin) ,str)))
            (overlay-put ov 'linum-str str))))
      (forward-line)
      (setq line (1+ line)))
    (set-window-margins win width)))


The problem here is the third to last line,

linum.el:164:
      (forward-line)

Linum assumes this will move at most one logical line forward, when
in the presence of intangible text it can move an arbitrary number of
logical lines forward.  *BUG*


I propose changing that line to:

      (let ((old-inhibit inhibit-point-motion-hooks))
	(setq inhibit-point-motion-hooks t)
	(forward-line)
	(setq inhibit-point-motion-hooks old-inhibit))

    I have verified that this causes the correct line numbers to be
shown, both with and without being called via the scrolling hook.


Comments?

- Mark




This bug report was last modified 15 years and 182 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.