Skip to content

Commit

Permalink
Merge pull request #8 from bon/main
Browse files Browse the repository at this point in the history
Fix for org-mode block check
  • Loading branch information
christophermadsen authored Nov 27, 2024
2 parents f7f6975 + 9d424a4 commit 88b9177
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lazy-ruff.el
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Ensures cursor position is maintained. Requires `ruff` in system's PATH."
(if (not (member lang lazy-ruff-org-src-languages))
(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)))
Expand All @@ -142,7 +142,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.
Expand All @@ -162,7 +162,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))
Expand All @@ -183,7 +183,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)
Expand Down

0 comments on commit 88b9177

Please sign in to comment.