[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/speedrect 0897b24ef8 03/16: fill-text: ensure filled re
From: |
ELPA Syncer |
Subject: |
[elpa] externals/speedrect 0897b24ef8 03/16: fill-text: ensure filled rectangles is non-ragged and doesn't move |
Date: |
Tue, 17 Dec 2024 18:59:38 -0500 (EST) |
branch: externals/speedrect
commit 0897b24ef8ea9ab9d72365e4f2970c9b125ba95d
Author: JD Smith <93749+jdtsmith@users.noreply.github.com>
Commit: JD Smith <93749+jdtsmith@users.noreply.github.com>
fill-text: ensure filled rectangles is non-ragged and doesn't move
---
speedrect.el | 56 ++++++++++++++++++++++++--------------------------------
1 file changed, 24 insertions(+), 32 deletions(-)
diff --git a/speedrect.el b/speedrect.el
index 673090001e..fade279dda 100644
--- a/speedrect.el
+++ b/speedrect.el
@@ -343,52 +343,44 @@ inserted text."
(kill-new (string-join rect "\n"))
(message "Copied rectangle as %d lines" (length rect))))
-(defun speedrect-fill-text (width)
- "Fill text in the selected rectangle to the given WIDTH.
+(defun speedrect-fill-text (start end &optional width)
+ "Fill text in the selected rectangle START..END to the given WIDTH.
WIDTH defaults to the selected rectangle's width, but can be set
with numeric prefix arg. If the marked rectangle is entirely
blank, yank and fill the last killed rectangle instead.
Whitespace is not preserved."
- (interactive
- (list (cond ((null current-prefix-arg)
- (car (rectangle-dimensions (point) (mark))))
- ((consp current-prefix-arg)
- (read-number "Fill width: "))
- (t (prefix-numeric-value current-prefix-arg)))))
+ (interactive "*r")
+ (unless width
+ (setq width (cond ((null current-prefix-arg)
+ (car (rectangle-dimensions start end)))
+ ((consp current-prefix-arg)
+ (read-number "Fill width: "))
+ (t (prefix-numeric-value current-prefix-arg)))))
(when (<= width 0) (user-error "Fill width must be >0"))
(with-undo-amalgamate
- (let* ((height (cdr (rectangle-dimensions (point) (mark))))
- (rect (delete-extract-rectangle (region-beginning) (region-end)))
+ (let* ((height (cdr (rectangle-dimensions start end)))
+ (rect (extract-rectangle start end))
(blankp (cl-every
(lambda (l) (string-match-p (rx bos (* space) eos) l))
rect))
- filled-height)
+ (formatter (apply-partially #'format (format "%%-%ds" width)))
+ lines)
(with-temp-buffer
(if blankp
- (progn
- (yank-rectangle)
- (goto-char (point-min))
- (when (skip-syntax-forward " " (line-end-position))
- (delete-region (point-min) (point))))
- (dolist (line rect) (insert (string-trim line) " \n")))
- (let ((fill-column (point-max))) ; unfill
- (fill-region (point-min) (point-max)))
+ (yank-rectangle)
+ (insert (string-trim (string-join rect " "))))
(let ((fill-column width)) ; fill@width
- (fill-region (point-min) (point-max) nil 'nosqueeze))
- (goto-char (point-min))
- (set-mark (point))
- (goto-char (point-max))
- (beginning-of-line)
- (setq filled-height (line-number-at-pos))
- (rectangle-forward-char width)
- (speedrect-copy-rectangle-dwim))
- (when (< height filled-height)
+ (fill-region (point-min) (point-max)))
+ (setq lines (mapcar formatter (string-lines (buffer-string)))))
+ (when (< height (length lines))
(save-excursion
- (when (> (mark) (point))
- (goto-char (mark)))
+ (when (> end start)
+ (goto-char end))
(end-of-line)
- (open-line (- filled-height height))))
- (speedrect-yank-rectangle-dwim))))
+ (open-line (- (length lines) height))))
+ (delete-rectangle start end t)
+ (when (> (point) (mark)) (exchange-point-and-mark))
+ (insert-rectangle lines))))
;;;; Help
(defun speedrect-transient-map-info ()
- [elpa] externals/speedrect updated (8cda38a010 -> c6e5e1fe7e), ELPA Syncer, 2024/12/17
- [elpa] externals/speedrect a472d721c2 04/16: wrap: alias wrapped functions (with --speedrect_wrap) for keycast, ELPA Syncer, 2024/12/17
- [elpa] externals/speedrect 0150882424 02/16: yank-from-calc: delete existing rectangle first, ELPA Syncer, 2024/12/17
- [elpa] externals/speedrect 9025ae3b49 11/16: Update README.md, ELPA Syncer, 2024/12/17
- [elpa] externals/speedrect 4eb3b6f58e 14/16: Update NEWS.org, ELPA Syncer, 2024/12/17
- [elpa] externals/speedrect 0897b24ef8 03/16: fill-text: ensure filled rectangles is non-ragged and doesn't move,
ELPA Syncer <=
- [elpa] externals/speedrect bc67b6bcfe 15/16: Update README.md, ELPA Syncer, 2024/12/17
- [elpa] externals/speedrect 822a77e867 01/16: README: add demo movie and new screenshot, ELPA Syncer, 2024/12/17
- [elpa] externals/speedrect f52088fd72 05/16: recall-last: turn on rectangle mark mode if not already on, ELPA Syncer, 2024/12/17
- [elpa] externals/speedrect 1735612384 06/16: quit: stash rectangle prior to quitting, ELPA Syncer, 2024/12/17
- [elpa] externals/speedrect 2f46cbec96 07/16: multiple-cursors: recall last rectangle rect when completed, ELPA Syncer, 2024/12/17
- [elpa] externals/speedrect 622df66aab 08/16: NEWS: update for v0.7, ELPA Syncer, 2024/12/17
- [elpa] externals/speedrect 2232149c30 09/16: Bumped version, ELPA Syncer, 2024/12/17
- [elpa] externals/speedrect 606898521a 12/16: Update README.md, ELPA Syncer, 2024/12/17
- [elpa] externals/speedrect 1c595296af 13/16: Update README.md, ELPA Syncer, 2024/12/17
- [elpa] externals/speedrect 3f6057bc32 10/16: Update README.md, ELPA Syncer, 2024/12/17