[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/nlinum 99d0fef 16/20: * packages/nlinum/nlinum.el (nlin
From: |
Stefan Monnier |
Subject: |
[elpa] externals/nlinum 99d0fef 16/20: * packages/nlinum/nlinum.el (nlinum-widen): New custom var |
Date: |
Sat, 28 Nov 2020 18:42:25 -0500 (EST) |
branch: externals/nlinum
commit 99d0fef381e9f44a3fdcf66f28c28109a7cdaf45
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>
* packages/nlinum/nlinum.el (nlinum-widen): New custom var
(nlinum--line-number-at-pos): Use it.
(nlinum--last-point-min): New var.
(nlinum--check-narrowing): New function.
(nlinum-mode): Use it.
---
nlinum.el | 63 ++++++++++++++++++++++++++++++++++++++++++++++++---------------
1 file changed, 48 insertions(+), 15 deletions(-)
diff --git a/nlinum.el b/nlinum.el
index 97efee8..99d32e7 100644
--- a/nlinum.el
+++ b/nlinum.el
@@ -1,10 +1,10 @@
;;; nlinum.el --- Show line numbers in the margin -*- lexical-binding: t -*-
-;; Copyright (C) 2012, 2014-2017 Free Software Foundation, Inc.
+;; Copyright (C) 2012, 2014-2019 Free Software Foundation, Inc.
;; Author: Stefan Monnier <monnier@iro.umontreal.ca>
;; Keywords: convenience
-;; Version: 1.8.1
+;; Version: 1.9
;; 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
@@ -24,7 +24,10 @@
;; This is like linum-mode, but uses jit-lock to be (hopefully)
;; more efficient.
-;;; News:
+;;;; News:
+
+;; v1.9:
+;; - Add `nlinu-widen'.
;; v1.8:
;; - Add `nlinum-use-right-margin'.
@@ -43,6 +46,12 @@
;; - New global mode `global-nlinum-mode'.
;; - New config var `nlinum-format-function'.
+;;;; Known bugs:
+;; - When narrowed, there can be a "bogus" line number that appears at the
+;; very end of the buffer.
+;; - After widening, the current line's number may stay stale until the
+;; next command.
+
;;; Code:
(require 'linum) ;For its face
@@ -61,6 +70,10 @@ When non-nil, the current line number is highlighted in
`nlinum-current-line'
face."
:type 'boolean)
+(defcustom nlinum-widen nil
+ "If nil, count lines within the current narrowing only."
+ :type 'boolean)
+
(defface nlinum-current-line
'((t :inherit linum :weight bold))
"Face for displaying current line.")
@@ -95,6 +108,7 @@ Linum mode is a buffer-local minor mode."
(remove-hook 'text-scale-mode-hook #'nlinum--setup-window :local)
(remove-hook 'after-change-functions #'nlinum--after-change :local)
(remove-hook 'post-command-hook #'nlinum--current-line-update :local)
+ (remove-hook 'pre-redisplay-functions #'nlinum--check-narrowing :local)
(kill-local-variable 'nlinum--line-number-cache)
(remove-overlays (point-min) (point-max) 'nlinum t)
;; (kill-local-variable 'nlinum--ol-counter)
@@ -112,6 +126,7 @@ Linum mode is a buffer-local minor mode."
(add-hook 'text-scale-mode-hook #'nlinum--setup-window nil :local)
(add-hook 'window-configuration-change-hook #'nlinum--setup-window nil t)
(add-hook 'after-change-functions #'nlinum--after-change nil :local)
+ (add-hook 'pre-redisplay-functions #'nlinum--check-narrowing nil :local)
(if nlinum-highlight-current-line
(add-hook 'post-command-hook #'nlinum--current-line-update nil :local)
(remove-hook 'post-command-hook #'nlinum--current-line-update :local))
@@ -271,22 +286,40 @@ Linum mode is a buffer-local minor mode."
(defun nlinum--after-change (&rest _args)
(setq nlinum--line-number-cache nil))
+(defvar nlinum--last-point-min nil)
+(make-variable-buffer-local 'nlinum--last-point-min)
+
+(defun nlinum--check-narrowing (&optional _win)
+ ;; FIXME: We should also flush if nlinum-widen was changed.
+ ;; Note: if nlinum-widen is t the flush is still needed when
+ ;; point-min is/was in the middle of a line.
+ (unless (eql nlinum--last-point-min (point-min))
+ (setq nlinum--last-point-min (point-min))
+ (nlinum--flush)))
+
(defun nlinum--line-number-at-pos ()
"Like `line-number-at-pos' but sped up with a cache.
Only works right if point is at BOL."
;; (cl-assert (bolp))
- (let ((pos
- (if (and nlinum--line-number-cache
- (> (- (point) (point-min))
- (abs (- (point) (car nlinum--line-number-cache)))))
- (funcall (if (> (point) (car nlinum--line-number-cache))
- #'+ #'-)
- (cdr nlinum--line-number-cache)
- (count-lines (point) (car nlinum--line-number-cache)))
- (line-number-at-pos))))
- ;;(assert (= pos (line-number-at-pos)))
- (setq nlinum--line-number-cache (cons (point) pos))
- pos))
+ (if nlinum-widen
+ (save-excursion
+ (save-restriction
+ (widen)
+ (forward-line 0) ;In case (point-min) was not at BOL.
+ (let ((nlinum-widen nil))
+ (nlinum--line-number-at-pos))))
+ (let ((pos
+ (if (and nlinum--line-number-cache
+ (> (- (point) (point-min))
+ (abs (- (point) (car nlinum--line-number-cache)))))
+ (funcall (if (> (point) (car nlinum--line-number-cache))
+ #'+ #'-)
+ (cdr nlinum--line-number-cache)
+ (count-lines (point) (car nlinum--line-number-cache)))
+ (line-number-at-pos))))
+ ;;(assert (= pos (line-number-at-pos)))
+ (setq nlinum--line-number-cache (cons (point) pos))
+ pos)))
(defcustom nlinum-format "%d"
"Format of the line numbers.
- [elpa] externals/nlinum d7dbf4a 03/20: * nlinum.el: Add global-nlinum-mode and nlinum-format-function., (continued)
- [elpa] externals/nlinum d7dbf4a 03/20: * nlinum.el: Add global-nlinum-mode and nlinum-format-function., Stefan Monnier, 2020/11/28
- [elpa] externals/nlinum 9a52252 07/20: Fixes: debbugs:17906, Stefan Monnier, 2020/11/28
- [elpa] externals/nlinum 02d3ccf 08/20: * nlinum.el: Use face-width if available. Hook into text-scale-mode, Stefan Monnier, 2020/11/28
- [elpa] externals/nlinum fbe07f1 09/20: * nlinum.el (nlinum--setup-window): Better preserve margin settings, Stefan Monnier, 2020/11/28
- [elpa] externals/nlinum 0ef1df7 10/20: * nlinum.el: Add highlighting of the current line, Stefan Monnier, 2020/11/28
- [elpa] externals/nlinum a4ae169 12/20: nlinum.el: Make it possible to use the right margin, Stefan Monnier, 2020/11/28
- [elpa] externals/nlinum f959610 13/20: * nlinum/nlinum.el: Don't assume nlinum-use-right-margin is fixed, Stefan Monnier, 2020/11/28
- [elpa] externals/nlinum 132ef19 04/20: * nlinum.el (nlinum-format): New custom variable., Stefan Monnier, 2020/11/28
- [elpa] externals/nlinum ba66199 06/20: * packages/nlinum/nlinum.el (nlinum--face-height): New function., Stefan Monnier, 2020/11/28
- [elpa] externals/nlinum 16d30cf 19/20: * packages/nlinum/nlinum.el (nlinum--flush): Widen to really flush all., Stefan Monnier, 2020/11/28
- [elpa] externals/nlinum 99d0fef 16/20: * packages/nlinum/nlinum.el (nlinum-widen): New custom var,
Stefan Monnier <=
- [elpa] externals/nlinum 05d0274 17/20: * packages/nlinum/nlinum.el (nlinum--check-narrowing): Flush the line-number-cache as well., Stefan Monnier, 2020/11/28
- [elpa] externals/nlinum 5cda97a 11/20: * nlinum.el: Bump version to 1.7, Stefan Monnier, 2020/11/28
- [elpa] externals/nlinum 8fd46ee 14/20: Fix nlinum face height function (Bug#26552), Stefan Monnier, 2020/11/28
- [elpa] externals/nlinum 7b18687 15/20: * packages/nlinum/nlinum.el: Bump version to 1.8.1., Stefan Monnier, 2020/11/28
- [elpa] externals/nlinum 60d6af0 20/20: * .gitignore: New file, Stefan Monnier, 2020/11/28
- [elpa] externals/nlinum ac8059b 18/20: * packages/nlinum/nlinum.el (nlinum--check-narrowing): Reset current-line, Stefan Monnier, 2020/11/28