[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 395db6d 016/215: Simplify eshell/comint/shell mode testing
From: |
Rocky Bernstein |
Subject: |
[elpa] master 395db6d 016/215: Simplify eshell/comint/shell mode testing. |
Date: |
Sat, 30 Jul 2016 14:48:48 +0000 (UTC) |
branch: master
commit 395db6d7723c67e86eb171feececb546b9a66a4b
Author: rocky <address@hidden>
Commit: rocky <address@hidden>
Simplify eshell/comint/shell mode testing.
Thanks to pythonnut: http://emacs.stackexchange.com/users/2642/pythonnut
http://emacs.stackexchange.com/questions/10387/how-can-i-tell-if-a-buffer-is-a-comint-buffer-eshell-buffer-or-neither/10390?iemail=1&noredirect=1#10390
---
realgud/common/send.el | 29 +++++++++++++----------------
realgud/common/track-mode.el | 32 +++++++++++++++++++-------------
realgud/common/utils.el | 15 +++++++++++++++
test/test-utils.el | 24 ++++++++++++++++++++++++
4 files changed, 71 insertions(+), 29 deletions(-)
diff --git a/realgud/common/send.el b/realgud/common/send.el
index 85f26b5..7ec0051 100644
--- a/realgud/common/send.el
+++ b/realgud/common/send.el
@@ -18,41 +18,38 @@
(require 'comint)
(require 'eshell)
(require 'load-relative)
-(require-relative-list '("window") "realgud-")
+(require-relative-list '("utils" "window") "realgud-")
(require-relative-list '("buffer/helper") "realgud-buffer-")
(declare-function realgud-get-cmdbuf 'realgud-buffer-helper)
(declare-function comint-goto-process-mark 'comint)
(declare-function comint-send-input 'comint)
+(declare-function realgud:canonic-major-mode 'realgud-utils)
(defun realgud:send-input ()
"Sends command buffer line either to comint or eshell"
(interactive)
- ;; FIXME DRY with code in realgud:send-command-common() and track-mode.el
- (cond ((and (boundp 'eshell-mode) eshell-mode)
- (eshell-send-input))
- ((and (boundp 'comint-prompt-regexp)
- (comint-check-proc (current-buffer)))
- (comint-send-input))
- ('t (error "We can only handle comint or eshell buffers")))
- )
+ (let ((mode (realgud:canonic-major-mode)))
+ (cond ((eq mode 'eshell)
+ (eshell-send-input))
+ ((eq mode 'comint)
+ (comint-send-input))
+ )))
(defun realgud:send-command-common (process command-str)
"Assume we are in a comint buffer. Insert COMMAND-STR and
send that input onto the process."
(if (eq 'run (process-status process))
- (progn
- ;; FIXME DRY with code in realgud:send-input() and track-mode.el
- (cond ((and (boundp 'eshell-mode) eshell-mode)
+ (let ((mode (realgud:canonic-major-mode)))
+ (cond ((eq mode 'eshell)
(goto-char eshell-last-output-end)
(setq eshell-last-output-start
(setq realgud-last-output-start (point-marker))))
- ((and (boundp 'comint-prompt-regexp)
- (comint-check-proc (current-buffer)))
+ ((eq mode 'comint)
+ (comint-check-proc (current-buffer))
(comint-goto-process-mark)
(setq comint-last-output-start
- (setq realgud-last-output-start (point-marker))))
- ('t (error "We can only handle cmint or eshell buffers")))
+ (setq realgud-last-output-start (point-marker)))))
(insert command-str)
(realgud:send-input)
)
diff --git a/realgud/common/track-mode.el b/realgud/common/track-mode.el
index 4199181..31539b3 100644
--- a/realgud/common/track-mode.el
+++ b/realgud/common/track-mode.el
@@ -23,7 +23,7 @@
(require-relative-list
'("core" "helper" "track" "loc" "lochist" "file"
"fringe" "window" "regexp" "menu" "backtrace-mode"
- "send" "shortkey") "realgud-")
+ "send" "shortkey" "utils") "realgud-")
(require-relative-list '("buffer/command") "realgud-buffer-")
@@ -37,6 +37,8 @@
'realgud-buffer-command)
(declare-function realgud-cmdbuf-info-set?
'realgud-buffer-command)
+(declare-function realgud:canonic-major-mode
+ 'realgud-utils)
(defvar realgud-track-mode-map
(let ((map (copy-keymap shell-mode-map)))
@@ -138,14 +140,14 @@ of this mode."
(set (make-local-variable 'tool-bar-map) realgud:tool-bar-map)
;; FIXME DRY with code in send.el
- (cond ((and (boundp 'eshell-mode) eshell-mode)
- (add-hook 'eshell-output-filter-functions
- 'realgud-track-eshell-output-filter-hook))
- ((and (boundp 'comint-prompt-regexp)
- (comint-check-proc (current-buffer)))
- (add-hook 'comint-output-filter-functions
- 'realgud-track-comint-output-filter-hook))
- ('t (error "We can only handle comint or eshell buffers")))
+ (let ((mode (realgud:canonic-major-mode)))
+ (cond ((eq mode 'eshell)
+ (add-hook 'eshell-output-filter-functions
+ 'realgud-track-eshell-output-filter-hook))
+ ((eq mode 'comint)
+ (add-hook 'comint-output-filter-functions
+ 'realgud-track-comint-output-filter-hook))
+ ))
(run-mode-hooks 'realgud-track-mode-hook))
;; else
(progn
@@ -155,10 +157,14 @@ of this mode."
)
(kill-local-variable 'realgud:tool-bar-map)
(realgud-fringe-erase-history-arrows)
- (remove-hook 'comint-output-filter-functions
- 'realgud-track-comint-output-filter-hook)
- (remove-hook 'eshell-output-filter-functions
- 'realgud-track-eshell-output-filter-hook)
+ (let ((mode (realgud:canonic-major-mode)))
+ (cond ((eq mode 'eshell)
+ (remove-hook 'eshell-output-filter-functions
+ 'realgud-track-eshell-output-filter-hook))
+ ((eq mode 'comint)
+ (remove-hook 'comint-output-filter-functions
+ 'realgud-track-comint-output-filter-hook))
+ ))
(let* ((cmd-process (get-buffer-process (current-buffer)))
(status (if cmd-process
(list (propertize (format ":%s"
diff --git a/realgud/common/utils.el b/realgud/common/utils.el
index aede640..66f6509 100644
--- a/realgud/common/utils.el
+++ b/realgud/common/utils.el
@@ -1,4 +1,6 @@
(require 'load-relative)
+(require 'comint)
+(require 'eshell)
(defun realgud:strip (str)
"Remove leading and tailing whitespace from STR."
@@ -15,4 +17,17 @@
(t
(append (realgud:flatten (car mylist)) (realgud:flatten (cdr mylist))))))
+(defun realgud:canonic-major-mode()
+ "Return
+ - 'eshell if we are in eshell-mode,
+ - 'comint if the major comint-mode or shell-mode
+Or raise an error if neither."
+
+ (cond ((eq major-mode 'eshell-mode)
+ 'eshell)
+ ((or (eq major-mode 'comint-mode) (eq major-mode 'shell-mode))
+ 'comint)
+ ('t (error "We can only handle comint, shell or eshell buffers"))
+ ))
+
(provide-me "realgud-")
diff --git a/test/test-utils.el b/test/test-utils.el
index 318a2e7..7605557 100644
--- a/test/test-utils.el
+++ b/test/test-utils.el
@@ -1,9 +1,14 @@
(require 'test-simple)
+(require 'comint)
+(require 'eshell)
+(require 'shell)
+
(load-file "../realgud/common/utils.el")
(declare-function realgud:flatten 'realgud-utils)
(declare-function realgud:strip 'realgud-regexp)
(declare-function __FILE__ 'load-relative)
+(declare-function realgud:canonic-major-mode 'realgud-utils)
(test-simple-start)
@@ -19,4 +24,23 @@
(assert-equal '(abc) (realgud:flatten '(abc)))
(assert-equal '(abc def h i j) (realgud:flatten '(abc (def (h) i) j)))
+(note "realgud:canonic-major-mode")
+
+(assert-raises error (realgud:canonic-major-mode)
+ "Not in eshell, comint or shell-mode")
+
+(with-temp-buffer
+ (comint-mode)
+ (assert-equal 'comint (realgud:canonic-major-mode)))
+
+(with-temp-buffer
+ (eshell-mode)
+ (assert-equal 'eshell (realgud:canonic-major-mode)))
+
+;; (with-temp-buffer
+;; (start-process "bogus" (current-buffer) "sleep" "1")
+;; (shell-mode)
+;; (assert-equal 'comint (realgud:canonic-major-mode))
+;; )
+
(end-tests)
- [elpa] master 9e2656a 029/215: Correct nodejs/init.el bugs - sync with master, (continued)
- [elpa] master 9e2656a 029/215: Correct nodejs/init.el bugs - sync with master, Rocky Bernstein, 2016/07/30
- [elpa] master 9cf5e4d 028/215: Add breakpoint set to nodejs, Rocky Bernstein, 2016/07/30
- [elpa] master 3993d13 020/215: Respect shortkey mode setting, Rocky Bernstein, 2016/07/30
- [elpa] master 3a0b837 022/215: Update README.md to note that we can use in eshell, Rocky Bernstein, 2016/07/30
- [elpa] master 886f741 024/215: Make sure we go into realgud-track mode when we have custom mode, Rocky Bernstein, 2016/07/30
- [elpa] master dc0b45b 034/215: Revert "Squelch one of the many compiler warnings", Rocky Bernstein, 2016/07/30
- [elpa] master b8d8686 032/215: Squelch one of the many compiler warnings, Rocky Bernstein, 2016/07/30
- [elpa] master 266e5df 021/215: Small error message grammar correction, Rocky Bernstein, 2016/07/30
- [elpa] master e2c3271 015/215: Minimal support for running under eshell, Rocky Bernstein, 2016/07/30
- [elpa] master 33bfa6f 033/215: Squelch one of the many compiler warnings, Rocky Bernstein, 2016/07/30
- [elpa] master 395db6d 016/215: Simplify eshell/comint/shell mode testing.,
Rocky Bernstein <=
- [elpa] master 2acb30c 031/215: Start js lang. add js backtrace regexp, Rocky Bernstein, 2016/07/30
- [elpa] master 1868152 025/215: core.el: remove duplicate command buffer creation, Rocky Bernstein, 2016/07/30
- [elpa] master b920afc 043/215: trepanjs: handle eval properly, Rocky Bernstein, 2016/07/30
- [elpa] master ea27a82 026/215: More copyright assignments to FSF, Rocky Bernstein, 2016/07/30
- [elpa] master 3d74bb5 013/215: More FSF copyright assignments., Rocky Bernstein, 2016/07/30
- [elpa] master 0e68d8d 038/215: common/regexp.el: start to DRY regexps, Rocky Bernstein, 2016/07/30
- [elpa] master 03ecacd 049/215: trepanjs msg change: stop in -> call in, Rocky Bernstein, 2016/07/30
- [elpa] master 986585b 035/215: Revert "Squelch one of the many compiler warnings", Rocky Bernstein, 2016/07/30
- [elpa] master 78aba8b 044/215: DRY with respect to realgud:regexp-captured-num, Rocky Bernstein, 2016/07/30
- [elpa] master bfa52c5 046/215: caddr -> cl-caddr. Fill in %s on format., Rocky Bernstein, 2016/07/30