pyplotter icon indicating copy to clipboard operation
pyplotter copied to clipboard

Remove elpy requirement

Open thesimonho opened this issue 8 years ago • 4 comments

thanks for this project. I've been looking for something like for a long long time!

just curious about the elpy requirement. I typically dont use elpy as I find it contains more than I actually need. Is there elpy specific functionality in pyplotter, or could it be generalized to people that use, say, anaconda mode?

thesimonho avatar May 29 '17 07:05 thesimonho

It won't be too much work to remove the elpy requirement and make it rely only on python-mode. Then anyone can use it. I should have done that from the start.

You are welcome to submit a pull request. Otherwise it may be a few weeks before I get around to this.

christopherjenness avatar May 29 '17 08:05 christopherjenness

It's basically just using the elpy functions to send selections to the REPL. Which is basically just a call to a function in python-mode.

christopherjenness avatar May 29 '17 18:05 christopherjenness

I've tried playing around with it but I'm not that familiar with elisp, so I think any changes I'm making are actually breaking it more than fixing anything. Also, its difficult for me to test the intended result without installing elpy, which never seems to succeed when I try installing it

thesimonho avatar May 29 '17 23:05 thesimonho

Here are the basics:

  • elpy-shell-get-or-create-process can essentially be removed (since it just checks for an inferior python process). If you want to keep that functionality, check for a process and then run-pythonto start a process if needed.
  • elpy-shell--region-without-indentation is a useful function that removes extra indentation. So you can, for example, run bits of code within a function, even though they are indented. I guess this could also be removed. Or, if you want to keep that functionality, you can just grab the whole function from elpy, since it is self-contained (see below)
  • elpy-shell-display-buffer just displays the REPL. This is also just a nice feature that can be removed if you always plan on having the REPL up, but it's nice in case things get all messed up. This can be rewritten within pyplotter pretty easily if you just set the REPL buffer as a variable and then display it when you want.
  • I was wrong above...I'm not using eply to send code to the REPL. I'm actually using python-shell-send-buffer. So really, elpy is just for a few optional features.
(defun elpy-shell--region-without-indentation (beg end)
  "Return the current region as a string, but without indentation."
  (if (= beg end)
      ""
    (let ((region (buffer-substring beg end))
          (indent-level nil)
          (indent-tabs-mode nil))
      (with-temp-buffer
        (insert region)
        (goto-char (point-min))
        (while (< (point) (point-max))
          (cond
           ((and (not indent-level)
                 (not (looking-at "[ \t]*$")))
            (setq indent-level (current-indentation)))
           ((and indent-level
                 (not (looking-at "[ \t]*$"))
                 (< (current-indentation)
                    indent-level))
            (error "Can't adjust indentation, consecutive lines indented less than starting line")))
          (forward-line))
        (indent-rigidly (point-min)
                        (point-max)
                        (- indent-level))
        ;; 'indent-rigidly' introduces tabs despite the fact that 'indent-tabs-mode' is nil
        ;; 'untabify' fix that
	(untabify (point-min) (point-max))
        (buffer-string))))

christopherjenness avatar May 30 '17 09:05 christopherjenness