Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some changes to make it work like Emacs vertical file completion. #185

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AdvancedNewFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

# Make sure all dependencies are reloaded on upgrade
if reloader in sys.modules:
reload(sys.modules[reloader])
reload(sys.modules[reloader]) # type: ignore

if VERSION > 3000:
from .advanced_new_file import reloader
Expand Down
15 changes: 11 additions & 4 deletions AdvancedNewFile.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
// A default initial value to fill the create new file input path with.
"default_initial": "",

// When renaming a file it will we pre populated with the file existing filename.
"autofill_path_the_existing": false,
Copy link
Member

Choose a reason for hiding this comment

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

At first I questioned why the setting was removed, but in hindsight it never made it into a release (a5f062b), the name is questionable, I'm not sure if the code even works, and the behavior is somewhat as well, though I can see the appeal. Regardless, the opposite should have been the default.

A mention of that in the commit message (and having it in a separate comment) would have been nice, though.


// A boolean defining if cursor text should be used. Text bound by single or
// double quotes or within a region will be used. If multiple cursors
// are used, the earliest selection containing a region or existing
Expand Down Expand Up @@ -182,5 +179,15 @@
"empty_filename_action": false,

// When specifying initial input, this boolean will place the cursor prior to the .<content>
"cursor_before_extension": false
"cursor_before_extension": false,

// Ignore regex patterns
"filter_regex": ["\\.DS_Store", "\\.git"],

// Use Chinese Pinyin to filter candidate in completion list
"use_pinyin_to_filter": false,

// miliseconds to delay when input char to complete.
// This only work for project file, because some projects maybe very large.
"completion_after_milliseconds": 100
}
17 changes: 16 additions & 1 deletion Default (Linux).sublime-keymap
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,20 @@
"context": [{
"key": "setting.anf_panel"
}]
}
},
{"keys": ["ctrl+n"],"command": "advanced_new_file_next",
"context": [{"key": "setting.anf_panel"}]
},
{"keys": ["ctrl+p"],"command": "advanced_new_file_prev",
"context": [{"key": "setting.anf_panel"}]
},
{"keys": ["ctrl+l"],"command": "advanced_new_file_updir",
Copy link
Member

@FichteFoll FichteFoll Jun 11, 2022

Choose a reason for hiding this comment

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

Why L? Is that how emacs does it? Please add some comments above the binding to explain their inspiration because I (for example) wouldn't know otherwise. Probably to the readme as well.

"context": [{"key": "setting.anf_panel"}]
},
{"keys": ["enter"],"command": "advanced_new_file_confirm",
"context": [{"key": "setting.anf_panel"}]
},
Comment on lines +21 to +23
Copy link
Member

Choose a reason for hiding this comment

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

Will this prevent submitting the inserted new file name when the completion list is not visible? It would also not match the native completions UX if "auto_complete_commit_on_tab": true.

