emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Redisplay bug in margin


From: Richard Stallman
Subject: Re: Redisplay bug in margin
Date: Mon, 24 Sep 2007 14:19:49 -0400

Now that Stephen has given us a precise test case,
would someone please fix this bug and ack?

To: address@hidden
From: Stephen Berman <address@hidden>
Date: Mon, 24 Sep 2007 00:49:44 +0200
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
Subject: Re: Redisplay bug in margin

--=-=-=

On Sun, 23 Sep 2007 17:54:35 -0400 Richard Stallman <address@hidden> wrote:

>     (load-file "<path/to/linum.el>") ;; linum.el version 0.9t
>
> That's not complete.  Could you post it again with a copy
> of the requisite linum.el code?

Sorry, I had misread "including a copy of a version of linum that
causes the failure" as requesting just the version number.  I attach
linum.el version 0.9t to this message; but again, note that the latest
version, 0.9u+ does not show the bug with Emacs 22.1 (though both
versions 0.9t and 0.9u+ show it with CVS Emacs from the trunk).  For
comparison, I also attach a diff between versions 0.9t and 0.9u+.  And
for completeness, here's the recipe again:

1. Save the following lines to  ~/linum-test.el:

(load-file "<path/to/linum.el>") ;; linum.el version 0.9t
(setq linum-format
      (lambda (line)
        (propertize (format "%d" line) 'face 'linum)))
