astoff / code-cells.el

Emacs utilities for code split into cells, including Jupyter notebooks
GNU General Public License v3.0
190 stars 12 forks source link

Not executing first line of file #27

Closed jabirali closed 1 month ago

jabirali commented 6 months ago

Thanks for creating this package! I enjoy the minimalist Jupyter-like workflow of python-mode when combined with code-cells.el and comint-mime.

While testing it out, I discovered that the following example file results in a somewhat surprising behavior in code-cells.el:

for i in range(10):
    print("Hello world")

# %%
print("Test")

If I place the cursor above the first # %% line and invoke code-cells-eval, then it prints out "Hello world" only once. So it appears that the first line of a Python script is never considered part of a cell. (If I place a shebang or blank line above the for loop, then it runs as expected.)

For comparison, I tried doing the same in Spyder, which prints "Hello world" 10 times as expected. I also tried it in VSCode, which simply doesn't recognize the area above the first # %% as a "cell" and therefore does nothing. I guess both of these behaviors make some sense.

I think this is not a big issue in practice, as I'll usually want a shebang on the first line of the file anyway, but I thought to report this anyway :).

I'm running it on Emacs Mac port (v29.1) with the following config:

(use-package code-cells
  :ensure t
  :after python
  :bind* (:map code-cells-mode-map
               ("M-p" . code-cells-backward-cell)
               ("M-n" . code-cells-forward-cell)
               ("M-RET" . code-cells-eval))
  :hook (python-mode . code-cells-mode)
  :config
  (set-face-attribute 'code-cells-header-line nil :overline nil :underline nil))
astoff commented 6 months ago

Sure, I'll have a look eventually. Thanks :-).

astoff commented 1 month ago

It's fixed now.