# How do I customize 'word ends' for TextView / add underscore to selection for double click?

**URL:** <https://www.ruby-forum.com/t/how-do-i-customize-word-ends-for-textview-add-underscore-to-selection-for-double-click/165592>\
**Category:** Ruby-Gnome 2\
**Created:** [April 15, 2009, 3:50pm UTC](https://www.ruby-forum.com/t/how-do-i-customize-word-ends-for-textview-add-underscore-to-selection-for-double-click/165592 "2009-04-15T15:50:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![chaschev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/cab0a1/32.png) [@chaschev](https://www.ruby-forum.com/u/chaschev)\
**Post date:** [April 15, 2009, 3:50pm UTC](https://www.ruby-forum.com/t/how-do-i-customize-word-ends-for-textview-add-underscore-to-selection-for-double-click/165592/1 "2009-04-15T15:50:02Z")

</div>

Hi,

I tried doing it with the code below and for the example from the  
distribution (pango/samples/break.rb) it worked: underscore  
was then similar to an ordinary letter. I mean word\_end for  
underscore became true. But this doesn’t work when I’m trying  
to double-click a word with an underscore - it always selects a  
part to the left or to the right of it. Any help is appreciated.

module Pango  
alias :super\_break :break  
module\_function :super\_break

```
def self.break s, analysis
  #puts "intercepted"
  r = super_break s, analysis
  # TODO: fix for ruby 1.9
  #puts s
  chars = s.unpack("U*")
  for i in 0...chars.length
    c = chars[i]
    #print c.chr
    r[i].word_end = false if c == 95 # _
  end
  r
end

```

end

Thanks,  
A.

---

<div class="post-metadata">

**Author:** ![chaschev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/cab0a1/32.png) [@chaschev](https://www.ruby-forum.com/u/chaschev)\
**Post date:** [April 17, 2009, 12:35pm UTC](https://www.ruby-forum.com/t/how-do-i-customize-word-ends-for-textview-add-underscore-to-selection-for-double-click/165592/2 "2009-04-17T12:35:40Z")

</div>

Your snippet works for Ruby code but won’t affect other Gtk widgets  
that depend on the C version of Pango, like GtkTextBuffer.

I too would love to know how to customize this kind of thing in Pango,  
but I’m not sure if it’s possible, based on my Google searchigns.  
Perhaps there is a Pango mailing list or irc channel we could ask in?

Please post back here if you do find a solution.

best,  
Dan

* * *

Daniel Benjamin Lucraft

[www.daniellucraft.com/blog](http://www.daniellucraft.com/blog)  
[twitter.com/danlucraft](http://twitter.com/danlucraft)

2009/4/15 Andrey C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
