[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] scratch/add-vdiff f915562 047/258: Use customizable function to f
From: |
Justin Burkett |
Subject: |
[elpa] scratch/add-vdiff f915562 047/258: Use customizable function to format closed fold strings |
Date: |
Wed, 17 May 2017 08:13:20 -0400 (EDT) |
branch: scratch/add-vdiff
commit f91556217c68b572b7fdaab46f35cfb0dd9e8909
Author: justbur <address@hidden>
Commit: justbur <address@hidden>
Use customizable function to format closed fold strings
---
README.org | 7 ++++---
vdiff.el | 52 +++++++++++++++++++++++++++++++---------------------
2 files changed, 35 insertions(+), 24 deletions(-)
diff --git a/README.org b/README.org
index 6b67c68..33bc620 100644
--- a/README.org
+++ b/README.org
@@ -90,8 +90,9 @@ The current customization options and there defaults are
;; Unchanged lines to leave unfolded around a fold
(setq vdiff-fold-padding 2)
- ;; Format string for text on closed folds. First element is the code on the
- ;; first line being covered. The second is the number of lines hidden.
- (setq vdiff-fold-format-string "+ %s --- %s lines ")
+ ;; Function that returns the string printed for a closed fold. The arguments
+ ;; passed are the number of lines folded, the text on the first line, and the
+ ;; width of the buffer.
+ (setq vdiff-fold-string-function 'vdiff-fold-string-default)
#+END_SRC
diff --git a/vdiff.el b/vdiff.el
index 4ccde7b..ba23f82 100644
--- a/vdiff.el
+++ b/vdiff.el
@@ -138,12 +138,12 @@ the buffer here, because those are handled differently."
:group 'vdiff
:type 'integer)
-(defcustom vdiff-fold-format-string "+ %s --- %s lines "
- "Format string for text on closed folds. First element is the
-code on the first line being covered. The second is the number of
-lines hidden."
+(defcustom vdiff-fold-string-function 'vdiff-fold-string-default
+ "Function that returns the string printed for a closed
+fold. The arguments passed are the number of lines folded, the
+text on the first line, and the width of the buffer."
:group 'vdiff
- :type 'string)
+ :type 'function)
(defface vdiff-addition-face
'((t :inherit diff-added))
@@ -367,31 +367,41 @@ lines hidden."
(overlay-put ovr 'after-string
(vdiff--make-subtraction-string
subtraction-padding)))))))
+(defun vdiff-fold-string-default (lines first-line width)
+ "Produces default format line for closed folds. See
+`vdiff-fold-string-function'."
+ (let ((first-line (string-trim-left first-line))
+ (start (format "+--%d lines: " lines))
+ (width (1- width)))
+ (if (> (+ 1 (length first-line) (length start)) width)
+ (concat start
+ (substring-no-properties
+ first-line 0 (- width (length start)))
+ "\n")
+ (concat start
+ first-line
+ (make-string (- width (length start) (length first-line)) ?-)
+ "\n"))))
+
(defun vdiff--make-fold (buffer range)
(with-current-buffer buffer
(let* ((beg-line (car range))
(end-line (cdr range))
(fold-start (vdiff--pos-at-line-beginning beg-line))
- (summ-text (buffer-substring-no-properties
- fold-start
- (min (save-excursion
- (goto-char fold-start)
- (line-end-position))
- (+ fold-start
- (- (vdiff--min-window-width) 20)))))
+ (first-line-text
+ (buffer-substring-no-properties
+ fold-start (save-excursion
+ (goto-char fold-start)
+ (line-end-position))))
(fold-end
(vdiff--pos-at-line-beginning end-line))
(ovr (make-overlay fold-start fold-end))
- (text (format vdiff-fold-format-string
- summ-text
- (- end-line beg-line)))
(text
- (propertize
- (concat text
- (make-string (- (vdiff--min-window-width)
- (length text) 1) ?-)
- "\n")
- 'face 'vdiff-closed-fold-face)))
+ (propertize (funcall vdiff-fold-string-function
+ (- end-line beg-line)
+ first-line-text
+ (vdiff--min-window-width))
+ 'face 'vdiff-closed-fold-face)))
(overlay-put ovr 'face 'vdiff-open-fold-face)
(overlay-put ovr 'vdiff-fold-text text)
(overlay-put ovr 'vdiff-type 'fold)
- [elpa] scratch/add-vdiff 16eb802 107/258: Update README, (continued)
- [elpa] scratch/add-vdiff 16eb802 107/258: Update README, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 0dc9fde 114/258: Try not to move point on change transmission, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff cc24574 115/258: Fix scroll update for other subtraction styles, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff c912ebc 120/258: Don't use window-size-change-hook, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 7561f87 100/258: Split line maps, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 32756c3 131/258: A little better than a WIP now, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 5a6623f 012/258: Update README, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff e178a90 017/258: One more fold fix, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff e6e87f3 019/258: Add screenshot, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff d77dd83 032/258: Take care to only remove vdiff overlays on refresh, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff f915562 047/258: Use customizable function to format closed fold strings,
Justin Burkett <=
- [elpa] scratch/add-vdiff d8a4efb 023/258: Remove unused variable, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 23b3360 030/258: Fix compiler warnings, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff eeede0b 045/258: Reset open-fold-face, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 96258b1 046/258: Don't set open fold face, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff dc7a5e2 049/258: Add a comment on line-map structure, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff e9d0cc7 050/258: Define new bitmaps for open and close of folds, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 1c8dd1e 138/258: Default to nil for auto refinement, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 3d0678f 142/258: Make bitmaps nicer, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 53ee239 149/258: Fix bug in receive changes for 3way, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff e171b7c 140/258: Depend on hydra, Justin Burkett, 2017/05/17