Skip to content
This repository has been archived by the owner on Apr 6, 2018. It is now read-only.

Implement gf (goto file) #727

Closed
wants to merge 3 commits into from

Conversation

irrationalistic
Copy link

This implements the gf keybinding which will allow the editor to open the file or url under the cursor. It supports absolute file paths, relative file paths, and even paths without an extension. If no extension is found, but multiple files are found with the same name (i.e. main.js or main.coffee), it will look to the currently loaded file for advice on the extension to use.

I've run into an issue where I can't seem to get tests to work properly. The situation is that in order for relative paths to work, there needs to be an actual file (from the file system) loaded into the editor. Any suggestions on how to get that working? I'd also need to be able to test that once the command is entered new files open as well.

@masukomi
Copy link

Can't comment on the testing but the PR could be improved by rebasing all the commits into 1. Or maybe 2: one for the initial implementation, and one for implementing multiple file selections.

@bronson
Copy link
Contributor

bronson commented Jul 2, 2015

Hi, looks good.

Any chance of reusing getCurrentWord instead of re-implementing it here?

That might require some refactoring... but it might be worth it since Vim seems to need the current word quite a bit.

@irrationalistic
Copy link
Author

I imagine that would be doable. Probably move it into a base class or utilities somewhere? I'll take a look.

@irrationalistic
Copy link
Author

I've refactored it into the utils file. It can be used from any component now and supports any cursor(s) and word regular expressions!

@bronson
Copy link
Contributor

bronson commented Jul 3, 2015

Looks excellent!! Now it just needs some testing. :)

I can try to help with that if you want. Got a few things I need to tie down first though.

@irrationalistic
Copy link
Author

That'd be awesome, thanks! I tried to get some stuff working, but no go. The problem is that it needs to have an actual file loaded since the relative path testing needs to be relative to the loaded file. Any thoughts you have would be great!

# range = cursor.getCurrentWordBufferRange wordRegex: wordRegex
# selectedPath = @editor.getTextInRange range
range = currentWord.range
selectedPath = currentWord.word
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would {range, selectedPath} = utils.getCurrentWord(...) work?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to be able to use selectedPath, but keep the getCurrentWord method as generic as possible, so i'd end up with an extra declaration anyways or I'd have to use word in the remaining code! Does that make sense?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oop, you're right. renaming word to selectedPath takes another line anyway so this change wouldn't buy much. Never mind!

@t9md
Copy link
Contributor

t9md commented Jul 20, 2015

Fore reference, I also implemented similar feature with open-this, the diff of this PR is.

  1. Try every possible ext name using grammar's FileTypes array(it include ext name list per language).
  2. Try to open the file with same base name if it can't find appropriate file in 1.

https://github.com/t9md/atom-open-this/blob/master/lib/main.coffee#L18-L24

And not include opening URL.

@lee-dohm
Copy link
Contributor

lee-dohm commented Apr 5, 2018

As stated in the README, this package is no longer maintained and is deprecated. We recommend that people use the vim-mode-plus package instead. Because of this, we are archiving this repository and closing all issues and pull requests. Thanks very much for your support and contributions!

@lee-dohm lee-dohm closed this Apr 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants