monnier pushed a commit to branch master in repository elpa. commit a2d0a2a867b6634b6bee3e6dccf8a6ce1d45aa85 Author: Stefan Monnier <monn...@iro.umontreal.ca> Date: Tue Apr 29 01:13:19 2014 -0400
* nlinum.el (nlinum-format): New custom variable. (nlinum--region): Change calling convention of nlinum-format-function. (nlinum-format-function): Change default value accordingly; Use nlinum-format; Try to generate less garbage. --- packages/nlinum/nlinum.el | 31 ++++++++++++++++++++++++------- 1 files changed, 24 insertions(+), 7 deletions(-) diff --git a/packages/nlinum/nlinum.el b/packages/nlinum/nlinum.el index 40d6214..750ebc0 100644 --- a/packages/nlinum/nlinum.el +++ b/packages/nlinum/nlinum.el @@ -4,7 +4,7 @@ ;; Author: Stefan Monnier <monn...@iro.umontreal.ca> ;; Keywords: convenience -;; Version: 1.2 +;; Version: 1.3 ;; 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,10 @@ ;;; News: +;; v1.3: +;; - New custom variable `nlinum-format'. +;; - Change in calling convention of `nlinum-format-function'. + ;; v1.2: ;; - New global mode `global-nlinum-mode'. ;; - New config var `nlinum-format-function'. @@ -77,6 +81,8 @@ Linum mode is a buffer-local minor mode." (lambda (buf) (with-current-buffer buf (with-silent-modifications + ;; FIXME: only remove `fontified' on those parts of the + ;; buffer that had an nlinum overlay! (remove-text-properties (point-min) (point-max) '(fontified))))) (current-buffer))) @@ -149,14 +155,24 @@ Linum mode is a buffer-local minor mode." (setq nlinum--line-number-cache (cons (point) pos)) pos)) +(defcustom nlinum-format "%d" + "Format of the line numbers. +Used by the default `nlinum-format-function'." + :type 'string + :group 'linum) + (defvar nlinum-format-function - (lambda (line) - (let* ((fmt (format "%%%dd" nlinum--width)) - (str (propertize (format fmt line) 'face 'linum))) + (lambda (line width) + (let ((str (format nlinum-format line))) + (when (< (length str) width) + ;; Left pad to try and right-align the line-numbers. + (setq str (concat (make-string (- width (length str)) ?\ ) str))) + (put-text-property 0 width 'face 'linum str) 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'.") +Takes 2 arguments LINE and WIDTH, both of them numbers, and should return +a string. WIDTH is the ideal width of the result. If the result is larger, +it may cause the margin to be resized and line numbers to be recomputed.") (defun nlinum--region (start limit) (save-excursion @@ -170,7 +186,8 @@ should be at least equal to `nlinum--width'.") (while (and (not (eobp)) (< (point) limit) (let* ((ol (make-overlay (point) (1+ (point)))) - (str (funcall nlinum-format-function line)) + (str (funcall nlinum-format-function + line nlinum--width)) (width (string-width str))) (when (< nlinum--width width) (setq nlinum--width width)