py-isort.el icon indicating copy to clipboard operation
py-isort.el copied to clipboard

Can't not sort region that in a non-file buffer

Open Yevgnen opened this issue 8 years ago • 1 comments

When the buffer is not saved, or in org-src-mode which is not related to a file, py-isort alerts an error.

Yevgnen avatar Nov 16 '16 09:11 Yevgnen

I wrote a function to do that after seeing this package and your comment. The function does not rely on any Emacs package and is quite short:

(defun isort-buffer ()
  "Uses the Python program isort on current buffer."
  (interactive)
  (setq tmp-file (make-temp-file "isort-test"))
  (mark-whole-buffer)
  (write-region (point-min) (point-max) tmp-file)
  (shell-command (concat "isort " tmp-file))
  (erase-buffer)
  (insert-file-contents tmp-file))

You can just bind it to your favorite shortcut or call it with M-x.

guilherme-salome avatar Aug 22 '19 20:08 guilherme-salome