shell.el 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. ;;; ede/shell.el --- A shell controlled by EDE.
  2. ;;
  3. ;; Copyright (C) 2009-2012 Free Software Foundation, Inc.
  4. ;;
  5. ;; Author: Eric M. Ludlam <eric@siege-engine.com>
  6. ;; This file is part of GNU Emacs.
  7. ;; GNU Emacs is free software: you can redistribute it and/or modify
  8. ;; it under the terms of the GNU General Public License as published by
  9. ;; the Free Software Foundation, either version 3 of the License, or
  10. ;; (at your option) any later version.
  11. ;; GNU Emacs is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;; GNU General Public License for more details.
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  17. ;;; Commentary:
  18. ;;
  19. ;; Run commands through a specialized EDE shell buffer. Commands will
  20. ;; be run as shell commands so users can type in their own thing in
  21. ;; the shells for testing purposes.
  22. ;;
  23. ;; Each thing that EDE wants to use will create a shell to interact with it.
  24. ;;; Code:
  25. (require 'ede)
  26. (declare-function comint-send-input "comint")
  27. (defmethod ede-shell-run-something ((target ede-target) command)
  28. "Create a shell to run stuff for TARGET.
  29. COMMAND is a text string representing the thing to be run."
  30. (let* ((buff (ede-shell-buffer target))
  31. (cp (ede-target-parent target))
  32. (dd (oref cp :directory)))
  33. ;; Show the new buffer.
  34. (when (not (get-buffer-window buff))
  35. (switch-to-buffer-other-window buff t))
  36. ;; Force a shell into the buffer.
  37. (shell buff)
  38. (while (eq (point-min) (point))
  39. (accept-process-output))
  40. ;; Change the default directory
  41. (if (not (string= (file-name-as-directory (expand-file-name default-directory))
  42. (file-name-as-directory (expand-file-name dd))))
  43. ;; Go there.
  44. (setq command (concat (concat "cd " dd ";" command))))
  45. ;; Run the command itself.
  46. (ede-shell-run-command command)
  47. ))
  48. (defun ede-shell-run-command (command)
  49. "Run the COMMAND in the current shell-buffer."
  50. (require 'comint)
  51. ;; go to end
  52. (goto-char (point-max))
  53. ;; Insert the stuff.
  54. (goto-char (point-max))
  55. (insert command)
  56. ;; Send the command.
  57. (comint-send-input)
  58. )
  59. (defmethod ede-shell-buffer ((target ede-target))
  60. "Get the buffer for running shell commands for TARGET."
  61. (let ((name (ede-name target)))
  62. (get-buffer-create (format "*EDE Shell %s*" name))))
  63. (provide 'ede/shell)
  64. ;; Local variables:
  65. ;; generated-autoload-file: "loaddefs.el"
  66. ;; generated-autoload-load-name: "ede/shell"
  67. ;; End:
  68. ;;; ede/shell.el ends here