(setq confirm-kill-emacs 'y-or-n-p)

2. emacs -q -l ~/linum-test.el ;; Emacs 22.1

3. M-x display-splash-screen

4. M-x linum-mode

5. C-x C-c

Steve Berman


--=-=-=
Content-Type: text/x-emacs-lisp
Content-Disposition: attachment; filename=linum.el
Content-Description: linum.el version 0.9t

;;; linum.el --- Display line numbers to the left of buffers

;; Copyright (C) 2007  Markus Triska

;; Author: Markus Triska <address@hidden>
;; Keywords: convenience

;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.

;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.

;;; Commentary:

;; Display line numbers for the current buffer. Copy linum.el to your
;; load-path and add to your .emacs:

;;    (require 'linum)

;; Then toggle display of line numbers with M-x linum-mode.

;;; Code:

(defconst linum-version "0.9t")

(defvar linum-overlays nil "Overlays used in this buffer.")
(defvar linum-available nil "Overlays available for reuse.")
(defvar linum-before-numbering nil
  "Functions run in each buffer before line numbering starts.")

(mapc #'make-variable-buffer-local '(linum-overlays linum-available))

(defgroup linum nil
  "Show line numbers to the left of buffers"
  :group 'convenience)

;;;###autoload
(defcustom linum-format 'dynamic
  "Format used to display line numbers. Either a format string
like \"%7d\", 'dynamic to adapt the width as needed, or a
function that is called with a line number as its argument and
should evaluate to a string to be shown on that line. See also
`linum-before-numbering'."
  :group 'linum
  :type 'sexp)

(defface linum
  '((t :inherit shadow))
  "Face for displaying line numbers in the display margin."
  :group 'linum)

(defcustom linum-eager t
  "Whether line numbers should be updated after each command.
The conservative setting `nil' might miss some buffer changes,
and you have to scroll or press C-l to update the numbers."
  :group 'linum
  :type 'boolean)

(defcustom linum-delay t
  "Whether updates should be delayed to give Emacs a chance for
other changes."
  :group 'linum
  :type 'boolean)

;;;###autoload
(define-minor-mode linum-mode
  "Toggle display of line numbers in the left marginal area."
  :lighter ""                           ; for desktop.el
  (if linum-mode
      (progn
        (if linum-eager
            (add-hook 'post-command-hook (if linum-delay
                                             'linum-schedule
                                           'linum-update-current) nil t)
          (add-hook 'after-change-functions 'linum-after-change nil t))
        (add-hook 'window-scroll-functions 'linum-after-scroll nil t)
        (add-hook 'window-size-change-functions 'linum-after-size)
        (add-hook 'change-major-mode-hook 'linum-delete-overlays nil t)
        (add-hook 'window-configuration-change-hook
                  'linum-after-config nil t)
        (linum-update-current)
        (message "Linum mode enabled"))
    (remove-hook 'post-command-hook 'linum-update-current t)
    (remove-hook 'post-command-hook 'linum-schedule t)
    (remove-hook 'window-size-change-functions 'linum-after-size)
    (remove-hook 'window-scroll-functions 'linum-after-scroll t)
    (remove-hook 'after-change-functions 'linum-after-change t)
    (remove-hook 'window-configuration-change-hook 'linum-after-config t)
    (remove-hook 'change-major-mode-hook 'linum-delete-overlays t)
    (linum-delete-overlays)
    (message "Linum mode disabled")))

;;;###autoload
(define-globalized-minor-mode global-linum-mode linum-mode linum-on)

(defun linum-on ()
  (unless (minibufferp)
    (linum-mode 1)))

(defun linum-delete-overlays ()
  "Delete all overlays displaying line numbers for this buffer."
  (mapc #'delete-overlay linum-overlays)
  (setq linum-overlays nil)
  (dolist (w (get-buffer-window-list (current-buffer) nil t))
    (set-window-margins w 0)))

(defun linum-update-current ()
  "Update line numbers for the current buffer."
  (linum-update (current-buffer)))

(defun linum-update (buffer)
  "Update line numbers for all windows displaying BUFFER."
  (with-current-buffer buffer
    (when linum-mode
      (setq linum-available linum-overlays)
      (setq linum-overlays nil)
      (save-excursion
        (mapc #'linum-update-window
              (get-buffer-window-list buffer nil 'visible)))
      (mapc #'delete-overlay linum-available)
      (setq linum-available nil))))

(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 (1+ (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)
        ov)
    (run-hooks 'linum-before-numbering)
    ;; Create an overlay (or reuse an existing one) for each
    ;; line visible in this window.
    (while (and (not (eobp)) (< (point) limit))
      (let ((str (if fmt
                   (propertize (format fmt line) 'face 'linum)
                 (funcall linum-format line))))
        (setq width (max width (length str)))
        (if (null linum-available)
            (setq ov (make-overlay (point) (point)))
          (setq ov (pop linum-available))
          (move-overlay ov (point) (point)))
        (push ov linum-overlays)
        (setq str (propertize " " 'display `((margin left-margin) ,str)))
        (overlay-put ov 'before-string str))
      (forward-line)
      (setq line (1+ line)))
    (set-window-margins win width)))

(defun linum-after-change (beg end len)
  ;; update overlays on deletions, and after newlines are inserted
  (when (or (= beg end)
            (= end (point-max))
            ;; TODO: use string-match-p with CVS or new release
            (string-match "\n" (buffer-substring-no-properties beg end)))
    (linum-update-current)))

(defun linum-after-scroll (win start)
  (linum-update (window-buffer win)))

(defun linum-after-size (frame)
  (linum-after-config))

(defun linum-schedule ()
  ;; schedule an update; the delay gives Emacs a chance for display changes
  (run-with-idle-timer 0 nil #'linum-update-current))

(defun linum-after-config ()
  (walk-windows (lambda (w)
                  (with-current-buffer (window-buffer w)
                    (when linum-mode
                      (save-excursion
                        (linum-update-window w))))) nil 'visible))

(provide 'linum)
;;; linum.el ends here

--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment; filename=linum-09t-09u+.diff
Content-Description: linum-09t-09u+.diff

*** linum.el    2007-09-16 16:29:19.000000000 +0200     version 0.9t
--- linum.el    2007-09-23 14:44:19.000000000 +0200     version 0.9u+
***************
*** 31,37 ****
  
  ;;; Code:
  
! (defconst linum-version "0.9t")
  
  (defvar linum-overlays nil "Overlays used in this buffer.")
  (defvar linum-available nil "Overlays available for reuse.")
--- 31,37 ----
  
  ;;; Code:
  
! (defconst linum-version "0.9u+")
  
  (defvar linum-overlays nil "Overlays used in this buffer.")
  (defvar linum-available nil "Overlays available for reuse.")
***************
*** 88,95 ****
          (add-hook 'change-major-mode-hook 'linum-delete-overlays nil t)
          (add-hook 'window-configuration-change-hook
                    'linum-after-config nil t)
!         (linum-update-current)
!         (message "Linum mode enabled"))
      (remove-hook 'post-command-hook 'linum-update-current t)
      (remove-hook 'post-command-hook 'linum-schedule t)
      (remove-hook 'window-size-change-functions 'linum-after-size)
--- 88,94 ----
          (add-hook 'change-major-mode-hook 'linum-delete-overlays nil t)
          (add-hook 'window-configuration-change-hook
                    'linum-after-config nil t)
!         (linum-update-current))
      (remove-hook 'post-command-hook 'linum-update-current t)
      (remove-hook 'post-command-hook 'linum-schedule t)
      (remove-hook 'window-size-change-functions 'linum-after-size)
***************
*** 97,104 ****
      (remove-hook 'after-change-functions 'linum-after-change t)
      (remove-hook 'window-configuration-change-hook 'linum-after-config t)
      (remove-hook 'change-major-mode-hook 'linum-delete-overlays t)
!     (linum-delete-overlays)
!     (message "Linum mode disabled")))
  
  ;;;###autoload
  (define-globalized-minor-mode global-linum-mode linum-mode linum-on)
--- 96,102 ----
      (remove-hook 'after-change-functions 'linum-after-change t)
      (remove-hook 'window-configuration-change-hook 'linum-after-config t)
      (remove-hook 'change-major-mode-hook 'linum-delete-overlays t)
!     (linum-delete-overlays)))
  
  ;;;###autoload
  (define-globalized-minor-mode global-linum-mode linum-mode linum-on)
***************
*** 180,190 ****
    (run-with-idle-timer 0 nil #'linum-update-current))
  
  (defun linum-after-config ()
!   (walk-windows (lambda (w)
!                   (with-current-buffer (window-buffer w)
!                     (when linum-mode
!                       (save-excursion
!                         (linum-update-window w))))) nil 'visible))
  
  (provide 'linum)
  ;;; linum.el ends here
--- 178,184 ----
    (run-with-idle-timer 0 nil #'linum-update-current))
  
  (defun linum-after-config ()
!   (walk-windows (lambda (w) (linum-update (window-buffer))) nil 'visible))
  
  (provide 'linum)
  ;;; linum.el ends here

--=-=-=
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Emacs-devel mailing list
address@hidden
http://lists.gnu.org/mailman/listinfo/emacs-devel
--=-=-=--








reply via email to

[Prev in Thread] Current Thread [Next in Thread]