Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for org-mode block check #8

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lazy-ruff.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand All @@ -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.
Expand All @@ -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))
Expand All @@ -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)
Expand Down