Best practice for renaming glyphs thoroughly?

(Mmm have been searching for relevant discussions and existing solutions but haven’t found any informative ones so far. Please redirect me to one if you know any of them.)

What’s the best practice if I want to change a glyph’s name and make sure all of the references to this glyph are updated? Some are updated automatically (e.g., GSEditViewController.text—are they?), but some need manual updating (e.g., component references and OTL feature rules). I thought Rainer’s Rename Glyphs script would offer a solution but seems its ability is more or less on the same level of the built-in “Find and replace in Glyph Name”…

A quick-n-dirty script would look like this:

OLD_TO_NEW_NAME = {"foo": "bar"}

def update_name(obj, attributes):
    for a in attributes:
        old_name = getattr(obj, a)
        new_name = OLD_TO_NEW_NAME.get(old_name, old_name)
        if new_name != old_name:
            setattr(obj, a, new_name)

f = Glyphs.font
f.disableUpdateInterface()

for g in f.glyphs[:]:
    update_name(g, [
        "name",
        "leftKerningGroup", "rightKerningGroup",
        "leftMetricsKey", "rightMetricsKey", "widthMetricsKey",
    ])
    for l in g.layers:
        update_name(l, [
            "leftMetricsKey", "rightMetricsKey", "widthMetricsKey",
        ])
        for c in l.components:
            update_name(c, ["name"])

for g in f.glyphs:
    for l in g.layers:
        l.syncMetrics()

f.enableUpdateInterface()

Besides some treatments should be done for the cases where a glyph’s new name happens to be another existing glyph’s name, I can tell there are at least the following not covered: vertical kerning groups and vertical metrics keys of glyphs and layers, GSFont.features, and GSFont.kerning. What else should be considered? Ah, probably also glyph names mentioned in certain custom parameters?

Components update automatically. Automatic feature code sometimes needs a button push, most of the time it updates automatically itself as well.

Only manual feature code should need manual updating.

Yeah I see the automatic updating in a newly created “New Font” file, however many of my files don’t do automatic updating of component references. Will try to construct a minimal test case.

The metrics keys are not yet automatically updated though, right? (I understand the kerning groups do not need to be consistent with a member’s glyph name.)

Which app version are you using? It has always worked for me without a hitch.

Mmm it failed too frequently that in my memory it probably never worked for me… This time I was using the latest stable, 2.6.4 (1286). But just tested the latest cutting edge, 2.6.5 (1312), and it was the same.

Couldn’t quickly construct a minimal test file in which the problem is reproducible. So I’m sending you the original project file in DM…

The glyphs have to be rendered at least once so that the components are properly loaded to be able to keep the connection with the right glyph. It is supposed to do that on opening the file for all glyphs. I’ll have a look.

Ah! That was indeed unexpected… Thanks for clarifying.

I would LOVE a quick, easy and secure way to rename a glyphs throughout a glyphs file, as I need this frequently and it costs so much time and it is quite prone to errors.

I often open the .glyphs file in a text editor and do a search-and-replace there.

That’s a safe way to rename a glyph entirely – if the old name (as a string) does not exist elsewhere in the font. So, make sure there is no glyph (or anything else in the file) that contains the old name as a substring because that might mess up things quite a bit. But usually, that case can be quite safely ruled out. You can still step through the search-and-replace if you are unsure. Plus, keep a back-up of the file, of course.