From 52662756075f31b19959dcd5ff54b0e54aad2500 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Breannd=C3=A1n=20=C3=93=20Nuall=C3=A1in?= Date: Fri, 22 Nov 2024 17:51:17 +0100 Subject: [PATCH 1/2] Check if we're in an org-mode buffer org-in-src-block-p is intended to be called only in an org-mode buffer. In other buffers it leads to an rx error. --- lazy-ruff.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lazy-ruff.el b/lazy-ruff.el index af709d1..9e7f775 100644 --- a/lazy-ruff.el +++ b/lazy-ruff.el @@ -181,7 +181,8 @@ Ensures cursor position is maintained. Requires `ruff` in system's PATH." ((use-region-p) (lazy-ruff-lint-format-region)) ;; Next, check if inside an org-babel code block - ((org-in-src-block-p) + ((and (eq major-mode 'org-mode) + (org-in-src-block-p)) (lazy-ruff-lint-format-block)) ;; Lastly, check if the current buffer is a Python mode buffer ((derived-mode-p 'python-mode 'python-base-mode) From 9d424a4e721ed4b6a5cb291dba967bc37da4554f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Breannd=C3=A1n=20=C3=93=20Nuall=C3=A1in?= Date: Fri, 22 Nov 2024 17:53:39 +0100 Subject: [PATCH 2/2] Replace tabs by spaces --- lazy-ruff.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lazy-ruff.el b/lazy-ruff.el index 9e7f775..8af1947 100644 --- a/lazy-ruff.el +++ b/lazy-ruff.el @@ -116,7 +116,7 @@ Ensures cursor position is maintained. Requires `ruff` in system's PATH." (if (not (string= lang "python")) (message "The source block is not Python") (with-temp-file temp-file (insert code)) - (lazy-ruff-run-commands temp-file (eq lazy-ruff-only-format-block t) (eq lazy-ruff-only-check-block t)) + (lazy-ruff-run-commands temp-file (eq lazy-ruff-only-format-block t) (eq lazy-ruff-only-check-block t)) (setq formatted-code (with-temp-buffer (insert-file-contents temp-file) (buffer-string))) @@ -140,7 +140,7 @@ Ensures cursor position is maintained. Requires `ruff` in system's PATH." (old-window-start (window-start))) ;;; Save point ;; Write buffer to temporary file, format it, and replace buffer contents. (write-region nil nil temp-file) - (lazy-ruff-run-commands temp-file (eq lazy-ruff-only-format-buffer t) (eq lazy-ruff-only-check-buffer t)) + (lazy-ruff-run-commands temp-file (eq lazy-ruff-only-format-buffer t) (eq lazy-ruff-only-check-buffer t)) (erase-buffer) (insert-file-contents temp-file) ;; Clean up temporary file. @@ -160,7 +160,7 @@ Ensures cursor position is maintained. Requires `ruff` in system's PATH." (temp-buffer (generate-new-buffer " *temp-ruff-output*"))) ;; Write selected region to temporary file, format it. (write-region start end temp-file nil 'silent) - (lazy-ruff-run-commands temp-file (eq lazy-ruff-only-format-region t) (eq lazy-ruff-only-check-region t)) + (lazy-ruff-run-commands temp-file (eq lazy-ruff-only-format-region t) (eq lazy-ruff-only-check-region t)) ;; Replace region with formatted content. (with-current-buffer temp-buffer (insert-file-contents temp-file))