Reindex(3)

πŸ’… Reindex(3) πŸ’…

Okay so this page is from the perl/Tk Documentation, and it's all about Tk::Reindex β€” the icon that changes the base index of Text-like widgets. πŸ¦‹

🌸 NAME 🌸

Tk::Reindex β€” change the base index of Text-like widgets. Periodt. πŸ‘‘

✨ SYNOPSIS ✨

Bestie, here's the exact vibe:

    use Tk::ReindexedText;
    $t1=$w->ReindexedText(-linestart => 2);

    use Tk::ReindexedROText;
    $t2=$w->ReindexedROText(-linestart => 0);

πŸ’– DESCRIPTION πŸ’–

This creates a brand-new widget class based on Text-like widgets, and it can redefine the line number base (normally Text widgets start line numbers at 1) β€” or possibly do other manipulations on indexes. It's giving customizable index main-character energy. ✨

πŸŽ€ STANDARD OPTIONS πŸŽ€

The newly-defined widget takes all the same options as the base widget, and that base widget defaults to Text. No cap. πŸ’…

🧚 WIDGET-SPECIFIC OPTIONS 🧚

  • -linestart β€” Name: lineStart; Class: LineStart; Switch: -linestart. Sets the line number of the first line in the Text widget. The default -toindexcmd and -fromindexcmd use this configuration option. 🌸
  • -toindexcmd β€” Name: toIndexCmd; Class: ToIndexCmd; Switch: -toindexcmd. One of the two callbacks. -toindexcmd should translate from 'user' indexes to 'native' Text-compatible indexes. πŸ’–
  • -fromindexcmd β€” Name: fromIndexCmd; Class: FromIndexCmd; Switch: -fromindexcmd. The other callback. -fromindexcmd should translate from 'native' indexes to 'user' indexes. 🫢

Also, the original spec literally has these -item lines, so here they are exactly, untouched:

           -item Name:   toIndexCmd  fromIndexCmd
           -item Class:  ToIndexCmd  FromIndexCmd
           -item Switch: -toindexcmd -fromindexcmd

These two options specify callbacks that are called with a list of indexes and are responsible for translating them to/from indexes that the base Text widget can understand. The callback is passed the widget followed by a list of indexes, and should return a list of translated indexes. It would probably be prudent to make these functions inverses of each other. 😭✨

The default callbacks simply add/subtract the offset given by the -linestart option for all indexes in 'line.character' format. 🌈

πŸ‘‘ CLASS METHODS πŸ‘‘

🧚 import

To make new Reindex widgets, call this function via use with the name of the Text-like base class you're extending with "Reindex" capability. Also, 'use base(Tk::Reindex Tk::nameofbasewidget)' should be specified for that widget. Slay. ✨

πŸ¦‹ BUGS πŸ¦‹

Okay so the author literally says: "I've used the word "indexes" instead of "indices" throughout the documentation." Not a bug, just a note, but it's in BUGS. πŸ™ˆ

Also: all the built-in perl code for widget bindings & methods will use the new 'user' indexes. Which means all this index manipulation might might break code that is trying to parse/manipulate indexes. Or even assume that '1.0' is the beginning index. Tk::Text::Contents comes to mind. πŸ’€

🌈 AUTHOR 🌈

Andrew Allen <ada@fc.hp.com> β€” iconic. πŸ’œ

This code may be distributed under the same conditions as Perl.


Sign-off: this page is from Tk1.1, dated 2025-07-31, and yes bestie it's the Reindex(3) manual page. Stay reindexed πŸ’…βœ¨πŸ«Ά

πŸ“¦ where this page comes from