]> code.delx.au - gnu-emacs-elpa/commitdiff
* packages/nlinum/nlinum.el (nlinum-mode): Don't leave overlays around when
authorStefan Monnier <monnier@iro.umontreal.ca>
Mon, 26 May 2014 23:18:05 +0000 (19:18 -0400)
committerStefan Monnier <monnier@iro.umontreal.ca>
Mon, 26 May 2014 23:18:05 +0000 (19:18 -0400)
switching major mode.

packages/nlinum/nlinum.el

index 750ebc01b33a08fe47f3b760cb80c17f54b9d06d..41b79b6f44c01793c246ce17932584103be66414 100644 (file)
@@ -54,12 +54,15 @@ 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))
@@ -136,6 +139,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))