Version 7 of emacs mode enhancement

Updated 2006-11-17 21:09:51 by CLN

I like emacs tcl-eval-region/defun very much, but sometimes if I walk through my code, I get annoying output for some commands. This makes tcl-eval-region somehow ineffective.

 set temp {0 0 0 0 0 0 0 0 0 0}
 => 0 0 0 0 0 0 0 0 0 0

This 2 elisp-functions do eval code of your source code the way tcl-eval-region does, but they prevent output by replacing ;;; with code without results before evaluating. I chose ;;; because one can use it without code becoming too dirty.

 set temp {1 1 1 1 1 1 1 1 1 1};;; #output is canceled
 =>
 set temp test;                    #output is not affected
 => test
 puts a;;;                         #output is not affected
 => a

how-to-use the functions: copy & paste the code into a file with .el extension. M-x load-file that file and then use them as you would use tcl-eval-region. after you have invoked them in a source buffer once, you have key-bindings C-c C-r for tcl-eval-region-no-output and C-c C-l for tcl-eval-line-no-output.

draw-back of this method: take care that you do not use ;;; for another purpose in the code you are evaluating via this functions.

 (defun tcl-eval-region-no-output ()
   "my own tcl-eval-region,  
 before sending a region to the tcl-process
 this function replaces
           ;;;
 with 
           ;; set tcl-eval-no-output {} ;;
 in order to prevent unwanted outputs"
   (interactive) 
   (local-set-key (kbd "C-c C-r") 'tcl-eval-region-no-output)
   (let* ((proc (inferior-tcl-proc))
          (s1 (buffer-substring (region-beginning) (region-end)))
          (s2 (replace-regexp-in-string ";;;" ";; set tcl-eval-no-output {};;" s1)))
     (tcl-send-string proc s2))
   )

 (defun tcl-eval-line-no-output ()
   "my own tcl-eval-line.
 before sending the tcl-code to the tcl-process
 it replaces
    ;;;   =>   ;; set tcl-eval-no-output {} ;;
 in order to prevent unwanted outputs"
   (interactive)
   (local-set-key (kbd "C-c C-l") 'tcl-eval-line-no-output)
   (let* ((proc (inferior-tcl-proc))
          (s1 (buffer-substring-no-properties (point-at-bol) (point-at-eol)))
          (s2 (replace-regexp-in-string ";;;" ";; set tcl-eval-no-output {};;" s1))
          (s3 (concat s2 "\n")))
     (tcl-send-string proc s3)
     (next-line))
   )

Category Dev. Tools