]> git.eshelyaron.com Git - emacs.git/commitdiff
Don't kill window buffer in erc--split-line
authorF. Jason Park <jp@neverwas.me>
Wed, 19 Feb 2025 03:20:45 +0000 (19:20 -0800)
committerEshel Yaron <me@eshelyaron.com>
Sun, 23 Feb 2025 08:09:51 +0000 (09:09 +0100)
* lisp/erc/erc-backend.el (erc--split-line): Restore original window
buffer before killing temp buffer.  (Bug#76404)

(cherry picked from commit 1270e6aec5ff4b6f420d132a2249bb94095a3f11)

lisp/erc/erc-backend.el

index 5823cfc5bae19a49ff81dddcbf8fa28c89d503d4..12f7a081bb7912cd0c168ad1757a45b6f414056a 100644 (file)
@@ -588,34 +588,35 @@ escape hatch for inhibiting their transmission.")
     (when (consp coding)
       (setq coding (car coding)))
     (setq coding (coding-system-change-eol-conversion coding 'unix))
-    (unwind-protect
-        (with-temp-buffer
-          (set-window-buffer (selected-window) (current-buffer))
-          (insert longline)
-          (goto-char (point-min))
-          (while (not (eobp))
-            (let ((upper (filepos-to-bufferpos erc-split-line-length
-                                               'exact coding)))
-              (goto-char (or upper (point-max)))
-              (unless (eobp)
-                (skip-chars-backward "^ \t"))
-              (when (bobp)
-                (when erc--reject-unbreakable-lines
-                  (user-error
-                   (substitute-command-keys
-                    (concat "Unbreakable line encountered "
-                            "(Recover input with \\[erc-previous-command])"))))
-                (goto-char upper))
-              (when-let ((cmp (find-composition (point) (1+ (point)))))
-                (if (= (car cmp) (point-min))
-                    (goto-char (nth 1 cmp))
-                  (goto-char (car cmp)))))
-            (when (= (point-min) (point))
-              (goto-char (point-max)))
-            (push (buffer-substring-no-properties (point-min) (point)) out)
-            (delete-region (point-min) (point)))
-          (or (nreverse out) (list "")))
-      (set-window-buffer (selected-window) original-window-buf))))
+    (with-temp-buffer
+      (unwind-protect
+          (progn
+            (set-window-buffer (selected-window) (current-buffer))
+            (insert longline)
+            (goto-char (point-min))
+            (while (not (eobp))
+              (let ((upper (filepos-to-bufferpos erc-split-line-length
+                                                 'exact coding)))
+                (goto-char (or upper (point-max)))
+                (unless (eobp)
+                  (skip-chars-backward "^ \t"))
+                (when (bobp)
+                  (when erc--reject-unbreakable-lines
+                    (user-error
+                     (substitute-command-keys
+                      (concat "Unbreakable line encountered (Recover input"
+                              " with \\[erc-previous-command])"))))
+                  (goto-char upper))
+                (when-let* ((cmp (find-composition (point) (1+ (point)))))
+                  (if (= (car cmp) (point-min))
+                      (goto-char (nth 1 cmp))
+                    (goto-char (car cmp)))))
+              (when (= (point-min) (point))
+                (goto-char (point-max)))
+              (push (buffer-substring-no-properties (point-min) (point)) out)
+              (delete-region (point-min) (point)))
+            (or (nreverse out) (list "")))
+        (set-window-buffer (selected-window) original-window-buf)))))
 
 ;; From Circe
 (defun erc-split-line (longline)