Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document potential emacs integration support #62

Open
atuleu opened this issue Nov 6, 2023 · 0 comments
Open

Document potential emacs integration support #62

atuleu opened this issue Nov 6, 2023 · 0 comments

Comments

@atuleu
Copy link

atuleu commented Nov 6, 2023

I could easily integrate jupyter_ascending with emacs with the help of an already available package code-cells. Using the, IMHO should be standard, use-package emacs configuration tool, it is only sufficient to add this code snippet to one's emacs econfiguration.

(use-package code-cells
	:mode ("\\.sync.py'" . code-cells-mode)

	:config
	(defun atu/jupyter-ascending-sync ()
		"Runs synchronization with jupyter-ascending. The synchornixation won´t  happen, if the variable atu/jupyter-sync-inhibit is non-nil"
		(interactive)
		(when (string-match-p ".sync.py\\'" (buffer-name))
			(unless atu/jupyter-sync-inhibit
				(call-process "python"
					nil nil nil
					"-m" "jupyter_ascending.requests.sync" "--filename" (buffer-file-name)
					)
				)
			)
		)

	(defun atu/jupyter-ascending-eval (start end)
		"Runs cell via jupyter-ascending or python-shell-send-region"
		(interactive)
		(if (not (string-match-p ".sync.py\\'" (buffer-name)))
			(python-shell-send-region start end)
			(setq-local atu/jupyter-sync-inhibit t)
			(save-buffer)
			(setq-local atu/jupyter-sync-inhibit nil)
			(call-process "python"
				nil nil nil
				"-m" "jupyter_ascending.requests.execute"
				"--filename" (buffer-file-name)
				"--linenumber" (number-to-string (line-number-at-pos))
				)
			)
		)

	(setq code-cells-eval-region-commands
		(mapcar (lambda (pair)
			        (if (eq (car pair) 'python-mode)
				        (cons 'python-mode 'atu/jupyter-ascending-eval)
				        pair))
			code-cells-eval-region-commands))

	:hook
	(python-mode . code-cells-mode-maybe)
	(code-cells-mode . (lambda ()
		                   (add-hook 'after-save-hook 'atu/jupyter-ascending-sync nil 'local)))
	)
                                                      

code-cells, which is compatible with jupytext provides much more functionalities, such as easy cell navigation and reordering, and native support for .ipynb files. I am not an emacs expert, so I would like not to go the path to build and package a mode to integrate this simple code, however, with the green light of this repo maintainers, I would happily contribute to jupyter_ascending's documentation in order to provide emacs community a potential integration of jupyter_ascending with emacs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant