Skip to content
This repository was archived by the owner on Mar 10, 2024. It is now read-only.

implemented python-shell-send-cell + new bindings#82

Closed
twmr wants to merge 4 commits into
fgallina:masterfrom
twmr:python-cell
Closed

implemented python-shell-send-cell + new bindings#82
twmr wants to merge 4 commits into
fgallina:masterfrom
twmr:python-cell

Conversation

@twmr

@twmr twmr commented Apr 7, 2012

Copy link
Copy Markdown

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.

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>
@fgallina

Copy link
Copy Markdown
Owner

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.

@fgallina

Copy link
Copy Markdown
Owner

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.

@twmr

twmr commented Apr 11, 2012

Copy link
Copy Markdown
Author

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 ;) ).

@fgallina

Copy link
Copy Markdown
Owner

Reopening until I get enough time to decide what's the best way to go.

@fgallina fgallina reopened this Apr 11, 2012
@tkf

tkf commented Apr 14, 2012

Copy link
Copy Markdown
Contributor

FYI, IPython seems to have different format of the cell.
http://ipython.org/ipython-doc/stable/interactive/htmlnotebook.html#the-notebook-format

@twmr

twmr commented Apr 14, 2012

Copy link
Copy Markdown
Author

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)>

@twmr

twmr commented Apr 15, 2012

Copy link
Copy Markdown
Author

This seems to work

  (when (save-excursion
          (save-match-data
            (goto-char (point-min))
            (search-forward "# <nbformat>" nil t)))
    (set (make-local-variable 'python-cell-delimiter-regex) "# <\\(codecell\\|markdowncell\\)>")

@twmr

twmr commented Apr 18, 2012

Copy link
Copy Markdown
Author

font-lock support is now done.

@fgallina

Copy link
Copy Markdown
Owner

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:

  1. I like your implementation as is and I'll want to include it: In this case we'll need you to sign FSF papers as python.el is confirmed to be included on Emacs' trunk (I got commit access last weekend).
  2. I prefer to implement in a different way: In this case none of the paper stuff is needed (you'll get your thanks in the commit message that's a guarantee :)

I'll keep you posted as soon as I make a decision.

Thanks!

@fgallina

Copy link
Copy Markdown
Owner

@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.

@fgallina fgallina closed this Jan 30, 2013
@twmr

twmr commented Jan 30, 2013

Copy link
Copy Markdown
Author

I'm fine with that. I will let you know when the plugin is ready.

Regards
thisch

@twmr

twmr commented Aug 3, 2013

Copy link
Copy Markdown
Author

@fgallina, what is the proper way to add keywords to python-font-lock-keywords in a minor mode ?

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))))

@twmr

twmr commented Aug 5, 2013

Copy link
Copy Markdown
Author

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)

@fgallina

Copy link
Copy Markdown
Owner

@Thisch I got to this really late, although I'm glad you found your way out. Cool stuff.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants