Make use of rectangle-preview custom variable.

lisp/rect.el (rectangle--string-preview): Only create a preview if
rectangle-preview is non-nil (Bug#23248).
This commit is contained in:
Mark Oteiza 2016-04-16 12:02:49 -04:00
parent aa0d83a727
commit 0f332848cd

View file

@ -408,40 +408,41 @@ With a prefix (or a FILL) argument, also fill too short lines."
:type 'boolean) :type 'boolean)
(defun rectangle--string-preview () (defun rectangle--string-preview ()
(let ((str (minibuffer-contents))) (when rectangle-preview
(when (equal str "") (let ((str (minibuffer-contents)))
(setq str (or (car-safe minibuffer-default) (when (equal str "")
(if (stringp minibuffer-default) minibuffer-default)))) (setq str (or (car-safe minibuffer-default)
(when str (setq str (propertize str 'face 'rectangle-preview))) (if (stringp minibuffer-default) minibuffer-default))))
(with-selected-window rectangle--string-preview-window (when str (setq str (propertize str 'face 'rectangle-preview)))
(unless (or (null rectangle--string-preview-state) (with-selected-window rectangle--string-preview-window
(equal str (car rectangle--string-preview-state))) (unless (or (null rectangle--string-preview-state)
(rectangle--string-flush-preview) (equal str (car rectangle--string-preview-state)))
(apply-on-rectangle (rectangle--string-flush-preview)
(lambda (startcol endcol) (apply-on-rectangle
(let* ((sc (move-to-column startcol)) (lambda (startcol endcol)
(start (if (<= sc startcol) (point) (let* ((sc (move-to-column startcol))
(forward-char -1) (start (if (<= sc startcol) (point)
(setq sc (current-column)) (forward-char -1)
(point))) (setq sc (current-column))
(ec (move-to-column endcol)) (point)))
(end (point)) (ec (move-to-column endcol))
(ol (make-overlay start end))) (end (point))
(push ol (nthcdr 3 rectangle--string-preview-state)) (ol (make-overlay start end)))
;; FIXME: The extra spacing doesn't interact correctly with (push ol (nthcdr 3 rectangle--string-preview-state))
;; the extra spacing added by the rectangular-region-highlight. ;; FIXME: The extra spacing doesn't interact correctly with
(when (< sc startcol) ;; the extra spacing added by the rectangular-region-highlight.
(overlay-put ol 'before-string (rectangle--space-to startcol))) (when (< sc startcol)
(let ((as (when (< endcol ec) (overlay-put ol 'before-string (rectangle--space-to startcol)))
;; (rectangle--space-to ec) (let ((as (when (< endcol ec)
(spaces-string (- ec endcol)) ;; (rectangle--space-to ec)
))) (spaces-string (- ec endcol))
(if (= start end) )))
(overlay-put ol 'after-string (if as (concat str as) str)) (if (= start end)
(overlay-put ol 'display str) (overlay-put ol 'after-string (if as (concat str as) str))
(if as (overlay-put ol 'after-string as)))))) (overlay-put ol 'display str)
(nth 1 rectangle--string-preview-state) (if as (overlay-put ol 'after-string as))))))
(nth 2 rectangle--string-preview-state)))))) (nth 1 rectangle--string-preview-state)
(nth 2 rectangle--string-preview-state)))))))
;; FIXME: Should this be turned into inhibit-region-highlight and made to apply ;; FIXME: Should this be turned into inhibit-region-highlight and made to apply
;; to non-rectangular regions as well? ;; to non-rectangular regions as well?