[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/nlinum f959610 13/20: * nlinum/nlinum.el: Don't assume
From: |
Stefan Monnier |
Subject: |
[elpa] externals/nlinum f959610 13/20: * nlinum/nlinum.el: Don't assume nlinum-use-right-margin is fixed |
Date: |
Sat, 28 Nov 2020 18:42:24 -0500 (EST) |
branch: externals/nlinum
commit f9596102b2e3f76b1442c7c3f2290a66843bca1a
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>
* nlinum/nlinum.el: Don't assume nlinum-use-right-margin is fixed
(nlinum--using-right-margin): New var.
(nlinum-mode): Copy nlinum-use-right-margin to nlinum--using-right-margin.
(nlinum--setup-window): Use the new var.
---
nlinum.el | 36 +++++++++++++++++++++++++-----------
1 file changed, 25 insertions(+), 11 deletions(-)
diff --git a/nlinum.el b/nlinum.el
index aef2d81..d0ab821 100644
--- a/nlinum.el
+++ b/nlinum.el
@@ -4,7 +4,7 @@
;; Author: Stefan Monnier <monnier@iro.umontreal.ca>
;; Keywords: convenience
-;; Version: 1.7
+;; Version: 1.8
;; 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
@@ -26,6 +26,9 @@
;;; News:
+;; v1.8:
+;; - Add `nlinum-use-right-margin'.
+
;; v1.7:
;; - Add ability to highlight current line number.
;; - New custom variable `nlinum-highlight-current-line' and
@@ -70,11 +73,14 @@ face."
(make-variable-buffer-local 'nlinum--current-line)
(defcustom nlinum-use-right-margin nil
- "Use the left (nil) or right (t) margin."
+ "If non-nil, put line numbers in the right margin instead of the left one."
:type 'boolean)
;; (defvar nlinum--desc "")
+(defvar nlinum--using-right-margin nil)
+(make-variable-buffer-local 'nlinum--using-right-margin)
+
;;;###autoload
(define-minor-mode nlinum-mode
"Toggle display of line numbers in the left margin (Linum mode).
@@ -93,6 +99,12 @@ Linum mode is a buffer-local minor mode."
(remove-overlays (point-min) (point-max) 'nlinum t)
;; (kill-local-variable 'nlinum--ol-counter)
(kill-local-variable 'nlinum--width)
+ (when (and (local-variable-p 'nlinum--using-right-margin)
+ (not (eq nlinum--using-right-margin nlinum-use-right-margin)))
+ ;; Remove outdated margins as well as margin annotations.
+ (let ((nlinum-mode nil)) (nlinum--flush))
+ (kill-local-variable 'nlinum--using-right-margin))
+ (setq nlinum--using-right-margin nlinum-use-right-margin)
(when nlinum-mode
;; FIXME: Another approach would be to make the mode permanent-local,
;; which might indeed be preferable.
@@ -132,7 +144,8 @@ Linum mode is a buffer-local minor mode."
(frame-char-height)))))
nlinum--width))
(cur-margins (window-margins))
- (cur-margin (if nlinum-use-right-margin (cdr cur-margins) (car
cur-margins)))
+ (cur-margin (if nlinum--using-right-margin
+ (cdr cur-margins) (car cur-margins)))
;; (EXT . OURS) keeps track of the size of the margin, where EXT is
the
;; size chosen by external code and OURS is the size we last set.
;; OURS is used to detect when someone else modifies the margin.
@@ -146,11 +159,11 @@ Linum mode is a buffer-local minor mode."
(and (car margin-settings) width
(setq width (max width (car margin-settings))))
(setcdr margin-settings width)
- ;; even more changes!
- (if nlinum-use-right-margin
- (set-window-margins nil (car cur-margins) (if nlinum-mode width (car
margin-settings)))
- (set-window-margins nil (if nlinum-mode width (car margin-settings))
- (cdr cur-margins)))))
+ (apply #'set-window-margins nil
+ (let ((new-margin (if nlinum-mode width (car margin-settings))))
+ (if nlinum--using-right-margin
+ (list (car cur-margins) new-margin)
+ (list new-margin (cdr cur-margins)))))))
(defun nlinum--setup-windows ()
(dolist (win (get-buffer-window-list nil nil t))
@@ -314,7 +327,9 @@ it may cause the margin to be resized and line numbers to
be recomputed.")
(let* ((ol (make-overlay (point) (1+ (point))))
(str (funcall nlinum-format-function
line nlinum--width))
- (width (string-width str)))
+ (width (string-width str))
+ (margin (if nlinum--using-right-margin
+ 'right-margin 'left-margin)))
(when (< nlinum--width width)
(setq nlinum--width width)
(nlinum--flush))
@@ -322,8 +337,7 @@ it may cause the margin to be resized and line numbers to
be recomputed.")
(overlay-put ol 'evaporate t)
(overlay-put ol 'before-string
(propertize " " 'display
- `((margin ,(if
nlinum-use-right-margin 'right-margin 'left-margin)) ,str)))
- ;;`((margin right-margin) ,str)))
+ `((margin ,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
- [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, 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 <=
- [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
- [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