wavexx / python-x.el

python.el extras for interactive evaluation
https://melpa.org/#/python-x
GNU General Public License v3.0
9 stars 2 forks source link

folding is required #1

Closed Lompik closed 9 years ago

Lompik commented 9 years ago

For some reason , I had to install this file https://raw.githubusercontent.com/jaalto/project-emacs--folding-mode/master/folding.el. I am probably one of the few who uses Python like R. Since you mentionned ESS, would it be possible to simply have the equivalent of the following in python :

ess-eval-region-or-function-or-paragraph = C-M x
ess-eval-region-or-function-or-paragraph-and-step  = C-c C-c 

i.e. use paragraph instead of folding delimiters.

wavexx commented 9 years ago

On 15/07/15 04:26, James Browder wrote:

For some reason , I had to install this file https://raw.githubusercontent.com/jaalto/project-emacs--folding-mode/master/folding.el.

I know, the package was missing from melpa, but now it's there so I can put it in.

I re-use several functions from folding.el

|ess-eval-region-or-function-or-paragraph = C-M x ess-eval-region-or-function-or-paragraph-and-step = C-c C-c |

i.e. use paragraph instead of |folding| delimiters.

I'll add this, as I used it from time to time.

But paragraphs are really too brittle for code. I now use code "sections" for the same purpose:

# --- do something
code code
code code

# --- do something else
code code

C-c C-c in either "section" will execute it. You can nest folds and sections, and it will work as expected.

Install `volatile-highlights' for added awesomeness.

C-c C-j and C-c C-n is also superior to ess-mode currently, as it understands continuations correctly (again, volatile-highlights help in these cases).

I was planning to make a tutorial before publishing python-x, but some colleagues were impatient ;)

I never expected anybody to install it so quickly.

Lompik commented 9 years ago

really too brittle for code.

I guess, but i failed to realize why. What's wrong with something like

(save-excursion
  (forward-paragraph)
  (let ((end (point)))
    (backward-paragraph)
    (python-shell-send-region (point) end)))
wavexx commented 9 years ago

On 15/07/15 14:37, James Browder wrote:

really too brittle for code.

I guess, but i failed to realize why. What's wrong with something like

I'm planning to add a true block/indentation-based method instead, which would play well with indented statements (loops and conditionals).

Not to say that paragraphs won't do, but whenever I use them in ESS I often need to execute two/three of them.

|(save-excursion (forward-paragraph) (let ((end (point))) (backward-paragraph) (python-shell-send-region start end))) |

I will definitely it as a new bindable function.

wavexx commented 9 years ago

The `folding' recipe is now "live" and I added it as a requirement. I'll keep this open until -send-paragraph is done as well.

wavexx commented 9 years ago

I added python-shell-send-paragraph, python-shell-send-paragraph-and-step and python-shell-send-region-or-paragraph.

Although they might come in handy from time to time, code sections are a comparable alternative to "notebook cells" if you ever used python notebooks, and generally work much better. YMMV

Lompik commented 9 years ago

Thanks so much !. volatile-highlights is nice addition.

wavexx commented 9 years ago

On 18/07/15 06:12, James Browder wrote:

Thanks so much !. volatile-highlights is nice addition.

Let me know if there's anything you miss from ESS. I was tempted to make a python backend (ess-python) in the beginning, but figured python-mode didn't miss so much.