* riece-yank.el (riece-yank-strip-space): New function split from
[riece] / lisp / riece-yank.el
index 8817f5e..c774980 100644 (file)
@@ -57,37 +57,40 @@ before/after the first/last non-blank line."
   (define-key riece-command-mode-map "\C-cy" 'undefined)
   (setq riece-yank-enabled nil))
 
+(defun riece-yank-strip-space (string)
+  (with-temp-buffer
+    (insert string)
+    (untabify (point-min) (point-max))
+    ;; Delete blank lines before the first non-blank line.
+    (goto-char (point-min))
+    (while (looking-at " *$")
+      (delete-region (point) (progn (forward-line) (point))))
+    ;; Delete blank lines after the last non-blank line.
+    (goto-char (point-max))
+    (while (progn (beginning-of-line) (looking-at " *$"))
+      (delete-region (point) (progn (end-of-line 0) (point))))
+    ;; Delete common spaces in front of lines.
+    (setq space-width (point-max))
+    (while (looking-at " +")
+      (setq space-width (min space-width (length (match-string 0))))
+      (forward-line))
+    (goto-char (point-min))
+    (while (not (eobp))
+      (delete-char space-width)
+      (forward-line))
+    (buffer-string)))
+
 (defun riece-command-yank (prefix)
   (interactive "sPrefix: ")
   (when (or (not prefix)
            (string= prefix ""))
     (setq prefix " "))
   (let* ((kill (current-kill 0))
-        msg)
+        msg space-width)
     (unless kill
       (error "Nothing to send in kill-ring"))
     (if riece-yank-strip-space
-       (with-temp-buffer
-         (insert kill)
-         (untabify (point-min) (point-max))
-         ;; Delete blank lines before the first non-blank line.
-         (goto-char (point-min))
-         (while (looking-at " *$")
-           (delete-region (point) (progn (forward-line) (point))))
-         ;; Delete blank lines after the last non-blank line.
-         (goto-char (point-max))
-         (while (progn (beginning-of-line) (looking-at " *$"))
-           (delete-region (point) (progn (end-of-line 0) (point))))
-         ;; Delete common spaces in front of lines.
-         (setq space-width (point-max))
-         (while (looking-at " +")
-           (setq space-width (min space-width (length (match-string 0))))
-           (forward-line))
-         (goto-char (point-min))
-         (while (not (eobp))
-           (delete-char space-width)
-           (forward-line))
-         (setq kill (buffer-string))))
+       (setq kill (riece-yank-strip-space kill)))
     (setq msg (split-string kill "\n"))
     (when (y-or-n-p (format "Send \"%s\"\n? " kill))
       (mapcar