[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/nlinum d7dbf4a 03/20: * nlinum.el: Add global-nlinum-mo
From: |
Stefan Monnier |
Subject: |
[elpa] externals/nlinum d7dbf4a 03/20: * nlinum.el: Add global-nlinum-mode and nlinum-format-function. |
Date: |
Sat, 28 Nov 2020 18:42:22 -0500 (EST) |
branch: externals/nlinum
commit d7dbf4a7dfa30eee8ffc0fc396d8a4ae8198ab01
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>
* nlinum.el: Add global-nlinum-mode and nlinum-format-function.
---
nlinum.el | 39 +++++++++++++++++++++++++++------------
1 file changed, 27 insertions(+), 12 deletions(-)
diff --git a/nlinum.el b/nlinum.el
index 1c9e4e8..40d6214 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 Free Software Foundation, Inc.
+;; Copyright (C) 2012, 2014 Free Software Foundation, Inc.
;; Author: Stefan Monnier <monnier@iro.umontreal.ca>
;; Keywords: convenience
-;; Version: 1.1
+;; Version: 1.2
;; 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,6 +24,12 @@
;; This is like linum-mode, but uses jit-lock to be (hopefully)
;; more efficient.
+;;; News:
+
+;; v1.2:
+;; - New global mode `global-nlinum-mode'.
+;; - New config var `nlinum-format-function'.
+
;;; Code:
(require 'linum) ;For its face.
@@ -63,7 +69,7 @@ Linum mode is a buffer-local minor mode."
(dolist (win (get-buffer-window-list nil nil t))
(with-selected-window win (nlinum--setup-window))))
-(defun nlinum--new-width ()
+(defun nlinum--flush ()
(nlinum--setup-windows)
;; (kill-local-variable 'nlinum--ol-counter)
(remove-overlays (point-min) (point-max) 'nlinum t)
@@ -143,6 +149,15 @@ Linum mode is a buffer-local minor mode."
(setq nlinum--line-number-cache (cons (point) pos))
pos))
+(defvar nlinum-format-function
+ (lambda (line)
+ (let* ((fmt (format "%%%dd" nlinum--width))
+ (str (propertize (format fmt line) 'face 'linum)))
+ str))
+ "Function to build the string representing the line number.
+Takes one argument (the line number) and returns a string whose width
+should be at least equal to `nlinum--width'.")
+
(defun nlinum--region (start limit)
(save-excursion
;; Text may contain those nasty intangible properties, but
@@ -151,23 +166,20 @@ Linum mode is a buffer-local minor mode."
(goto-char start)
(unless (bolp) (forward-line 1))
(remove-overlays (point) limit 'nlinum t)
- (let ((line (nlinum--line-number-at-pos))
- (fmt (format "%%%dd" nlinum--width)))
+ (let ((line (nlinum--line-number-at-pos)))
(while
(and (not (eobp)) (< (point) limit)
(let* ((ol (make-overlay (point) (1+ (point))))
- (str (format fmt line))
+ (str (funcall nlinum-format-function line))
(width (string-width str)))
(when (< nlinum--width width)
(setq nlinum--width width)
- (nlinum--new-width))
+ (nlinum--flush))
(overlay-put ol 'nlinum t)
(overlay-put ol 'evaporate t)
(overlay-put ol 'before-string
(propertize " " 'display
- `((margin left-margin)
- ,(propertize str
- 'face 'linum))))
+ `((margin left-margin) ,str)))
;; (setq nlinum--ol-counter (1- nlinum--ol-counter))
;; (when (= nlinum--ol-counter 0)
;; (run-with-idle-timer 0.5 nil #'nlinum--flush-overlays
@@ -176,7 +188,10 @@ Linum mode is a buffer-local minor mode."
(zerop (forward-line 1))))))))
;; (setq nlinum--desc (format "-%d" (nlinum--ol-count)))
nil)
-
-
+
+;;;###autoload
+(define-globalized-minor-mode global-nlinum-mode nlinum-mode
+ (lambda () (unless (minibufferp) (nlinum-mode))))
+
(provide 'nlinum)
;;; nlinum.el ends here
- [elpa] branch externals/nlinum created (now 60d6af0), Stefan Monnier, 2020/11/28
- [elpa] externals/nlinum 37cc4b2 01/20: Add nlinum.el, Stefan Monnier, 2020/11/28
- [elpa] externals/nlinum c64e489 05/20: * packages/nlinum/nlinum.el (nlinum-mode): Don't leave overlays around when, Stefan Monnier, 2020/11/28
- [elpa] externals/nlinum 5081418 02/20: * nlinum.el: Speed up by caching last line-number., Stefan Monnier, 2020/11/28
- [elpa] externals/nlinum d7dbf4a 03/20: * nlinum.el: Add global-nlinum-mode and nlinum-format-function.,
Stefan Monnier <=
- [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, 2020/11/28