diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1998-07-15 06:13:08 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1998-07-15 06:13:08 +0000 |
commit | c30c3bffe472ee999fc722f63dd1c1984db1d1ce (patch) | |
tree | fd5a1cd95ad875ce2768b09c88cecc155dba74b8 | |
parent | 35c6e6af5ba2c405a91dc6b9e4af833d0979ed22 (diff) |
1.1b9_31
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@267 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 20 | ||||
-rw-r--r-- | bignum.c | 14 | ||||
-rw-r--r-- | eval.c | 36 | ||||
-rw-r--r-- | ext/tcltklib/tcltklib.c | 68 | ||||
-rw-r--r-- | gc.c | 10 | ||||
-rw-r--r-- | lib/matrix.rb | 10 | ||||
-rw-r--r-- | lib/pstore.rb | 3 | ||||
-rw-r--r-- | lib/tk.rb | 175 | ||||
-rw-r--r-- | lib/tkcanvas.rb | 150 | ||||
-rw-r--r-- | lib/tkfont.rb | 445 | ||||
-rw-r--r-- | lib/tktext.rb | 216 | ||||
-rw-r--r-- | lib/weakref.rb | 4 | ||||
-rw-r--r-- | numeric.c | 7 | ||||
-rw-r--r-- | parse.y | 2 | ||||
-rw-r--r-- | sample/ruby-mode.el | 42 | ||||
-rw-r--r-- | sprintf.c | 6 | ||||
-rw-r--r-- | variable.c | 18 | ||||
-rw-r--r-- | version.h | 4 |
18 files changed, 1024 insertions, 206 deletions
@@ -1,7 +1,27 @@ +Wed Jul 15 15:11:57 1998 Yukihiro Matsumoto <[email protected]> + + * experimental release 1.1b9_31. + +Wed Jul 15 15:05:27 1998 Yukihiro Matsumoto <[email protected]> + + * eval.c (thread_create): exit() and abort() in threads now + forwarded to main_thread. + +Tue Jul 14 14:03:47 1998 Yukihiro Matsumoto <[email protected]> + + * variable.c (obj_instance_variables): list names that is not + instance variables. + + * gc.c (GC_MALLOC_LIMIT): choose smaller limit value. + Mon Jul 13 12:39:38 1998 Yukihiro Matsumoto <[email protected]> * object.c (str2cstr): should not return NULL. +Fri Jul 10 11:51:46 1998 Yukihiro Matsumoto <[email protected]> + + * parse.y (gettable): needed to add dyna_in_block() check. + Thu Jul 9 17:38:23 1998 Yukihiro Matsumoto <[email protected]> * experimental release 1.1b9_30. @@ -19,7 +19,7 @@ typedef unsigned short USHORT; #define BITSPERDIG (sizeof(short)*CHAR_BIT) #define BIGRAD (1L << BITSPERDIG) #define DIGSPERINT ((unsigned int)(sizeof(long)/sizeof(short))) -#define BIGUP(x) ((unsigned int)(x) << BITSPERDIG) +#define BIGUP(x) ((unsigned long)(x) << BITSPERDIG) #define BIGDN(x) (((x)<0) ? ~((~(x))>>BITSPERDIG) : (x)>>BITSPERDIG) #define BIGLO(x) ((x) & (BIGRAD-1)) @@ -85,17 +85,17 @@ bignorm(x) while (len-- && !ds[len]) ; RBIGNUM(x)->len = ++len; - if (len*sizeof(USHORT) < sizeof(VALUE) || - (len*sizeof(USHORT) == sizeof(VALUE) && - ds[sizeof(VALUE)/sizeof(USHORT)-1] <= 0x3fff)) { + if (len*sizeof(USHORT) <= sizeof(VALUE)) { long num = 0; while (len--) { num = BIGUP(num) + ds[len]; } - if (RBIGNUM(x)->sign) { - if (POSFIXABLE(num)) return INT2FIX(num); + if (num >= 0) { + if (RBIGNUM(x)->sign) { + if (POSFIXABLE(num)) return INT2FIX(num); + } + else if (NEGFIXABLE(-num)) return INT2FIX(-num); } - else if (NEGFIXABLE(-num)) return INT2FIX(-num); } return x; } @@ -5649,7 +5649,6 @@ thread_remove() curr_thread->status = THREAD_KILLED; curr_thread->prev->next = curr_thread->next; curr_thread->next->prev = curr_thread->prev; - thread_schedule(); } static int @@ -6230,6 +6229,8 @@ catch_timer(sig) int thread_tick = THREAD_TICK; #endif +static VALUE thread_raise _((int, VALUE*, VALUE)); + VALUE thread_create(fn, arg) VALUE (*fn)(); @@ -6274,36 +6275,29 @@ thread_create(fn, arg) } } POP_TAG(); + thread_remove(); if (state && th->status != THREAD_TO_KILL && !NIL_P(errinfo)) { - if (state == TAG_FATAL || obj_is_kind_of(errinfo, eSystemExit) || - thread_abort || curr_thread->abort || RTEST(debug)) { - /* fatal error or global exit within this thread */ - /* need to stop whole script */ + if (state == TAG_FATAL) { + /* fatal error within this thread, need to stop whole script */ main_thread->errinfo = errinfo; thread_cleanup(); } -#if 0 + else if (obj_is_kind_of(errinfo, eSystemExit)) { + /* delegate exception to main_thread */ + thread_raise(1, &errinfo, main_thread->thread); + } else if (thread_abort || curr_thread->abort || RTEST(debug)) { - thread_critical = 0; - thread_ready(main_thread); - main_thread->errinfo = errinfo; - if (curr_thread == main_thread) { - rb_raise(errinfo); - } - curr_thread = main_thread; - th_raise_argc = 1; - th_raise_argv[0] = errinfo; - th_raise_file = sourcefile; - th_raise_line = sourceline; - thread_restore_context(curr_thread, 4); + VALUE err = exc_new(eSystemExit, 0, 0); + error_print(); + /* exit on main_thread */ + thread_raise(1, &err, main_thread->thread); } -#endif else { curr_thread->errinfo = errinfo; } } - thread_remove(); - return 0; + thread_schedule(); + return 0; /* not reached */ } static VALUE diff --git a/ext/tcltklib/tcltklib.c b/ext/tcltklib/tcltklib.c index df242997e8..5948c8f5b0 100644 --- a/ext/tcltklib/tcltklib.c +++ b/ext/tcltklib/tcltklib.c @@ -242,6 +242,72 @@ ip_eval(VALUE self, VALUE str) return(str_new2(ptr->ip->result)); } + +static VALUE +ip_toUTF8(VALUE self, VALUE str, VALUE encodename) +{ +#ifndef TCL_UTF_MAX + return str; +#else + Tcl_Interp *interp; + Tcl_Encoding encoding; + Tcl_DString dstr; + struct tcltkip *ptr; + char *buff1,*buff2; + + Data_Get_Struct(self,struct tcltkip, ptr); + interp = ptr->ip; + + encoding = Tcl_GetEncoding(interp,STR2CSTR(encodename)); + buff1 = ALLOCA_N(char,strlen(STR2CSTR(str))+1); + strcpy(buff1,STR2CSTR(str)); + + Tcl_DStringInit(&dstr); + Tcl_DStringFree(&dstr); + Tcl_ExternalToUtfDString(encoding,buff1,strlen(buff1),&dstr); + buff2 = ALLOCA_N(char,Tcl_DStringLength(&dstr)+1); + strcpy(buff2,Tcl_DStringValue(&dstr)); + + Tcl_FreeEncoding(encoding); + Tcl_DStringFree(&dstr); + + return str_new2(buff2); +#endif +} + +static VALUE +ip_fromUTF8(VALUE self, VALUE str, VALUE encodename) +{ +#ifndef TCL_UTF_MAX + return str; +#else + Tcl_Interp *interp; + Tcl_Encoding encoding; + Tcl_DString dstr; + struct tcltkip *ptr; + char *buff1,*buff2; + + Data_Get_Struct(self,struct tcltkip, ptr); + interp = ptr->ip; + + encoding = Tcl_GetEncoding(interp,STR2CSTR(encodename)); + buff1 = ALLOCA_N(char,strlen(STR2CSTR(str))+1); + strcpy(buff1,STR2CSTR(str)); + + Tcl_DStringInit(&dstr); + Tcl_DStringFree(&dstr); + Tcl_UtfToExternalDString(encoding,buff1,strlen(buff1),&dstr); + buff2 = ALLOCA_N(char,Tcl_DStringLength(&dstr)+1); + strcpy(buff2,Tcl_DStringValue(&dstr)); + + Tcl_FreeEncoding(encoding); + Tcl_DStringFree(&dstr); + + return str_new2(buff2); +#endif +} + + static VALUE ip_invoke(int argc, VALUE *argv, VALUE obj) { @@ -356,6 +422,8 @@ void Init_tcltklib() rb_define_singleton_method(ip, "new", ip_new, 0); rb_define_method(ip, "_eval", ip_eval, 1); + rb_define_method(ip, "_toUTF8",ip_toUTF8,2); + rb_define_method(ip, "_fromUTF8",ip_fromUTF8,2); rb_define_method(ip, "_invoke", ip_invoke, -1); rb_define_method(ip, "_return_value", ip_retval, 0); rb_define_method(ip, "mainloop", lib_mainloop, 0); @@ -37,9 +37,9 @@ static void run_final(); #ifndef GC_MALLOC_LIMIT #if defined(MSDOS) || defined(__human68k__) -#define GC_MALLOC_LIMIT 200000 +#define GC_MALLOC_LIMIT 100000 #else -#define GC_MALLOC_LIMIT 400000 +#define GC_MALLOC_LIMIT 200000 #endif #endif @@ -55,12 +55,10 @@ xmalloc(size) ArgError("negative allocation size (or too big)"); } if (size == 0) size = 1; -#if 0 malloc_memories += size; if (malloc_memories > GC_MALLOC_LIMIT) { gc_gc(); } -#endif mem = malloc(size); if (!mem) { gc_gc(); @@ -95,6 +93,10 @@ xrealloc(ptr, size) ArgError("negative re-allocation size"); } if (!ptr) return xmalloc(size); + malloc_memories += size; + if (malloc_memories > GC_MALLOC_LIMIT) { + gc_gc(); + } mem = realloc(ptr, size); if (!mem) { gc_gc(); diff --git a/lib/matrix.rb b/lib/matrix.rb index 6639fe72ea..3924e93ecb 100644 --- a/lib/matrix.rb +++ b/lib/matrix.rb @@ -2,8 +2,8 @@ # # matrix.rb - # $Release Version: 1.0$ -# $Revision: 1.4 $ -# $Date: 1998/07/08 06:39:13 $ +# $Revision: 1.5 $ +# $Date: 1998/07/14 14:35:18 $ # Original Version from Smalltalk-80 version # on July 23, 1985 at 8:37:17 am # by Keiju ISHITSUKA @@ -180,8 +180,8 @@ module ExceptionForMatrix end class Matrix - @RCS_ID='-$Id: matrix.rb,v 1.4 1998/07/08 06:39:13 keiju Exp keiju $-' - + @RCS_ID='-$Id: matrix.rb,v 1.5 1998/07/14 14:35:18 keiju Exp keiju $-' + include ExceptionForMatrix # instance creations @@ -857,7 +857,7 @@ class Vector end def clone - Vector.elements(@rows) + Vector.elements(@elements) end def hash diff --git a/lib/pstore.rb b/lib/pstore.rb index 3f95e8c059..743b1da5d0 100644 --- a/lib/pstore.rb +++ b/lib/pstore.rb @@ -89,6 +89,9 @@ class PStore catch(:pstore_abort_transaction) do value = yield(self) end + rescue Exception + @abort = true + raise ensure unless @abort begin @@ -33,6 +33,8 @@ module TkComm return val.split.collect{|v| tk_tcl2ruby(v)} end case val + when /^@font/ + TkFont.get_obj(val) when /^-?\d+$/ val.to_i when /^\./ @@ -277,11 +279,11 @@ module TkComm end def _bind(path, context, cmd, args=nil) - _bind_core('', path, context, cmd, args=nil) + _bind_core('', path, context, cmd, args) end def _bind_append(path, context, cmd, args=nil) - _bind_core('+', path, context, cmd, args=nil) + _bind_core('+', path, context, cmd, args) end private :install_bind, :tk_event_sequence, :_bind_core, :_bind, :_bind_append @@ -412,6 +414,10 @@ module TkCore TclTkLib.mainloop end + def messageBox(keys) + tk_call 'tk_messageBox', *hash_kv(keys) + end + def tk_call(*args) print args.join(" "), "\n" if $DEBUG args.filter {|x|_get_eval_string(x)} @@ -443,6 +449,7 @@ module Tk TCL_VERSION = INTERP._invoke("info", "tclversion") TK_VERSION = INTERP._invoke("set", "tk_version") + JAPANIZED_TK = (INTERP._invoke("info", "commands", "kanji") != "") def root TkRoot.new @@ -452,6 +459,14 @@ module Tk tk_call 'bell' end + def toUTF8(str,encoding) + INTERP._toUTF8(str,encoding) + end + + def fromUTF8(str,encoding) + INTERP._fromUTF8(str,encoding) + end + module Scrollable def xscrollcommand(cmd=Proc.new) configure_cmd 'xscrollcommand', cmd @@ -1312,8 +1327,109 @@ module TkOption module_function :add, :clear, :get, :readfile end +module TkTreatFont + def font_configinfo + ret = TkFont.used_on(self.path) + if ret == nil + ret = TkFont.init_widget_font(self.path, self.path, 'configure') + end + ret + end + alias fontobj font_configinfo + + def font_configure(slot) + if (fnt = slot['font']) + slot['font'] = nil + if fnt.kind_of? TkFont + return fnt.call_font_configure(self.path, self.path,'configure',slot) + else + latinfont_configure(fnt) if fnt + end + end + if (ltn = slot['latinfont']) + slot['latinfont'] = nil + latinfont_configure(ltn) if ltn + end + if (ltn = slot['asciifont']) + slot['asciifont'] = nil + latinfont_configure(ltn) if ltn + end + if (knj = slot['kanjifont']) + slot['kanjifont'] = nil + kanjifont_configure(knj) if knj + end + + tk_call(self.path, 'configure', *hash_kv(slot)) if slot != {} + self + end + + def latinfont_configure(ltn, keys=nil) + fobj = fontobj + if ltn.kind_of? TkFont + conf = {} + ltn.latin_configinfo.each{|key,val| conf[key] = val} + if keys + fobj.latin_configure(conf.update(keys)) + else + fobj.latin_configure(conf) + end + else + fobj.latin_replace(ltn) + end + end + alias asciifont_configure latinfont_configure + + def kanjifont_configure(knj, keys=nil) + fobj = fontobj + if knj.kind_of? TkFont + conf = {} + knj.kanji_configinfo.each{|key,val| conf[key] = val} + if keys + fobj.kanji_configure(conf.update(keys)) + else + fobj.kanji_configure(cond) + end + else + fobj.kanji_replace(knj) + end + end + + def font_copy(window, tag=nil) + if tag + window.tagfontobj(tag).configinfo.each{|key,value| + fontobj.configure(key,value) + } + fontobj.replace(window.tagfontobj(tag).latin_font, + window.tagfontobj(tag).kanji_font) + else + window.fontobj.configinfo.each{|key,value| + fontobj.configure(key,value) + } + fontobj.replace(window.fontobj.latin_font, window.fontobj.kanji_font) + end + end + + def latinfont_copy(window, tag=nil) + if tag + fontobj.latin_replace(window.tagfontobj(tag).latin_font) + else + fontobj.latin_replace(window.fontobj.latin_font) + end + end + alias asciifont_copy latinfont_copy + + def kanjifont_copy(window, tag=nil) + if tag + fontobj.kanji_replace(window.tagfontobj(tag).kanji_font) + else + fontobj.kanji_replace(window.fontobj.kanji_font) + end + end +end + class TkObject<TkKernel include Tk + include TkTreatFont def path return @path @@ -1356,12 +1472,23 @@ class TkObject<TkKernel tk_tcl2ruby tk_call path, 'cget', "-#{slot}" end - def configure(slot, value=None) - if slot.kind_of? Hash - tk_call path, 'configure', *hash_kv(slot) - else - tk_call path, 'configure', "-#{slot}", value - end + def configure(slot, value=None) + if slot.kind_of? Hash + if ( slot['font'] || slot['kanjifont'] \ + || slot['latinfont'] || slot['asciifont'] ) + font_configure(slot.dup) + else + tk_call path, 'configure', *hash_kv(slot) + end + + else + if ( slot == 'font' || slot == 'kanjifont' \ + || slot == 'latinfont' || slot == 'asciifont' ) + font_configure({slot=>value}) + else + tk_call path, 'configure', "-#{slot}", value + end + end end def configure_cmd(slot, value) @@ -1369,15 +1496,27 @@ class TkObject<TkKernel end def configinfo(slot = nil) - if slot - conf = tk_split_list(tk_send('configure', "-#{slot}") ) - conf[0] = conf[0][1..-1] - conf + if slot == 'font' || slot == 'kanjifont' + fontobj + else - tk_split_list(tk_send('configure') ).collect{|conf| - conf[0] = conf[0][1..-1] - conf - } + if slot + conf = tk_split_list(tk_send('configure', "-#{slot}") ) + conf[0] = conf[0][1..-1] + conf + + else + ret = tk_split_list(tk_send('configure') ).collect{|conf| + conf[0] = conf[0][1..-1] + conf + } + if ret.assoc('font') + ret.delete_if{|item| item[0] == 'font' || item[0] == 'kanjifont'} + ret.push(['font', fontobj]) + else + ret + end + end end end @@ -1429,7 +1568,8 @@ class TkWindow<TkObject install_win(if parent then parent.path end) create_self if keys - tk_call @path, 'configure', *hash_kv(keys) + # tk_call @path, 'configure', *hash_kv(keys) + configure(keys) end end @@ -1996,3 +2136,4 @@ autoload :TkDialog, 'tkdialog' autoload :TkMenubar, 'tkmenubar' autoload :TkAfter, 'tkafter' autoload :TkPalette, 'tkpalette' +autoload :TkFont, 'tkfont' diff --git a/lib/tkcanvas.rb b/lib/tkcanvas.rb index 4ee0c3cd48..613e97af38 100644 --- a/lib/tkcanvas.rb +++ b/lib/tkcanvas.rb @@ -6,8 +6,124 @@ # by Hidetoshi Nagai <[email protected]> require "tk" +require 'tkfont' + +module TkTreatCItemFont + def tagfont_configinfo(tagOrId) + if tagOrId.kind_of?(TkcItem) || tagOrId.kind_of?(TkcTag) + pathname = self.path + ';' + tagOrId.id.to_s + else + pathname = self.path + ';' + tagOrId.to_s + end + ret = TkFont.used_on(pathname) + if ret == nil + ret = TkFont.init_widget_font(pathname, + self.path, 'itemconfigure', tagOrId) + end + ret + end + alias tagfontobj tagfont_configinfo + + def tagfont_configure(tagOrId, slot) + if tagOrId.kind_of?(TkcItem) || tagOrId.kind_of?(TkcTag) + pathname = self.path + ';' + tagOrId.id.to_s + else + pathname = self.path + ';' + tagOrId.to_s + end + if (fnt = slot['font']) + slot['font'] = nil + if fnt.kind_of? TkFont + return fnt.call_font_configure(pathname, + self.path,'itemconfigure',tagOrId,slot) + else + latintagfont_configure(tagOrId, fnt) if fnt + end + end + if (ltn = slot['latinfont']) + slot['latinfont'] = nil + latintagfont_configure(tagOrId, ltn) if ltn + end + if (ltn = slot['asciifont']) + slot['asciifont'] = nil + latintagfont_configure(tagOrId, ltn) if ltn + end + if (knj = slot['kanjifont']) + slot['kanjifont'] = nil + kanjitagfont_configure(tagOrId, knj) if knj + end + + tk_call(self.path, 'itemconfigure', tagOrId, *hash_kv(slot)) if slot != {} + self + end + + def latintagfont_configure(tagOrId, ltn, keys=nil) + fobj = tagfontobj(tagOrId) + if ltn.kind_of? TkFont + conf = {} + ltn.latin_configinfo.each{|key,val| conf[key] = val} + if keys + fobj.latin_configure(conf.update(keys)) + else + fobj.latin_configure(conf) + end + else + fobj.latin_replace(ltn) + end + end + alias asciitagfont_configure latintagfont_configure + + def kanjitagfont_configure(tagOrId, knj, keys=nil) + fobj = tagfontobj(tagOrId) + if knj.kind_of? TkFont + conf = {} + knj.kanji_configinfo.each{|key,val| conf[key] = val} + if keys + fobj.kanji_configure(conf.update(keys)) + else + fobj.kanji_configure(conf) + end + else + fobj.kanji_replace(knj) + end + end + + def tagfont_copy(tagOrId, window, wintag=nil) + if wintag + window.tagfontobj(wintag).configinfo.each{|key,value| + tagfontobj(tagOrId).configure(key,value) + } + tagfontobj(tagOrId).replace(window.tagfontobj(wintag).latin_font, + window.tagfontobj(wintag).kanji_font) + else + window.tagfont(tagOrId).configinfo.each{|key,value| + tagfontobj(tagOrId).configure(key,value) + } + tagfontobj(tagOrId).replace(window.fontobj.latin_font, + window.fontobj.kanji_font) + end + end + + def latintagfont_copy(tagOrId, window, wintag=nil) + if wintag + tagfontobj(tagOrId).latin_replace(window.tagfontobj(wintag).latin_font) + else + tagfontobj(tagOrId).latin_replace(window.fontobj.latin_font) + end + end + alias asciitagfont_copy latintagfont_copy + + def kanjitagfont_copy(tagOrId, window, wintag=nil) + if wintag + tagfontobj(tagOrId).kanji_replace(window.tagfontobj(wintag).kanji_font) + else + tagfontobj(tagOrId).kanji_replace(window.fontobj.kanji_font) + end + end +end class TkCanvas<TkWindow + include TkTreatCItemFont + WidgetClassName = 'Canvas'.freeze TkClassBind::WidgetClassNameTBL[WidgetClassName] = self def self.to_eval @@ -171,16 +287,34 @@ class TkCanvas<TkWindow end def itemcget(tagOrId, option) - tk_send 'itemcget', tagid(tagOrId), option + tk_send 'itemcget', tagid(tagOrId), "-#{option}" end def itemconfigure(tagOrId, key, value=None) if key.kind_of? Hash - tk_send 'itemconfigure', tagid(tagOrId), *hash_kv(key) + if ( key['font'] || key['kanjifont'] \ + || key['latinfont'] || key['asciifont'] ) + tagfont_configure(tagOrId, key.dup) + else + tk_send 'itemconfigure', tagid(tagOrId), *hash_kv(key) + end + else - tk_send 'itemconfigure', tagid(tagOrId), "-#{key}", value + if ( key == 'font' || key == 'kanjifont' \ + || key == 'latinfont' || key == 'asciifont' ) + tagfont_configure(tagid(tagOrId), {key=>value}) + else + tk_call 'itemconfigure', tagid(tagOrId), "-#{key}", value + end end end +# def itemconfigure(tagOrId, key, value=None) +# if key.kind_of? Hash +# tk_send 'itemconfigure', tagid(tagOrId), *hash_kv(key) +# else +# tk_send 'itemconfigure', tagid(tagOrId), "-#{key}", value +# end +# end # def itemconfigure(tagOrId, keys) # tk_send 'itemconfigure', tagid(tagOrId), *hash_kv(keys) # end @@ -258,6 +392,7 @@ end module TkcTagAccess include TkComm + include TkTreatTagFont def addtag(tag) @c.addtag(tag, 'with', @id) @@ -286,8 +421,8 @@ module TkcTagAccess # @c.itemconfigure @id, keys # end - def configinfo - @c.itemconfigure @id + def configinfo(key=nil) + @c.itemconfiginfo @id, key end def coords(*args) @@ -494,7 +629,7 @@ class TkcItem<TkObject if not parent.kind_of?(TkCanvas) fail format("%s need to be TkCanvas", parent.inspect) end - @c = parent + @parent = @c = parent @path = parent.path if args[-1].kind_of? Hash keys = args.pop @@ -502,7 +637,8 @@ class TkcItem<TkObject @id = create_self(*args).to_i ;# 'canvas item id' is integer number CItemID_TBL[@id] = self if keys - tk_call @path, 'itemconfigure', @id, *hash_kv(keys) + # tk_call @path, 'itemconfigure', @id, *hash_kv(keys) + configure(keys) if keys end end def create_self(*args); end diff --git a/lib/tkfont.rb b/lib/tkfont.rb index 5e20359523..0d926f00c8 100644 --- a/lib/tkfont.rb +++ b/lib/tkfont.rb @@ -1,3 +1,10 @@ +# +# tkfont.rb - the class to treat fonts on Ruby/Tk +# +# by Hidetoshi NAGAI ([email protected]) +# +require 'tk' + class TkFont include Tk extend TkCore @@ -14,10 +21,10 @@ class TkFont ################################### def TkFont.families(window=nil) case (Tk::TK_VERSION) - when /^4.*/ + when /^4\.*/ ['fixed'] - when /^8.*/ + when /^8\.*/ if window list(tk_call('font', 'families', '-displayof', window)) else @@ -27,21 +34,69 @@ class TkFont end def TkFont.names - r = [] case (Tk::TK_VERSION) - when /^4.*/ - r += ['fixed', 'a14', 'k14'] + when /^4\.*/ + r = ['fixed'] + r += ['a14', 'k14'] if JAPANIZED_TK Tk_FontNameTBL.each_value{|obj| r.push(obj)} - when /^8.*/ - list(tk_call('font', 'names')).each{|f| - if f =~ /^(@font[0-9]+)(c|l|k)$/ - r.push(Tk_FontNameTBL[$1]) if $2 == 'c' + r | [] + + when /^8\.*/ + list(tk_call('font', 'names')) + + end + end + + def TkFont.create_copy(font) + keys = {} + font.configure.each{|key,value| keys[key] = value } + new_font = TkFont.new(font.latin_font, font.kanji_font, keys) + end + + def TkFont.get_obj(name) + if name =~ /^(@font[0-9]+)(|c|l|k)$/ + Tk_FontNameTBL[$1] + else + nil + end + end + + def TkFont.init_widget_font(path, *args) + case (Tk::TK_VERSION) + when /^4\.*/ + conf = tk_split_list(tk_call(*args)) + ltn = conf.assoc('font')[4] + ltn = nil if ltn == [] + knj = conf.assoc('kanjifont')[4] + knj = nil if knj == [] + TkFont.new(ltn, knj).call_font_configure(path, *args) + + when /^8\.*/ + fnt = tk_split_list(tk_call(*(args + ['-font'])))[4] + if fnt == [] + TkFont.new(nil, nil).call_font_configure(path, *(args + [{}])) + else + compound = Hash[*list(tk_call('font', 'configure', + fnt))].collect{|key,value| + [key[1..-1], value] + }.assoc('compound')[1] + if compound == [] + TkFont.new(fnt, DEFAULT_KANJI_FONT_NAME) \ + .call_font_configure(path, *(args + [{}])) else - r.push(f) + TkFont.new(compound[0], compound[1]) \ + .call_font_configure(path, *(args + [{}])) end - } + end + end + end + + def TkFont.used_on(path=nil) + if path + Tk_FontUseTBL[path] + else + Tk_FontUseTBL.values | [] end - r end ################################### @@ -81,7 +136,7 @@ class TkFont pixels, points, resx, resy, space, avgWidth, charset, encoding]) end - def create_latinfont_tk4x(font=nil) + def create_latinfont_tk4x(font) if font.kind_of? Hash @latinfont = '-' + _get_font_info_from_hash(font).join('-') + '-' @@ -119,7 +174,12 @@ class TkFont end end - def create_kanjifont_tk4x(font=nil) + def create_kanjifont_tk4x(font) + unless JAPANIZED_TK + @kanjifont = "" + return + end + if font.kind_of? Hash @kanjifont = '-' + _get_font_info_from_hash(font).join('-') + '-' @@ -160,25 +220,51 @@ class TkFont end def create_compoundfont_tk4x(keys) - @compoundfont = [[@latinfont], [@kanjifont]] - @fontslot = {'font'=>@latinfont, 'kanjifont'=>@kanjifont} + if JAPANIZED_TK + @compoundfont = [[@latinfont], [@kanjifont]] + @fontslot = {'font'=>@latinfont, 'kanjifont'=>@kanjifont} + else + @compoundfont = @latinfont + @fontslot = {'font'=>@latinfont} + end end - def create_latinfont_tk80(font=nil) + def create_latinfont_tk8x(font) @latinfont = @id + 'l' - if font.kind_of? Hash - tk_call('font', 'create', @latinfont, *hash_kv(font)) - elsif font.kind_of? Array - tk_call('font', 'create', @latinfont, '-copy', array2tk_list(font)) - elsif font.kind_of? TkFont - tk_call('font', 'create', @latinfont, '-copy', font.latin_font) + if JAPANIZED_TK + if font.kind_of? Hash + tk_call('font', 'create', @latinfont, *hash_kv(font)) + elsif font.kind_of? Array + tk_call('font', 'create', @latinfont, '-copy', array2tk_list(font)) + elsif font.kind_of? TkFont + tk_call('font', 'create', @latinfont, '-copy', font.latin_font) + else + tk_call('font', 'create', @latinfont, '-copy', font) + end else - tk_call('font', 'create', @latinfont, '-copy', font) + if font.kind_of? Hash + tk_call('font', 'create', @latinfont, *hash_kv(font)) + else + keys = {} + if font.kind_of? Array + actual_core(array2tk_list(font)).each{|key,val| keys[key] = val} + elsif font.kind_of? TkFont + actual_core(font.latin_font).each{|key,val| keys[key] = val} + else + actual_core(font).each{|key,val| keys[key] = val} + end + tk_call('font', 'create', @latinfont, *hash_kv(keys)) + end end end - def create_kanjifont_tk80(font=nil) + def create_kanjifont_tk80(font) + unless JAPANIZED_TK + @kanjifont = "" + return + end + @kanjifont = @id + 'k' if font.kind_of? Hash @@ -202,20 +288,79 @@ class TkFont end end + def create_kanjifont_tk81(font) + @kanjifont = @id + 'k' + + if font.kind_of? Hash + tk_call('font', 'create', @kanjifont, *hash_kv(font)) + else + keys = {} + if font.kind_of? Array + actual_core(array2tk_list(font)).each{|key,val| keys[key] = val} + elsif font.kind_of? TkFont + actual_core(font.kanji_font).each{|key,val| keys[key] = val} + else + actual_core(font).each{|key,val| keys[key] = val} + end + tk_call('font', 'create', @kanjifont, *hash_kv(keys)) + end + + keys = {} + actual_core(@kanjifont).each{|key,val| keys[key] = val} + begin + tk_call('font', 'configure', @compoundfont, *hash_kv(keys)) + rescue + end + end + def create_compoundfont_tk80(keys) @compoundfont = @id + 'c' - @fontslot = {'font'=>@compoundfont} - tk_call('font', 'create', @compoundfont, - '-compound', "#{@latinfont} #{@kanjifont}", *hash_kv(keys)) + if JAPANIZED_TK + @fontslot = {'font'=>@compoundfont} + tk_call('font', 'create', @compoundfont, + '-compound', "#{@latinfont} #{@kanjifont}", *hash_kv(keys)) + else + tk_call('font', 'create', @compoundfont) + latinkeys = {} + begin + actual_core(@latinfont).each{|key,val| latinkeys[key] = val} + rescue + latinkeys {} + end + if latinkeys != {} + tk_call('font', 'configure', @compoundfont, *hash_kv(latinkeys)) + end + @fontslot = {'font'=>@compoundfont} + tk_call('font', 'configure', @compoundfont, *hash_kv(keys)) + end end - def set_font_core_tk4x(window) - Tk_FontUseTBL[window.path] = @id - window.configure(@fontslot) - end + def create_compoundfont_tk81(keys) + @compoundfont = @id + 'c' + tk_call('font', 'create', @compoundfont) - def set_font_core_tk80(window) - window.configure(@fontslot) + latinkeys = {} + begin + actual_core(@latinfont).each{|key,val| latinkeys[key] = val} + rescue + latinkeys {} + end + if latinkeys != {} + tk_call('font', 'configure', @compoundfont, *hash_kv(latinkeys)) + end + + kanjikeys = {} + begin + actual_core(@kanjifont).each{|key,val| kanjikeys[key] = val} + rescue + kanjikeys {} + end + if kanjikeys != {} + tk_call('font', 'configure', @compoundfont, *hash_kv(kanjikeys)) + end + + @fontslot = {'font'=>@compoundfont} + tk_call('font', 'configure', @compoundfont, *hash_kv(keys)) end def actual_core_tk4x(font, window=nil, option=nil) @@ -229,7 +374,7 @@ class TkFont end end - def actual_core_tk80(font, window=nil, option=nil) + def actual_core_tk8x(font, window=nil, option=nil) if option == 'compound' "" elsif option @@ -271,7 +416,7 @@ class TkFont end end - def configure_core_tk80(font, slot, value=None) + def configure_core_tk8x(font, slot, value=None) if slot.kind_of? Hash tk_call 'font', 'configure', font, *hash_kv(slot) else @@ -279,7 +424,7 @@ class TkFont end end - def configinfo_core_tk80(font, option=nil) + def configinfo_core_tk8x(font, option=nil) if option == 'compound' "" elsif option @@ -300,12 +445,18 @@ class TkFont def latin_replace_core_tk4x(ltn) create_latinfont_tk4x(ltn) - @compoundfont[0] = [@latinfont] + @compoundfont[0] = [@latinfont] if JAPANIZED_TK @fontslot['font'] = @latinfont - Tk_FontUseTBL.dup.each{|w, id| - if id == @id + Tk_FontUseTBL.dup.each{|w, fobj| + if self == fobj begin - w.configure('font', @latinfont) + if w.include?(';') + win, tag = w.split(';') + winobj = tk_tcl2ruby(win) + winobj.tagfont_configure(tag, {'font'=>@latinfont}) + else + tk_tcl2ruby(w).configure('font', @latinfont) + end rescue Tk_FontUseTBL[w] = nil end @@ -315,13 +466,21 @@ class TkFont end def kanji_replace_core_tk4x(knj) + return self unless JAPANIZED_TK + create_kanjifont_tk4x(knj) @compoundfont[1] = [@kanjifont] @fontslot['kanjifont'] = @kanjifont - Tk_FontUseTBL.dup.each{|w, id| - if id == @id + Tk_FontUseTBL.dup.each{|w, fobj| + if self == fobj begin - w.configure('kanjifont', @kanjifont) + if w.include?(';') + win, tag = w.split(';') + winobj = tk_tcl2ruby(win) + winobj.tagfont_configure(tag, {'kanjifont'=>@kanjifont}) + else + tk_tcl2ruby(w).configure('kanjifont', @kanjifont) + end rescue Tk_FontUseTBL[w] = nil end @@ -330,15 +489,34 @@ class TkFont self end - def latin_replace_core_tk80(ltn) + def latin_replace_core_tk8x(ltn) tk_call('font', 'delete', @latinfont) - create_latinfont_tk80(ltn) + create_latinfont(ltn) self end def kanji_replace_core_tk80(knj) + return self unless JAPANIZED_TK + tk_call('font', 'delete', @kanjifont) - create_kanjifont_tk80(knj) + create_kanjifont(knj) + self + end + + def kanji_replace_core_tk81(knj) + if font.kind_of? Hash + tk_call('font', 'configure', @compoundfont, *hash_kv(font)) + else + keys = {} + if font.kind_of? Array + actual_core(array2tk_list(font)).each{|key,val| keys[key] = val} + elsif font.kind_of? TkFont + actual_core(font.latin_font).each{|key,val| keys[key] = val} + else + actual_core(font).each{|key,val| keys[key] = val} + end + tk_call('font', 'configure', @compoundfont, *hash_kv(keys)) + end self end @@ -346,7 +524,7 @@ class TkFont 0 end - def measure_core_tk80(window, text) + def measure_core_tk8x(window, text) if window number(tk_call('font', 'measure', @compoundfont, '-displayof', window, text)) @@ -364,7 +542,7 @@ class TkFont end end - def metrics_core_tk80(font, window, option=nil) + def metrics_core_tk8x(font, window, option=nil) if option if window number(tk_call('font', 'metrics', font, "-#{option}")) @@ -390,11 +568,10 @@ class TkFont # private alias ################################### case (Tk::TK_VERSION) - when /^4.*/ + when /^4\.*/ alias create_latinfont create_latinfont_tk4x alias create_kanjifont create_kanjifont_tk4x alias create_compoundfont create_compoundfont_tk4x - alias set_font_core set_font_core_tk4x alias actual_core actual_core_tk4x alias configure_core configure_core_tk4x alias configinfo_core configinfo_core_tk4x @@ -404,25 +581,77 @@ class TkFont alias metrics_core metrics_core_tk4x when /^8\.0/ - alias create_latinfont create_latinfont_tk80 + alias create_latinfont create_latinfont_tk8x alias create_kanjifont create_kanjifont_tk80 alias create_compoundfont create_compoundfont_tk80 - alias set_font_core set_font_core_tk80 - alias actual_core actual_core_tk80 - alias configure_core configure_core_tk80 - alias configinfo_core configinfo_core_tk80 - alias latin_replace_core latin_replace_core_tk80 + alias actual_core actual_core_tk8x + alias configure_core configure_core_tk8x + alias configinfo_core configinfo_core_tk8x + alias latin_replace_core latin_replace_core_tk8x alias kanji_replace_core kanji_replace_core_tk80 - alias measure_core measure_core_tk80 - alias metrics_core metrics_core_tk80 + alias measure_core measure_core_tk8x + alias metrics_core metrics_core_tk8x + + when /^8\.1/ + alias create_latinfont create_latinfont_tk8x + alias create_kanjifont create_kanjifont_tk81 + alias create_compoundfont create_compoundfont_tk81 + alias actual_core actual_core_tk8x + alias configure_core configure_core_tk8x + alias configinfo_core configinfo_core_tk8x + alias latin_replace_core latin_replace_core_tk8x + alias kanji_replace_core kanji_replace_core_tk81 + alias measure_core measure_core_tk8x + alias metrics_core metrics_core_tk8x end ################################### public ################################### - def set_font(window) - set_font_core(window) + def call_font_configure(path, *args) + args += hash_kv(args.pop.update(@fontslot)) + tk_call *args + Tk_FontUseTBL[path] = self + self + end + + def used + ret = [] + Tk_FontUseTBL.each{|key,value| + if key.include?(';') + win, tag = key.split(';') + winobj = tk_tcl2ruby(win) + if winobj.kind_of? TkText + ret.push([winobj, winobj.tagid2obj(tag)]) + elsif winobj.kind_of? TkCanvas + if (tagobj = TkcTag.id2obj(tag)).kind_of? TkcTag + ret.push([winobj, tagobj]) + elsif (tagobj = TkcItem.id2obj(tag)).kind_of? TkcItem + ret.push([winobj, tagobj]) + else + ret.push([winobj, tag]) + end + else + ret.push([win, tag]) + end + else + ret.push(tk_tcl2ruby(key)) if value == self + end + } + ret + end + + def id + @id + end + + def to_eval + font + end + + def font + @compoundfont end def latin_font @@ -452,12 +681,22 @@ class TkFont end def kanji_actual(option=nil) - actual_core(@kanjifont, nil, option) + #if JAPANIZED_TK + if @kanjifont != "" + actual_core(@kanjifont, nil, option) + else + actual_core_tk4x(nil, nil, option) + end end def kanji_actual_displayof(window, option=nil) - window = '.' unless window - actual_core(@kanjifont, window, option) + #if JAPANIZED_TK + if @kanjifont != "" + window = '.' unless window + actual_core(@kanjifont, window, option) + else + actual_core_tk4x(nil, window, option) + end end def [](slot) @@ -477,24 +716,45 @@ class TkFont end def latin_configure(slot, value=None) - configure_core(@latinfont, slot, value) + if JAPANIZED_TK + configure_core(@latinfont, slot, value) + else + configure(slot, value) + end end def latin_configinfo(slot=nil) - configinfo_core(@latinfont, slot) + if JAPANIZED_TK + configinfo_core(@latinfont, slot) + else + configure(slot, value) + end end def kanji_configure(slot, value=None) - configure_core(@kanjifont, slot, value) + #if JAPANIZED_TK + if @kanjifont != "" + configure_core(@kanjifont, slot, value) + else + #"" + configure(slot, value) + end end def kanji_configinfo(slot=nil) - configinfo_core(@kanjifont, slot) + #if JAPANIZED_TK + if @kanjifont != "" + configinfo_core(@kanjifont, slot) + else + #[] + configinfo(slot) + end end def replace(ltn, knj) latin_replace(ltn) - kanji_replace(ltn) + kanji_replace(knj) + self end def latin_replace(ltn) @@ -533,12 +793,20 @@ class TkFont end def kanji_metrics(option=nil) - metrics_core(@kanjifont, nil, option) + if JAPANIZED_TK + metrics_core(@kanjifont, nil, option) + else + metrics_core_tk4x(nil, nil, option) + end end def kanji_metrics_displayof(window, option=nil) - window = '.' unless window - metrics_core(@kanjifont, window, option) + if JAPANIZED_TK + window = '.' unless window + metrics_core(@kanjifont, window, option) + else + metrics_core_tk4x(nil, window, option) + end end ################################### @@ -554,3 +822,36 @@ class TkFont alias ascii_metrics latin_metrics end + +module TkTreatTagFont + def font_configinfo + @parent.tagfont_configinfo(@id) + end + alias font font_configinfo + + def font_configure(slot) + @parent.tagfont_configure(@id, slot) + end + + def latinfont_configure(ltn, keys=nil) + @parent.latintagfont_configure(@id, ltn, keys) + end + alias asciifont_configure latinfont_configure + + def kanjifont_configure(knj, keys=nil) + @parent.kanjitagfont_configure(@id, ltn, keys) + end + + def font_copy(window, wintag=nil) + @parent.tagfont_copy(@id, window, wintag) + end + + def latinfont_copy(window, wintag=nil) + @parent.latintagfont_copy(@id, window, wintag) + end + alias asciifont_copy latinfont_copy + + def kanjifont_copy(window, wintag=nil) + @parent.kanjitagfont_copy(@id, window, wintag) + end +end diff --git a/lib/tktext.rb b/lib/tktext.rb index 7b5cea5c72..8ffc626046 100644 --- a/lib/tktext.rb +++ b/lib/tktext.rb @@ -4,8 +4,124 @@ # by Yukihiro Matsumoto <[email protected]> require 'tk.rb' +require 'tkfont' + +module TkTreatTextTagFont + def tagfont_configinfo(tag) + if tag.kind_of? TkTextTag + pathname = self.path + ';' + tag.id + else + pathname = self.path + ';' + tag + end + ret = TkFont.used_on(pathname) + if ret == nil + ret = TkFont.init_widget_font(pathname, + self.path, 'tag', 'configure', tag) + end + ret + end + alias tagfontobj tagfont_configinfo + + def tagfont_configure(tag, slot) + if tag.kind_of? TkTextTag + pathname = self.path + ';' + tag.id + else + pathname = self.path + ';' + tag + end + if (fnt = slot['font']) + slot['font'] = nil + if fnt.kind_of? TkFont + return fnt.call_font_configure(pathname, + self.path,'tag','configure',tag,slot) + else + latintagfont_configure(tag, fnt) if fnt + end + end + if (ltn = slot['latinfont']) + slot['latinfont'] = nil + latintagfont_configure(tag, ltn) if ltn + end + if (ltn = slot['asciifont']) + slot['asciifont'] = nil + latintagfont_configure(tag, ltn) if ltn + end + if (knj = slot['kanjifont']) + slot['kanjifont'] = nil + kanjitagfont_configure(tag, knj) if knj + end + + tk_call(self.path, 'tag', 'configure', tag, *hash_kv(slot)) if slot != {} + self + end + + def latintagfont_configure(tag, ltn, keys=nil) + fobj = tagfontobj(tag) + if ltn.kind_of? TkFont + conf = {} + ltn.latin_configinfo.each{|key,val| conf[key] = val} + if keys + fobj.latin_configure(conf.update(keys)) + else + fobj.latin_configure(conf) + end + else + fobj.latin_replace(ltn) + end + end + alias asciitagfont_configure latintagfont_configure + + def kanjitagfont_configure(tag, knj, keys=nil) + fobj = tagfontobj(tag) + if knj.kind_of? TkFont + conf = {} + knj.kanji_configinfo.each{|key,val| conf[key] = val} + if keys + fobj.kanji_configure(conf.update(keys)) + else + fobj.kanji_configure(conf) + end + else + fobj.kanji_replace(knj) + end + end + + def tagfont_copy(tag, window, wintag=nil) + if wintag + window.tagfontobj(wintag).configinfo.each{|key,value| + tagfontobj(tag).configure(key,value) + } + tagfontobj(tag).replace(window.tagfontobj(wintag).latin_font, + window.tagfontobj(wintag).kanji_font) + else + window.tagfont(tag).configinfo.each{|key,value| + tagfontobj(tag).configure(key,value) + } + tagfontobj(tag).replace(window.fontobj.latin_font, + window.fontobj.kanji_font) + end + end + + def latintagfont_copy(tag, window, wintag=nil) + if wintag + tagfontobj(tag).latin_replace(window.tagfontobj(wintag).latin_font) + else + tagfontobj(tag).latin_replace(window.fontobj.latin_font) + end + end + alias asciitagfont_copy latintagfont_copy + + def kanjitagfont_copy(tag, window, wintag=nil) + if wintag + tagfontobj(tag).kanji_replace(window.tagfontobj(wintag).kanji_font) + else + tagfontobj(tag).kanji_replace(window.fontobj.kanji_font) + end + end +end class TkText<TkTextWin + include TkTreatTextTagFont + WidgetClassName = 'Text'.freeze TkClassBind::WidgetClassNameTBL[WidgetClassName] = self def self.to_eval @@ -32,31 +148,28 @@ class TkText<TkTextWin def _addtag(name, obj) @tags[name] = obj end + + def tagid2obj(tagid) + if not @tags[tagid] + tagid + else + @tags[tagid] + end + end + def tag_names(index=None) tk_split_list(tk_send('tag', 'names', index)).collect{|elt| - if not @tags[elt] - elt - else - @tags[elt] - end + tagid2obj(elt) } end def window_names tk_send('window', 'names').collect{|elt| - if not @tags[elt] - elt - else - @tags[elt] - end + tagid2obj(elt) } end def image_names tk_send('image', 'names').collect{|elt| - if not @tags[elt] - elt - else - @tags[elt] - end + tagid2obj(elt) } end @@ -158,13 +271,24 @@ class TkText<TkTextWin def tag_configure(tag, key, val=None) if key.kind_of? Hash - tk_send 'tag', 'configure', tag, *hash_kv(key) + if ( key['font'] || key['kanjifont'] \ + || key['latinfont'] || key['asciifont'] ) + tagfont_configure(tag, key.dup) + else + tk_send 'tag', 'configure', tag, *hash_kv(key) + end + else - tk_send 'tag', 'configure', tag, "-#{key}", val + if ( key == 'font' || key == 'kanjifont' \ + || key == 'latinfont' || key == 'asciifont' ) + tagfont_configure({key=>val}) + else + tk_call 'tag', 'configure', tag, "-#{key}", val + end end end - def configinfo(tag, key=nil) + def tag_configinfo(tag, key=nil) if key conf = tk_split_list(tk_send('tag','configure',tag,"-#{key}")) conf[0] = conf[0][1..-1] @@ -296,21 +420,32 @@ class TkText<TkTextWin end class TkTextTag<TkObject + include TkTreatTagFont + $tk_text_tag = 'tag0000' def initialize(parent, keys=nil) if not parent.kind_of?(TkText) fail format("%s need to be TkText", parent.inspect) end - @t = parent + @parent = @t = parent @path = @id = $tk_text_tag $tk_text_tag = $tk_text_tag.succ - tk_call @t.path, "tag", "configure", @id, *hash_kv(keys) + #tk_call @t.path, "tag", "configure", @id, *hash_kv(keys) + configure(keys) if keys @t._addtag id, self end def id return @id end + def first + @id + '.first' + end + + def last + @id + '.last' + end + def add(*index) tk_call @t.path, 'tag', 'add', @id, *index end @@ -349,12 +484,15 @@ class TkTextTag<TkObject end def configure(key, val=None) - if key.kind_of? Hash - tk_call @t.path, 'tag', 'configure', @id, *hash_kv(key) - else - tk_call @t.path, 'tag', 'configure', @id, "-#{key}", val - end + @t.tag_configure @id, key, val end +# def configure(key, val=None) +# if key.kind_of? Hash +# tk_call @t.path, 'tag', 'configure', @id, *hash_kv(key) +# else +# tk_call @t.path, 'tag', 'configure', @id, "-#{key}", val +# end +# end # def configure(key, value) # if value == FALSE # value = "0" @@ -365,17 +503,20 @@ class TkTextTag<TkObject # end def configinfo(key=nil) - if key - conf = tk_split_list(tk_call(@t.path, 'tag','configure',@id,"-#{key}")) - conf[0] = conf[0][1..-1] - conf - else - tk_split_list(tk_call(@t.path, 'tag', 'configure', @id)).collect{|conf| - conf[0] = conf[0][1..-1] - conf - } - end - end + @t.tag_configinfo @id, key + end +# def configinfo(key=nil) +# if key +# conf = tk_split_list(tk_call(@t.path, 'tag','configure',@id,"-#{key}")) +# conf[0] = conf[0][1..-1] +# conf +# else +# tk_split_list(tk_call(@t.path, 'tag', 'configure', @id)).collect{|conf| +# conf[0] = conf[0][1..-1] +# conf +# } +# end +# end def bind(seq, cmd=Proc.new, args=nil) id = install_bind(cmd, args) @@ -420,7 +561,8 @@ class TkTextTagSel<TkTextTag end @t = parent @path = @id = 'sel' - tk_call @t.path, "tag", "configure", @id, *hash_kv(keys) + #tk_call @t.path, "tag", "configure", @id, *hash_kv(keys) + configure(keys) if keys @t._addtag id, self end end diff --git a/lib/weakref.rb b/lib/weakref.rb index 539bb9336c..c31e959e74 100644 --- a/lib/weakref.rb +++ b/lib/weakref.rb @@ -32,10 +32,10 @@ class WeakRef<Delegator def initialize(orig) super - @__id = orig.id + @__id = orig.__id__ ObjectSpace.call_finalizer orig ObjectSpace.call_finalizer self - ID_MAP[@__id] = self.id + ID_MAP[@__id] = self.__id__ ID_REV_MAP[self.id] = @__id end @@ -1094,12 +1094,13 @@ static VALUE fix_lshift(x, y) VALUE x, y; { - long val, width; + long val; + int width; val = NUM2LONG(x); - width = NUM2LONG(y); + width = NUM2INT(y); if (width > (sizeof(VALUE)*CHAR_BIT-1) - || (unsigned long)val>>(sizeof(VALUE)*CHAR_BIT-1-width) > 0) { + || ((unsigned long)val)>>(sizeof(VALUE)*CHAR_BIT-1-width) > 0) { return big_lshift(int2big(val), y); } val = val << width; @@ -3436,7 +3436,7 @@ gettable(id) return NEW_LIT(INT2FIX(sourceline)); } else if (is_local_id(id)) { - if (dyna_var_defined(id)) return NEW_DVAR(id); + if (dyna_in_block() && dyna_var_defined(id)) return NEW_DVAR(id); if (local_id(id)) return NEW_LVAR(id); /* method call without arguments */ return NEW_VCALL(id); diff --git a/sample/ruby-mode.el b/sample/ruby-mode.el index bfecb51214..94ac7d1799 100644 --- a/sample/ruby-mode.el +++ b/sample/ruby-mode.el @@ -47,8 +47,11 @@ ruby-block-end-re "\\)\\>\\|\\}\\|\\]\\)") ) -(defconst ruby-operator-chars "[,.+*/%-&|^~=<>:]") -(defconst ruby-symbol-chars "[a-zA-Z0-9_]") +(defconst ruby-operator-chars ",.+*/%-&|^~=<>:") +(defconst ruby-operator-re (concat "[" ruby-operator-chars "]")) + +(defconst ruby-symbol-chars "a-zA-Z0-9_") +(defconst ruby-symbol-re (concat "[" ruby-symbol-chars "]")) (defvar ruby-mode-abbrev-table nil "Abbrev table in use in ruby-mode buffers.") @@ -184,34 +187,29 @@ The variable ruby-indent-level controls the amount of indentation. (indent-to x) (move-to-column (+ x shift)))))) -(defun ruby-expr-beg (&optional modifier) +(defun ruby-expr-beg (&optional modifier pnt) (save-excursion (if (looking-at "\\?") (progn (or (bolp) (forward-char -1)) (not (looking-at "\\sw"))) + (store-match-data nil) (skip-chars-backward " \t") (or (bolp) (forward-char -1)) - (or (looking-at ruby-operator-chars) + (or (bolp) + (looking-at ruby-operator-re) (looking-at "[\\[({]") (and (not modifier) (looking-at "[!?]")) - (bolp) - (and (looking-at ruby-symbol-chars) + (and (looking-at ruby-symbol-re) (forward-word -1) - (or - (and (not modifier) (bolp)) - (looking-at ruby-block-beg-re) - (looking-at ruby-block-op-re) - (looking-at ruby-block-mid-re) - (and modifier - (save-excursion - (forward-char -1) - (let ((c (char-after (point)))) - (or (eq c ?.) - (eq c ? ) - (eq c ?\t)))))) - (goto-char (match-end 0)) - (looking-at "[^_]")))))) + (if (and (not modifier) (bolp)) + t + (if (or (looking-at ruby-block-beg-re) + (looking-at ruby-block-op-re) + (looking-at ruby-block-mid-re)) + (progn + (goto-char (match-end 0)) + (looking-at "[^_]"))))))))) (defun ruby-parse-region (start end) (let ((indent-point end) @@ -468,13 +466,13 @@ The variable ruby-indent-level controls the amount of indentation. (skip-chars-backward " \t") (or (bobp) (forward-char -1)) (and - (or (and (looking-at ruby-symbol-chars) + (or (and (looking-at ruby-symbol-re) (skip-chars-backward ruby-symbol-chars) (looking-at ruby-block-op-re) (save-excursion (goto-char (match-end 0)) (not (looking-at "[a-z_]")))) - (and (looking-at ruby-operator-chars) + (and (looking-at ruby-operator-re) (or (not (or (eq ?/ (char-after (point))))) (null (nth 0 (ruby-parse-region parse-start (point))))) (not (eq (char-after (1- (point))) ?$)) @@ -612,9 +612,6 @@ fmt_setup(buf, c, flags, width, prec) int flags, width, prec; { *buf++ = '%'; - if (strchr("doOXx", c)) { - *buf++ = 'l'; - } if (flags & FSHARP) *buf++ = '#'; if (flags & FPLUS) *buf++ = '+'; if (flags & FMINUS) *buf++ = '-'; @@ -630,6 +627,9 @@ fmt_setup(buf, c, flags, width, prec) buf += strlen(buf); } + if (strchr("doOXx", c)) { + *buf++ = 'l'; + } *buf++ = c; *buf = '\0'; } diff --git a/variable.c b/variable.c index 7a827ed88b..c05853899e 100644 --- a/variable.c +++ b/variable.c @@ -650,7 +650,7 @@ rb_gvar_defined(entry) } static int -var_i(key, entry, ary) +gvar_i(key, entry, ary) ID key; struct global_entry *entry; VALUE ary; @@ -666,7 +666,7 @@ f_global_variables() char buf[4]; char *s = "&`'+123456789"; - st_foreach(global_tbl, var_i, ary); + st_foreach(global_tbl, gvar_i, ary); if (!NIL_P(backref_get())) { while (*s) { sprintf(buf, "$%c", *s++); @@ -757,6 +757,18 @@ rb_ivar_defined(obj, id) return FALSE; } +static int +ivar_i(key, entry, ary) + ID key; + struct global_entry *entry; + VALUE ary; +{ + if (rb_is_instance_id(key)) { + ary_push(ary, str_new2(rb_id2name(key))); + } + return ST_CONTINUE; +} + VALUE obj_instance_variables(obj) VALUE obj; @@ -769,7 +781,7 @@ obj_instance_variables(obj) case T_MODULE: ary = ary_new(); if (ROBJECT(obj)->iv_tbl) { - st_foreach(ROBJECT(obj)->iv_tbl, var_i, ary); + st_foreach(ROBJECT(obj)->iv_tbl, ivar_i, ary); } return ary; } @@ -1,2 +1,2 @@ -#define RUBY_VERSION "1.1b9_30" -#define VERSION_DATE "98/07/09" +#define RUBY_VERSION "1.1b9_31" +#define VERSION_DATE "98/07/15" |