emacs mode enhancement

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))
   )

Bryan Oakley 16 Sept 2008 - Following is an elisp macro that takes a line of tcl code that looks like:

    foo -option1 value1 -option2 {option 2} -option3 \
        [value three -foo -bar]

... and converts it to something that looks like:

    foo \
        -option1 value1 \
        -option2 {option 2} \
        -option3 [value three -foo -bar]

I've wanted this function for years and never got around to writing it. I was experimenting with stackoverflow.com and when I didn't get a suitable answer for my question I suddenly found the motivation to write it myself. My elisp is extremely rusty so I make no guarantees but it seems to work in the limited amount of testing I've done.

Bind tcl-multiline-options to something like C-x \, move your cursor onto a line of Tcl code (or even a continuation line), press the magic keystroke, and voila!

    (defun tcl-multiline-options ()
      "spread option/value pairs across multiple lines with continuation characters"
      (interactive)
      (save-excursion
        (tcl-join-continuations)
        (beginning-of-line)
        (while (re-search-forward " -[^ ]+ +"  (line-end-position) t)
          (goto-char (match-beginning 0))
          (insert " \\\n")
          (goto-char (+(match-end 0) 3))
          (indent-according-to-mode)
          (forward-sexp))
        ))

    (defun tcl-join-continuations ()
      "join multiple continuation lines into a single physical line"
      (interactive)
      (while (progn (end-of-line) (char-equal (char-before) ?\\))
        (forward-line 1))
      (while (save-excursion (end-of-line 0) (char-equal (char-before) ?\\))
        (end-of-line 0)
        (delete-char -1)
        (delete-char 1)
        (fixup-whitespace)
        ))