]> git.eshelyaron.com Git - emacs.git/commitdiff
sh-script.el: Fix fixing Flymake diagnostics from other buffer
authorEshel Yaron <me@eshelyaron.com>
Fri, 7 Mar 2025 14:53:30 +0000 (15:53 +0100)
committerEshel Yaron <me@eshelyaron.com>
Fri, 7 Mar 2025 14:53:30 +0000 (15:53 +0100)
* lisp/progmodes/sh-script.el (sh-shellcheck-fix):

lisp/progmodes/sh-script.el

index 7a745c380b6314fb7081265fe7e7edee869717e9..ab2e30dcee2209a7c59ce40a40d204372a610081 100644 (file)
@@ -3241,20 +3241,21 @@ shell command and conveniently use this command."
 
 (defvar-local sh--shellcheck-process nil)
 
-(defun sh-shellcheck-fix (data)
+(defun sh-shellcheck-fix (source data)
   "Format DATA, a cons cell (TITLE . FIX), as a Flymake fix suggestion."
-  `((,(car data)
-     ((,(current-buffer)
-       ,@(mapcar
-          (lambda (rep)
-            (let-alist rep
-              (without-restriction
-                (save-excursion
-                  (goto-char (point-min))
-                  (list (1- (+ (pos-bol .line) .column))
-                        (1- (+ (pos-bol .endLine) .endColumn))
-                        .replacement)))))
-          (alist-get 'replacements (cdr data))))))))
+  (with-current-buffer source
+    `((,(car data)
+       ((,(current-buffer)
+         ,@(mapcar
+            (lambda (rep)
+              (let-alist rep
+                (without-restriction
+                  (save-excursion
+                    (goto-char (point-min))
+                    (list (1- (+ (pos-bol .line) .column))
+                          (1- (+ (pos-bol .endLine) .endColumn))
+                          .replacement)))))
+            (alist-get 'replacements (cdr data)))))))))
 
 (defun sh-shellcheck-flymake (report-fn &rest _args)
   "Flymake backend using the shellcheck program.
@@ -3299,7 +3300,8 @@ member of `flymake-diagnostic-functions'."
                                 (_ :note))
                               (format "SC%s: %s" .code .message)
                               (cons .message .fix) nil
-                              (when (consp .fix) #'sh-shellcheck-fix)))))
+                              (when (consp .fix)
+                                (apply-partially #'sh-shellcheck-fix source))))))
                         (funcall report-fn))))
                 (kill-buffer (process-buffer proc)))))))
     (unless dialect