implemented python-shell-send-cell + new bindings#82
Conversation
this commit implements the four functions python-shell-send-cell python-forward-cell python-backward-cell python-beginning-of-cell plus appropriate bindings Signed-off-by: Thomas Hisch <thomas@opentech.at>
|
Hi thisch, First of all, thanks for your interest in this mode. I appreciate the effort you put on this patch but I don't feel this is something I'd like to implement in the core of python.el. The main reason is that the definition of cell is really arbitrary, I really feel this kind of stuff is something that belongs to your .emacs.d than to the mode itself. |
|
I now seem to understand the idea of cell better, I'll check a little bit more on that and see if it's worth to have it implemented in the core. |
|
Thx for your answer. The usage of cells/blocks (cell-movement and cell-execution) in MATLAB is quite common for me but unfortunately cell-support is missing in all emacs python modes AFAIK. I was inspired by the matlab-emacs mode/project that implements cell-support for MATLAB files in emacs to implement this feature in python.el (btw this is my first non-trivial pull-request in elisp ;) ). |
|
Reopening until I get enough time to decide what's the best way to go. |
|
FYI, IPython seems to have different format of the cell. |
|
What we could do is the following: check if the file has the '# x' line to verify if its an IPython file. If so make the cell-delimiter regexp buffer local and set it to # <(codecell|markdown)> |
|
This seems to work |
plus: regex -> regexp
|
font-lock support is now done. |
|
Hi thisch, I'm still yet not convinced of adding this cell stuff, I'm going to come back at this at some point, but anyways notice that I don't want to add font-locking to non-standard stuff. I want to prevent having an angry fruit salad in the buffer so I'm not following pyhon-mode.el's policy of having a special faces for non standard Emacs stuff. I know it might sound as a bad thing but I'm convinced that restricting the scope of stuff we add to the mode will benefit it in several ways (and remaining clean and maintainable are two of them). If people want to highlight specific stuff other than Emacs' defaults that's really fine (I sometimes do it myself) but I feel this kind of stuff really belongs to users' .emacs rather than the core python.el. With all that said I appreciate your effort and time on opening a ticket and explaining the concept of cells, I didn't went (yet) through your implementation but in the case I decide we are going for it two things might happen:
I'll keep you posted as soon as I make a decision. Thanks! |
|
@Thisch, if you are still interested into getting this functionality in some place, I'd recommend you to write is as a python.el plugin. You could call it python-cells and follow the https://github.com/fgallina/python-django.el naming conventions. I'm closing this one. |
|
I'm fine with that. I will let you know when the plugin is ready. Regards |
|
@fgallina, what is the proper way to add keywords to Neither of the following two snippets (which are part of my python-cell-mode minor mode) lead to the same result as the code in this PR. (eval-after-load 'python
(progn
(make-variable-buffer-local 'python-font-lock-keywords)
(setq python-font-lock-keywords
(append python-font-lock-keywords
`(,(rx line-start (* space)
(group (and "#" (or (and "#" (* (not (any "\n"))))
(and " <" (or "codecell" "markdowncell") ">"))
line-end)))
(1 python-cellbreak-face append))))))(eval-after-load 'python
(font-lock-add-keywords
'python
`(,(rx line-start (* space)
(group (and "#" (or (and "#" (* (not (any "\n"))))
(and " <" (or "codecell" "markdowncell") ">"))
line-end)))
(1 python-cellbreak-face append)))) |
|
After a careful study of the emacs font-lock functions and a bit of trial and error I managed to add font-lock support to my minor-mode thisch/python-cell.el (eval-after-load 'python
'(font-lock-add-keywords 'python-mode `((,python-cell-cellbreak-regex
1 'python-cell-cellbreak-face prepend))))
(defcustom python-cell-cellbreak-regexp
(rx line-start (* space)
(group (and "#" (or (and "#" (* (not (any "\n"))))
(and " <" (or "codecell" "markdowncell") ">"))
line-end)))
"Regexp used for detecting the cell boundaries of code cells/blocks."
:type 'string
:group 'python-cell
:safe 'stringp) |
|
@Thisch I got to this really late, although I'm glad you found your way out. Cool stuff. |
this pull request implements the five functions
python-shell-send-cell
python-forward-cell
python-backward-cell
python-beginning-of-cell
python-end-of-cell
plus appropriate bindings
and creates a new face python-cellbrake-face used for fontification of the cellbreak lines.