Split out editor finding from `Base.edit` so can be reused in `Pkg.edit`

`Base.edit` directly sometimes spawns so isn't suitable for use in
`Pkg.edit` which needs to wait for the edit to complete.