[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/code-cells 83cb4d0095 24/36: Add code-cells-eval
From: |
ELPA Syncer |
Subject: |
[elpa] externals/code-cells 83cb4d0095 24/36: Add code-cells-eval |
Date: |
Mon, 28 Feb 2022 15:57:43 -0500 (EST) |
branch: externals/code-cells
commit 83cb4d0095eb3fa513c964e1b90e3343fe2d65dc
Author: Augusto Stoffel <arstoffel@gmail.com>
Commit: Augusto Stoffel <arstoffel@gmail.com>
Add code-cells-eval
---
code-cells.el | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
diff --git a/code-cells.el b/code-cells.el
index f6961edf5b..19dc2faccf 100644
--- a/code-cells.el
+++ b/code-cells.el
@@ -179,6 +179,49 @@ COMMAND."
(looking-at (code-cells-boundary-regexp)))
d))))
+;;; Code evaluation
+
+(defcustom code-cells-eval-region-commands
+ '((jupyter-repl-interaction-mode . jupyter-eval-region)
+ (python-mode . python-shell-send-region)
+ (emacs-lisp-mode . eval-region)
+ (lisp-interaction-mode . eval-region))
+ "Alist of commands to evaluate a region.
+The keys are major or minor modes and the values are functions
+taking region bounds as argument."
+ :type '(alist :key-type symbol :value-type symbol))
+
+;;;###autoload
+(defun code-cells-eval (start end)
+ "Evaluate code according to current modes.
+The first suitable function from `code-cells-eval-region-commands'
+is used to do the job.
+
+Interactively, evaluate the region, if active, otherwise the
+current code cell. With a numeric prefix, evaluate that many
+code cells.
+
+Called from Lisp, evaluate region between START and END."
+ (interactive (code-cells--bounds (prefix-numeric-value current-prefix-arg)
t))
+ (funcall
+ (or (seq-some (pcase-lambda (`(,mode . ,fun))
+ (when (or (and (boundp mode) mode)
+ (derived-mode-p mode))
+ fun))
+ code-cells-eval-region-commands)
+ (user-error
+ "No entry for the current modes in
`code-cells-eval-region-commands'."))
+ start end)
+ (pulse-momentary-highlight-region start end))
+
+;;;###autoload
+(defun code-cells-eval-above (arg)
+ "Evaluate this and all above cells."
+ (interactive "p")
+ (code-cells-eval (point-min) (save-excursion
+ (code-cells-forward-cell arg)
+ (point))))
+
;;; Minor mode
(defvar-local code-cells--saved-vars nil
@@ -237,6 +280,14 @@ level."
(font-lock-remove-keywords nil (code-cells--font-lock-keywords)))
(font-lock-flush))
+(let ((map (make-sparse-keymap)))
+ (define-key code-cells-mode-map "\C-c%" map)
+ (define-key map ";" 'code-cells-comment-or-uncomment)
+ (define-key map "@" 'code-cells-mark-cell)
+ (define-key map "b" 'code-cells-backward-cell)
+ (define-key map "f" 'code-cells-forward-cell)
+ (define-key map "e" 'code-cells-eval))
+
;;; Jupyter notebook conversion
(defcustom code-cells-convert-ipynb-style
- [elpa] externals/code-cells 2dc51b44a3 12/36: Correct outline level before first cell header, (continued)
- [elpa] externals/code-cells 2dc51b44a3 12/36: Correct outline level before first cell header, ELPA Syncer, 2022/02/28
- [elpa] externals/code-cells 9500e07f83 15/36: Fix byte-compilation issue, ELPA Syncer, 2022/02/28
- [elpa] externals/code-cells adda62ec82 16/36: Address some packaging issues, ELPA Syncer, 2022/02/28
- [elpa] externals/code-cells 67e1479a75 28/36: Add code-cells-mode-maybe, ELPA Syncer, 2022/02/28
- [elpa] externals/code-cells f93db2d65c 29/36: Refinement in Commentary section, ELPA Syncer, 2022/02/28
- [elpa] externals/code-cells 47305f5439 31/36: Indicate that spaces are allowed before cell boundary marker, ELPA Syncer, 2022/02/28
- [elpa] externals/code-cells 68148cfc1f 33/36: Improve cell boundary face, ELPA Syncer, 2022/02/28
- [elpa] externals/code-cells f5150fc213 34/36: Update README.md, ELPA Syncer, 2022/02/28
- [elpa] externals/code-cells 55e108733a 06/36: Add helper function to call external processes, ELPA Syncer, 2022/02/28
- [elpa] externals/code-cells e6f0230a40 05/36: Notes about the Jupytext integration, ELPA Syncer, 2022/02/28
- [elpa] externals/code-cells 83cb4d0095 24/36: Add code-cells-eval,
ELPA Syncer <=
- [elpa] externals/code-cells 84cc996bff 32/36: Add missing compile-time requirement, ELPA Syncer, 2022/02/28
- [elpa] externals/code-cells dcb0465a46 36/36: Fix image link, ELPA Syncer, 2022/02/28