aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Steingold2013-08-20 21:16:27 -0400
committerSam Steingold2013-08-20 21:16:27 -0400
commit6e50e9836a5e539cf2286fff44e9966e074f9c7b (patch)
treece415c188150d0b0c7fd7fcfd27eadb49af2ed0d
parentdbb0d3504311881c0a944855b54e3ef1fb301651 (diff)
downloademacs-6e50e9836a5e539cf2286fff44e9966e074f9c7b.tar.gz
emacs-6e50e9836a5e539cf2286fff44e9966e074f9c7b.zip
Add rudimentary inferior shell interaction
* lisp/progmodes/sh-script.el (sh-shell-process): New buffer-local variable. (sh-set-shell): Reset it. (sh-show-shell, sh-cd-here, sh-send-line-or-region-and-step): New commands (bound to C-c C-z, C-c C-d, and C-c C-n).
-rw-r--r--lisp/ChangeLog8
-rw-r--r--lisp/progmodes/sh-script.el59
2 files changed, 67 insertions, 0 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 8e33b30f697..9050178b706 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,11 @@
12013-08-21 Sam Steingold <sds@gnu.org>
2
3 Add rudimentary inferior shell interaction
4 * progmodes/sh-script.el (sh-shell-process): New buffer-local variable.
5 (sh-set-shell): Reset it.
6 (sh-show-shell, sh-cd-here, sh-send-line-or-region-and-step): New
7 commands (bound to C-c C-z, C-c C-d, and C-c C-n).
8
12013-08-20 Stefan Monnier <monnier@iro.umontreal.ca> 92013-08-20 Stefan Monnier <monnier@iro.umontreal.ca>
2 10
3 * align.el: Use lexical-binding. 11 * align.el: Use lexical-binding.
diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el
index 29020d95226..c8b65e0a029 100644
--- a/lisp/progmodes/sh-script.el
+++ b/lisp/progmodes/sh-script.el
@@ -497,6 +497,9 @@ This is buffer-local in every such buffer.")
497 (define-key map "\C-c+" 'sh-add) 497 (define-key map "\C-c+" 'sh-add)
498 (define-key map "\C-\M-x" 'sh-execute-region) 498 (define-key map "\C-\M-x" 'sh-execute-region)
499 (define-key map "\C-c\C-x" 'executable-interpret) 499 (define-key map "\C-c\C-x" 'executable-interpret)
500 (define-key map "\C-c\C-n" 'sh-send-line-or-region-and-step)
501 (define-key map "\C-c\C-d" 'sh-cd-here)
502 (define-key map "\C-c\C-z" 'sh-show-shell)
500 503
501 (define-key map [remap delete-backward-char] 504 (define-key map [remap delete-backward-char]
502 'backward-delete-char-untabify) 505 'backward-delete-char-untabify)
@@ -1462,6 +1465,61 @@ The default is t because I assume that in one Emacs session one is
1462frequently editing existing scripts with different styles.") 1465frequently editing existing scripts with different styles.")
1463 1466
1464 1467
1468;; inferior shell interaction
1469;; TODO: support multiple interactive shells
1470(defvar sh-shell-process nil
1471 "The inferior shell process for interaction.")
1472(make-variable-buffer-local 'sh-shell-process)
1473(defun sh-shell-process (force)
1474 "Get a shell process for interaction.
1475If FORCE is non-nil and no process found, create one."
1476 (if (and sh-shell-process (process-live-p sh-shell-process))
1477 sh-shell-process
1478 (setq sh-shell-process
1479 (let ((found nil) proc
1480 (procs (process-list)))
1481 (while (and (not found) procs
1482 (process-live-p (setq proc (pop procs)))
1483 (process-command proc))
1484 (when (string-equal sh-shell (file-name-nondirectory
1485 (car (process-command proc))))
1486 (setq found proc)))
1487 (or found
1488 (and force
1489 (get-buffer-process
1490 (let ((explicit-shell-file-name sh-shell-file))
1491 (shell)))))))))
1492
1493(defun sh-show-shell ()
1494 "Pop the shell interaction buffer."
1495 (interactive)
1496 (pop-to-buffer (process-buffer (sh-shell-process t))))
1497
1498(defun sh-send-text (text)
1499 "Send the text to the `sh-shell-process'."
1500 (comint-send-string (sh-shell-process t) (concat text "\n")))
1501
1502(defun sh-cd-here ()
1503 "Change directory in the current interaction shell to the current one."
1504 (interactive)
1505 (sh-send-text (concat "cd " default-directory)))
1506
1507(defun sh-send-line-or-region-and-step ()
1508 "Send the current line to the inferior shell and step to the next line.
1509When the region is active, send the region instead."
1510 (interactive)
1511 (let (from to end)
1512 (if (use-region-p)
1513 (setq from (region-beginning)
1514 to (region-end)
1515 end to)
1516 (setq from (line-beginning-position)
1517 to (line-end-position)
1518 end (1+ to)))
1519 (sh-send-text (buffer-substring-no-properties from to))
1520 (goto-char end)))
1521
1522
1465;; mode-command and utility functions 1523;; mode-command and utility functions
1466 1524
1467;;;###autoload 1525;;;###autoload
@@ -2169,6 +2227,7 @@ Calls the value of `sh-set-shell-hook' if set."
2169 (setq font-lock-set-defaults nil) 2227 (setq font-lock-set-defaults nil)
2170 (font-lock-set-defaults) 2228 (font-lock-set-defaults)
2171 (font-lock-fontify-buffer)) 2229 (font-lock-fontify-buffer))
2230 (setq sh-shell-process nil)
2172 (run-hooks 'sh-set-shell-hook)) 2231 (run-hooks 'sh-set-shell-hook))
2173 2232
2174 2233