{"keys": ["ctrl+j"],"command": "insert", "args": {"characters": "\t"},
Copy link
Member

Choose a reason for hiding this comment

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

I suppose this is how tab completion works currently, but I find that questionable when you could instead bind the tab key to a proper command instead.

"context": [{"key": "setting.anf_panel"}]
},
]
17 changes: 16 additions & 1 deletion Default (OSX).sublime-keymap
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,20 @@
"context": [{
"key": "setting.anf_panel"
}]
}
},
{"keys": ["ctrl+n"],"command": "advanced_new_file_next",
"context": [{"key": "setting.anf_panel"}]
},
{"keys": ["ctrl+p"],"command": "advanced_new_file_prev",
"context": [{"key": "setting.anf_panel"}]
},
{"keys": ["ctrl+l"],"command": "advanced_new_file_updir",
"context": [{"key": "setting.anf_panel"}]
},
{"keys": ["enter"],"command": "advanced_new_file_confirm",
"context": [{"key": "setting.anf_panel"}]
},
{"keys": ["ctrl+j"],"command": "insert", "args": {"characters": "\t"},
"context": [{"key": "setting.anf_panel"}]
},
]
17 changes: 16 additions & 1 deletion Default (Windows).sublime-keymap
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,20 @@
"context": [{
"key": "setting.anf_panel"
}]
}
},
{"keys": ["ctrl+n"],"command": "advanced_new_file_next",
"context": [{"key": "setting.anf_panel"}]
},
{"keys": ["ctrl+p"],"command": "advanced_new_file_prev",
"context": [{"key": "setting.anf_panel"}]
},
{"keys": ["ctrl+l"],"command": "advanced_new_file_updir",
"context": [{"key": "setting.anf_panel"}]
},
{"keys": ["enter"],"command": "advanced_new_file_confirm",
"context": [{"key": "setting.anf_panel"}]
},
{"keys": ["ctrl+j"],"command": "insert", "args": {"characters": "\t"},
"context": [{"key": "setting.anf_panel"}]
},
]
3 changes: 2 additions & 1 deletion Default.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
{ "caption": "ANF: Delete File", "command": "advanced_new_file_delete"},
{ "caption": "ANF: Delete Current File", "command": "advanced_new_file_delete", "args": {"current": true}},
{ "caption": "ANF: Copy Current File", "command": "advanced_new_file_copy" },
{ "caption": "ANF: Cut to File", "command": "advanced_new_file_cut_to_file" }
{ "caption": "ANF: Cut to File", "command": "advanced_new_file_cut_to_file" },
{ "caption": "ANF: Project File", "command": "advanced_new_file_project_file" }
]
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@ Note with either method, you may need to restart Sublime Text 2 for the plugin t
Installation through [package control](http://wbond.net/sublime_packages/package_control) is recommended. It will handle updating your packages as they become available. To install, do the following.

* In the Command Palette, enter `Package Control: Install Package`
* Search for `ANF` to see the list of available commands
* Search for `AdvancedNewFile`

### Manual
Clone or copy this repository into the packages directory. You will need to rename the folder to `AdvancedNewFile` if using this method. By default, the Package directory is located at:

* OS X: ~/Library/Application Support/Sublime Text 2/Packages/
* Windows: %APPDATA%/Sublime Text 2/Packages/
* Windows: %APPDATA%/Roaming/Sublime Text 2/Packages/
* Linux: ~/.config/sublime-text-2/Packages/
Copy link
Member

Choose a reason for hiding this comment

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

This commit removed ST2 (and Python 2.6) support by changing the super calls and I think that's perfectly fine, but the documentaiton should be updated accordingly.


or

* OS X: ~/Library/Application Support/Sublime Text 3/Packages/
* Windows: %APPDATA%/Sublime Text 3/Packages/
* Windows: %APPDATA%/Roaming/Sublime Text 3/Packages/
* Linux: ~/.config/sublime-text-3/Packages/

Depending on your install on windows, the ST packages path may be `%APPDATA%/Sublime Text 2/...`

## Usage
Simply bring up the AdvancedNewFile input through the appropriate [key binding](https://github.com/skuroda/Sublime-AdvancedNewFile#keymaps). Then, enter the path, along with the file name into the input field. Upon pressing enter, the file will be created. In addition, if the directories specified do not yet exists, they will also be created. For more advanced usage of this plugin, be sure to look at [Advanced Path Usage](https://github.com/skuroda/Sublime-AdvancedNewFile#advanced-path-usage). By default, the path to the file being created will be filled shown in the status bar as you enter the path information.
Simply bring up the AdvancedNewFile input through the appropriate [key binding](https://github.com/skuroda/Sublime-AdvancedNewFile). Then, enter the path, along with the file name into the input field. Upon pressing enter, the file will be created. In addition, if the directories specified do not yet exists, they will also be created. For more advanced usage of this plugin, be sure to look at [Advanced Path Usage](https://github.com/skuroda/Sublime-AdvancedNewFile#advanced-path-usage). By default, the path to the file being created will be filled shown in the status bar as you enter the path information.
Copy link
Member

Choose a reason for hiding this comment

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

What is the "key binding" link supposed to point to? (needs to be updated for the repo move, too)

A mention of the command palette would also be nice.


**Default directory:**
The default directory is specified by the `default_root` setting. By default, it will be the top directory of the folders listed in the window. If this cannot be resolved, the home directory will be used. See [Settings](https://github.com/skuroda/Sublime-AdvancedNewFile#settings) (`default_root`) for more information.
Expand All @@ -44,6 +44,12 @@ The plugin does not contain any menu commands by default. To add them yourself,
## Keymaps
If you have issues with keymaps, consider running [FindKeyConflicts](https://github.com/skuroda/FindKeyConflicts), also available through the package manager. Alternatively, set command logging to true by entering `sublime.log_commands(True)` in the Sublime Text console.

- `tab` or `ctrl+j` to choose the first candidate
- `ctrl+n` change to the next candidate in the completion list
- `ctrl+p` change to the prev candidate in the completion list
- `ctrl+l` change to the updir of the input path
- `enter` choose the first candidate when popup, otherwise confirm(finish) the operation when no popup

### Windows
`ctrl+alt+n`: General keymap to create new files.

Expand Down Expand Up @@ -233,7 +239,7 @@ To begin at the home directory simply start with `~/` like you would in the shel
#### Aliases:
You can create an alias to quickly navigate to a directory. Simply type in the alias followed by a colon. Then specify the path as you would normally. Note, in an event a specified alias conflicts with a [predefined alias](https://github.com/skuroda/Sublime-AdvancedNewFile#predefined-aliases), the specified alias will take precedence.

Alias paths may be relative or absolute. If a relative path is specified, the `alias_root` setting will be used as the base. When specifying absolute paths, be sure to use the system specific style (e.g. Windows `C:\\Users\\username\\Desktop`, OS X and Linux `/home/username/desktop/`). In addition, you may specify an alias from the home directory by using `~/`.
Alias paths may be relative or absolute. If a relative path is specified, the `alias_root` setting will be used as the base. When specifying absolute paths, be sure to use the system specific style (e.g. Windows `C:\\Users\\username\\Desktop`, OS X and Linix `/home/username/desktop/`). In addition, you may specify an alias from the home directory by using `~/`.
Copy link
Member

Choose a reason for hiding this comment

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

This introduced a typo.


If an invalid alias is specified, an error pop up will be displayed when trying to create the file.

Expand Down Expand Up @@ -273,6 +279,10 @@ In Sublime Text 2, the name of the folder will be the actual name of the folder,
###### Current Working Directory
To specify the current working directory, simply type a colon, without any preceding text. Alternatively, set `relative_from_current` to `true` in your settings. Paths specified as relative paths will then begin from the current working directory.

## TODO
### project scope settings
`filter_regex` and `use_pinyin_to_filter` settings are project related. We can set these in `.sublime-project` file for project specific.

## Notes
Thanks to Dima Kukushkin ([xobb1t](https://github.com/xobb1t)) for the original work on this plugin. Also, thank you to [facelessuser](https://github.com/facelessuser), and by extension biermeester and matthjes for the idea of platform specific settings. Additional thanks to [kemayo](https://github.com/kemayo) for the work in identifying git executable.

Expand Down
10 changes: 7 additions & 3 deletions advanced_new_file/anf_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

ALIAS_SETTING = "alias"
DEFAULT_INITIAL_SETTING = "default_initial"
AUTOFILL_RENAME = "autofill_path_the_existing"
USE_CURSOR_TEXT_SETTING = "use_cursor_text"
SHOW_FILES_SETTING = "show_files"
SHOW_PATH_SETTING = "show_path"
Expand Down Expand Up @@ -41,12 +40,14 @@
COPY_FILE_DEFAULT_ROOT_SETTING = "copy_file_default_root"
DEFAULT_NEW_FILE = "empty_filename_action"
CURSOR_BEFORE_EXTENSION_SETTING = "cursor_before_extension"
FILTER_REGEX_SETTING = "filter_regex"
USE_PINYIN_TO_FILTER_SETTING = "use_pinyin_to_filter"
COMPLETION_DELAY_SETTING = "completion_after_milliseconds"


SETTINGS = [
ALIAS_SETTING,
DEFAULT_INITIAL_SETTING,
AUTOFILL_RENAME,
USE_CURSOR_TEXT_SETTING,
SHOW_FILES_SETTING,
SHOW_PATH_SETTING,
Expand Down Expand Up @@ -82,7 +83,10 @@
RENAME_FILE_DEFAULT_ROOT_SETTING,
COPY_FILE_DEFAULT_ROOT_SETTING,
DEFAULT_NEW_FILE,
CURSOR_BEFORE_EXTENSION_SETTING
CURSOR_BEFORE_EXTENSION_SETTING,
FILTER_REGEX_SETTING,
USE_PINYIN_TO_FILTER_SETTING,
COMPLETION_DELAY_SETTING,
]

NIX_ROOT_REGEX = r"^/"
Expand Down
9 changes: 7 additions & 2 deletions advanced_new_file/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
from .helper_commands import AnfReplaceCommand, AdvancedNewFileCommand, AnfRemoveRegionContentAndRegionCommand
from .new_file_command import AdvancedNewFileNew, AdvancedNewFileNewAtCommand, AdvancedNewFileNewAtFileCommand, AdvancedNewFileNewEventListener
from .new_file_command import AdvancedNewFileNew, AdvancedNewFileNextCommand, AdvancedNewFilePrevCommand, AdvancedNewFileUpdirCommand, AdvancedNewFileNewAtCommand, AdvancedNewFileNewAtFileCommand, AdvancedNewFileNewEventListener
from .delete_file_command import AdvancedNewFileDelete
from .cut_to_file import AdvancedNewFileCutToFile
from .move_file_command import AdvancedNewFileMove, AdvancedNewFileMoveAtCommand
from .copy_file_command import AdvancedNewFileCopy, AdvancedNewFileCopyAtCommand
from .project_file_command import AdvancedNewFileProjectFileCommand

__all__ = [
"AnfReplaceCommand",
"AdvancedNewFileCommand",
"AdvancedNewFileNew",
"AdvancedNewFileNextCommand",
"AdvancedNewFilePrevCommand",
"AdvancedNewFileUpdirCommand",
"AdvancedNewFileNewAtCommand",
"AdvancedNewFileNewAtFileCommand",
"AdvancedNewFileNewEventListener",
Expand All @@ -18,5 +22,6 @@
"AdvancedNewFileCopy",
"AdvancedNewFileCopyAtCommand",
"AnfRemoveRegionContentAndRegionCommand",
"AdvancedNewFileCutToFile"
"AdvancedNewFileCutToFile",
"AdvancedNewFileProjectFileCommand"
]
Loading