Skip to content

Free-form selection

(:span) selects the literal source code of a statement and has the following signature:

clojure
(:span [pattern])

Being thorough

Say you're refactoring part of an application that had a model named "Group" and now you want it to be called "Category" instead. You've already done the work, perhaps using SYNG to guide you to the individual statement types throughout the process, but now you want to verify you didn't miss anything:

clojure
(:span /group/i)

(:span) in its greediness is ideal for such a task because it would catch things you might not have specifically looked for -- things that would otherwise be harmless except for the unwary onlooker who'll be maintaining the code long after you left and has no idea that "group" used to be a "category".

Constructs that are not part of your API could be one example of this, like a bound argument name:

javascript
export const getCategoryById = groupId => { }
                            /* ^^^^^^^ */

Note how we did rename the exported function (that is part of our API) but not the argument, which is binding to a local identifier and can be easily missed.

(:span) can get very noisy, so you probably want to confine this stage of the search to the specific files you're working with, to minimize that noise.

Selecting destructuring patterns

(:span) can be ideal for finding an identifier in a [destructuring] pattern where you might not know - or care - what its structure looks like; whether it's destructuring an object or an array, or at what depth that identified is being destructured:

clojure
(var (:span /count/))
javascript
var {
  a: {
    b: [{
      count
   /* ^^^^^ */
    }]
  }
} = x

Copyright © 2022-present Semantic Works, Inc.