jed-users mailing list

[2006 Date Index] [2006 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

Re: read_mini leaves "" on stack


=?UTF-8?Q?J=C3=B6rg?= Sommer <joerg@xxxxxxxxxxxx> wrote:
>OK. Nice to know. But back to my problem: Run ispell for a wrong word and
>press ^G at the prompt. At me, it leave a empty string on the stack. IMO
>it's a problem of read_mini().

One of the advantages of using slang-2 try/catch exception handling
instead of slang-1 ERROR_BLOCKS is that the stack will be better
maintained.  Here is a patch to ispell.sl that illustrates what I
mean.  Note that there is nothing in the patch that explicitly deals
with the stack, nevertheless it fixes the problem that you have
reported.   This patch has also been checked into the svn repository.
Thanks, --John

Index: ispell.sl
===================================================================
--- ispell.sl	(revision 4)
+++ ispell.sl	(working copy)
@@ -86,36 +86,34 @@
    num_win = nwindows();
    pop2buf(buf);
    old_buf = pop2buf_whatbuf(ibuf);   
-   
-   ERROR_BLOCK 
-     {
-	sw2buf(old_buf);
-	pop2buf(buf);
-	if (num_win == 1) onewindow();
-	bury_buffer(ibuf);
-     }
 
    set_buffer_modified_flag(0);
-   num = read_mini("Enter choice. (^G to abort)", "0", Null_String);
-   num = sprintf ("(%s)", num);
-   
-   if (fsearch(num))
+   variable ok = 0;
+   try
      {
+	num = read_mini("Enter choice. (^G to abort)", "0", "");
+	if (0 == fsearch(sprintf ("(%s)", num)))
+	  throw RunTimeError, "$num is an invalid choice"$;
+
 	() = ffind_char (' '); trim();
 	push_mark_eol(); trim(); new_word = bufsubstr();
 	set_buffer_modified_flag(0);
 	sw2buf(old_buf);
 	pop2buf(buf);
+	ok = 1;
 	bskip_chars(letters); push_mark();
 	skip_chars(letters); del_region();
 	insert(new_word);
      }
-   else 
+   finally:
      {
-	sw2buf(old_buf);
-	pop2buf(buf);
+	if (ok == 0)
+	  {
+	     sw2buf(old_buf);
+	     pop2buf(buf);
+	  }
+	if (num_win == 1) onewindow();
+	bury_buffer(ibuf);
      }
-   if (num_win == 1) onewindow();
-   bury_buffer(ibuf);
 }
 

--------------------------
To unsubscribe send email to <jed-users-request@xxxxxxxxxxx> with
the word "unsubscribe" in the message body.
Need help? Email <jed-users-owner@xxxxxxxxxxx>.


[2006 date index] [2006 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]