branch: externals/realgud commit 57eed605a4a144cf29a00a4881c8bf480f3c82dc Author: Jacob O'Donnell <jacobodonn...@gmail.com> Commit: Jacob O'Donnell <jacobodonn...@gmail.com>
making eval output truncate and saving all the current command hash instead of just eval for future usage --- realgud/common/track.el | 37 +++++++++++++++++++++++++++++-------- test/test-track.el | 48 +++++++++++++++++++++++++++++------------------- test/test-utils.el | 4 ++++ 3 files changed, 62 insertions(+), 27 deletions(-) diff --git a/realgud/common/track.el b/realgud/common/track.el index bb54384..eeeb3e9 100644 --- a/realgud/common/track.el +++ b/realgud/common/track.el @@ -42,6 +42,11 @@ :type 'symbolp :group 'realgud) +(defcustom realgud-eval-message-print-length 1000 +"If non-nil, truncate eval output into the echo area" + :type 'symbolp + :group 'realgud) + (declare-function buffer-killed? 'realgud-helper) (declare-function fn-p-to-fn?-alias 'realgud-helper) (declare-function realgud-bp-add-info 'realgud-bp) @@ -178,14 +183,23 @@ message." "Gets the output stripping the command and debugger prompt from the TEXT." (realgud:join-string (butlast (cdr (split-string text "\n"))) "\n")) +(defun realgud:get-command-name(command-name) + "Gets the COMMAND-NAME for this particular debugger." + (gethash command-name (buffer-local-value 'realgud-command-name-hash (current-buffer)))) + (defun realgud:eval-command-p(text) "Checks the TEXT if the command that was ran was an eval command." - (let ((eval-string (buffer-local-value 'realgud-eval-string (current-buffer)))) - (string-prefix-p eval-string (realgud:get-output-command text)))) + (string-prefix-p (realgud:get-command-name "eval") (realgud:get-output-command text))) + +(defun realgud:truncate-eval-message(text) + "Truncates the TEXT to the size of realgud-eval-message-print-length." + (if (< realgud-eval-message-print-length (length text)) + (substring text 0 realgud-eval-message-print-length) + text)) (defun realgud:message-eval-results(text) "Output the TEXT to the message area." - (message (realgud:get-eval-output text))) + (message (realgud:truncate-eval-message (realgud:get-eval-output text)))) (defun realgud:track-from-region(from to &optional cmd-mark opt-cmdbuf shortkey-on-tracing? no-warn-if-no-match?) @@ -761,11 +775,18 @@ find a location. non-nil if we can find a location. (if loc (or (realgud-track-loc-action loc cmdbuf) 't) nil)) )) - ) -(defun realgud-set-eval-string-to-buffer-local (command-hash) + ) + +(defun realgud:populate-command-hash(key value) + "Adds a KEY and VALUE to the realgud-command-name-hash the command name to a debugger specific command." + (puthash key + (replace-regexp-in-string "%.*" "" (car (split-string value " "))) + realgud-command-name-hash)) + +(defun realgud-set-command-name-hash-to-buffer-local (command-hash) "Sets the eval string as a buffer local variable from the COMMAND-HASH." - (set (make-local-variable 'realgud-eval-string) - (replace-regexp-in-string "%s" "" (or (gethash "eval" command-hash) "No Eval String")))) + (set (make-local-variable 'realgud-command-name-hash) (make-hash-table :test 'equal)) + (maphash 'realgud:populate-command-hash command-hash)) (defun realgud:track-set-debugger (debugger-name) "Set debugger name and information associated with that @@ -788,7 +809,7 @@ we can't find a debugger with that information.`. (setq command-hash (gethash base-variable-name realgud-command-hash)) ) - (realgud-set-eval-string-to-buffer-local command-hash) + (realgud-set-command-name-hash-to-buffer-local command-hash) (if regexp-hash (let* ( diff --git a/test/test-track.el b/test/test-track.el index 8dc6e21..c3f8f9d 100644 --- a/test/test-track.el +++ b/test/test-track.el @@ -11,20 +11,21 @@ (load-file "../realgud/debugger/trepan/core.el") (load-file "../realgud/debugger/trepan/init.el") -(declare-function __FILE__ 'load-relative) -(declare-function realgud-cmdbuf-init 'realgud-buffer-command) -(declare-function realgud-loc-filename 'realgud-loc) -(declare-function realgud-loc-p 'realgud-loc) -(declare-function realgud-loc-line-number 'realgud-loc) -(declare-function realgud:track-from-region 'realgud-track) -(declare-function realgud-track-loc 'realgud-track) -(declare-function realgud-track-loc-remaining 'realgud-track) -(declare-function realgud-track-selected-frame 'realgud-track) -(declare-function realgud-track-termination? 'realgud-track) -(declare-function realgud:get-eval-output 'realgud-track) -(declare-function realgud:get-output-command 'realgud-track) -(declare-function realgud:eval-command-p 'realgud-track) -(declare-function realgud-set-eval-string-to-buffer-local 'realgud-track) +(declare-function __FILE__ 'load-relative) +(declare-function realgud-cmdbuf-init 'realgud-buffer-command) +(declare-function realgud-loc-filename 'realgud-loc) +(declare-function realgud-loc-p 'realgud-loc) +(declare-function realgud-loc-line-number 'realgud-loc) +(declare-function realgud:track-from-region 'realgud-track) +(declare-function realgud-track-loc 'realgud-track) +(declare-function realgud-track-loc-remaining 'realgud-track) +(declare-function realgud-track-selected-frame 'realgud-track) +(declare-function realgud-track-termination? 'realgud-track) +(declare-function realgud:get-eval-output 'realgud-track) +(declare-function realgud:get-output-command 'realgud-track) +(declare-function realgud:eval-command-p 'realgud-track) +(declare-function realgud-set-command-name-hash-to-buffer-local 'realgud-track) +(declare-function realgud:truncate-eval-message 'realgud-track) (test-simple-start) @@ -103,15 +104,24 @@ trepan: That's all, folks... (assert-equal "" (realgud:get-output-command "")) (note "realgud:eval-command-p") -(set (make-local-variable 'realgud-eval-string) "eval ") +(setq test-command-name-hash (make-hash-table :test 'equal)) +(puthash "eval" "eval" test-command-name-hash) +(set (make-local-variable 'realgud-command-name-hash) test-command-name-hash) (assert-t (realgud:eval-command-p "eval 'cow'\n'cow'\n(pdb)")) (assert-nil (realgud:eval-command-p "next 1")) -(note "realgud-set-eval-string-to-buffer-local") +(note "realgud-set-command-name-hash-to-buffer-local") (setq test-command-hash (make-hash-table :test 'equal)) -(puthash "eval" "eval %s" test-command-hash) -(realgud-set-eval-string-to-buffer-local test-command-hash) -(assert-equal "eval " (buffer-local-value 'realgud-eval-string (current-buffer))) +(puthash "eval" "!%s" test-command-hash) +(realgud-set-command-name-hash-to-buffer-local test-command-hash) +(assert-equal "!" (gethash "eval" (buffer-local-value 'realgud-command-name-hash (current-buffer)))) + +(note "realgud:truncate-eval-message") +(let ((realgud-eval-message-print-length 500)) + (assert-equal (realgud:truncate-eval-message (make-string 501 ?x)) (make-string 500 ?x))) +(let ((realgud-eval-message-print-length 500)) + (assert-equal (realgud:truncate-eval-message "cat") "cat")) + ;; (setq debugger-bp-output (format "Breakpoint %d set at line %d\n\tin file %s.\n" ;; bp-num line-number test-filename)) diff --git a/test/test-utils.el b/test/test-utils.el index 47d9958..3fc0f42 100644 --- a/test/test-utils.el +++ b/test/test-utils.el @@ -12,6 +12,7 @@ (declare-function realgud:strip 'realgud-regexp) (declare-function __FILE__ 'load-relative) (declare-function realgud:canonic-major-mode 'realgud-utils) +(declare-function realgud:join-string 'realgud-utils) (test-simple-start) @@ -23,6 +24,9 @@ (assert-equal "abc" (realgud:strip "abc")) (assert-equal "def" (realgud:strip "\n def\t ")) +(note "realgud:join-string") +(assert-equal "a b c" (realgud:join-string '("a" "b" "c") " ")) + (note "realgud:flatten") (assert-equal '(abc) (realgud:flatten '(abc))) (assert-equal '(abc def h i j) (realgud:flatten '(abc (def (h) i) j)))