X-Git-Url: https://code.delx.au/gnu-emacs-elpa/blobdiff_plain/37fc4433fb7e0f99a0ff74ddb23075127b7e4656..c7f675e016968265d24265c0d7c8662f20b0f2bb:/packages/nlinum/nlinum.el diff --git a/packages/nlinum/nlinum.el b/packages/nlinum/nlinum.el index 750ebc01b..82e274c7a 100644 --- a/packages/nlinum/nlinum.el +++ b/packages/nlinum/nlinum.el @@ -4,7 +4,7 @@ ;; Author: Stefan Monnier ;; Keywords: convenience -;; Version: 1.3 +;; Version: 1.5 ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by @@ -54,20 +54,34 @@ Linum mode is a buffer-local minor mode." :lighter nil ;; (" NLinum" nlinum--desc) (jit-lock-unregister #'nlinum--region) (remove-hook 'window-configuration-change-hook #'nlinum--setup-window t) - (remove-hook 'after-change-functions #'nlinum--after-change) + (remove-hook 'after-change-functions #'nlinum--after-change t) (kill-local-variable 'nlinum--line-number-cache) (remove-overlays (point-min) (point-max) 'nlinum t) ;; (kill-local-variable 'nlinum--ol-counter) (kill-local-variable 'nlinum--width) (when nlinum-mode + ;; FIXME: Another approach would be to make the mode permanent-local, + ;; which might indeed be preferable. + (add-hook 'change-major-mode-hook (lambda () (nlinum-mode -1))) (add-hook 'window-configuration-change-hook #'nlinum--setup-window nil t) (add-hook 'after-change-functions #'nlinum--after-change nil t) (jit-lock-register #'nlinum--region t)) (nlinum--setup-windows)) +(defun nlinum--face-height (face) + (aref (font-info (face-font face)) 2)) + (defun nlinum--setup-window () - (set-window-margins nil (if nlinum-mode nlinum--width) - (cdr (window-margins)))) + (let ((width (if (display-graphic-p) + (ceiling + ;; We'd really want to check the widths rather than the + ;; heights, but it's a start. + (/ (* nlinum--width 1.0 + (nlinum--face-height 'linum)) + (frame-char-height))) + nlinum--width))) + (set-window-margins nil (if nlinum-mode width) + (cdr (window-margins))))) (defun nlinum--setup-windows () (dolist (win (get-buffer-window-list nil nil t)) @@ -136,6 +150,14 @@ Linum mode is a buffer-local minor mode." (defvar nlinum--line-number-cache nil) (make-variable-buffer-local 'nlinum--line-number-cache) +;; We could try and avoid flushing the cache at every change, e.g. with: +;; (defun nlinum--before-change (start _end) +;; (if (and nlinum--line-number-cache +;; (< start (car nlinum--line-number-cache))) +;; (save-excursion (goto-char start) (nlinum--line-number-at-pos)))) +;; But it's far from clear that it's worth the trouble. The current simplistic +;; approach seems to be good enough in practice. + (defun nlinum--after-change (&rest _args) (setq nlinum--line-number-cache nil))