Skip to content

Commit bf4909a

Browse files
committed
Handle files without extensions for templates.
1 parent 7731334 commit bf4909a

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

AdvancedNewFile.sublime-settings

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,14 @@
114114
"vcs_management": false,
115115

116116
// An object containing information to use for templates when creating new files.
117-
// The key values for this object should be a file extension. The value may either
118-
// be a string of the content to be inserted or a list of paths. If a list of paths
119-
// is specified, the name of the file will be displayed during selection. The paths
120-
// must either be absolute, from the home directory of the user (`~/`), or relative
121-
// to the Packages directory. These relative files should have the form
122-
// "Packages/User/mytest.sublime-snippet". If a string is used, or the list contains
123-
// a single entry, it will be automatically inserted into any newly created files.
117+
// The key values for this object should be a file extension. Files without extensions
118+
// such as "Makefile" or ".bash_profile" use the full file name as the key.
119+
// The value may either be a string of the content to be inserted or a list of paths.
120+
// If a list of paths is specified, the name of the file will be displayed during
121+
// selection. The paths must either be absolute, from the home directory of the
122+
// user (`~/`), or relative to the Packages directory. These relative files should have
123+
// the form "Packages/User/mytest.sublime-snippet". If a string is used, or the list
124+
// contains a single entry, it will be automatically inserted into any newly created files.
124125
"file_templates": {},
125126

126127
// Setting this value to true will allow you to escape characters as you normally

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ Setting to control if VCS management is used when moving and removing files.
158158

159159
`file_templates`:
160160

161-
An object containing information to use for templates when creating new files. The key values for this object should be a file extension. The value may either be a string of the content to be inserted or a list of paths. If a list of paths is specified, the name of the file will be displayed during selection. The paths must either be absolute, from the home directory of the user (`~/`), or relative to the Packages directory. These relative files should have the form "Packages/User/mytest.sublime-snippet". If a string is used, or the list contains a single entry, it will be automatically inserted into any newly created files.
161+
An object containing information to use for templates when creating new files. The key values for this object should be a file extension. Files without extensions such as "Makefile" or ".bash_profile" use the full file name as the key. The value may either be a string of the content to be inserted or a list of paths. If a list of paths is specified, the name of the file will be displayed during selection. The paths must either be absolute, from the home directory of the user (`~/`), or relative to the Packages directory. These relative files should have the form "Packages/User/mytest.sublime-snippet". If a string is used, or the list contains a single entry, it will be automatically inserted into any newly created files.
162162

163163
`posix_input`:
164164

advanced_new_file/commands/new_file_command.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,15 @@ def is_visible(self, dirs):
132132
class AdvancedNewFileNewEventListener(sublime_plugin.EventListener):
133133
def on_load(self, view):
134134
if view.settings().get("_anf_new", False):
135-
_, extension = os.path.splitext(view.file_name())
136-
extension = extension[1:]
135+
absolute_file_path = view.file_name()
136+
if absolute_file_path is None:
137+
return
138+
file_name = self.get_basename(absolute_file_path)
139+
_, full_extension = os.path.splitext(file_name)
140+
if len(full_extension) == 0:
141+
extension = file_name
142+
else:
143+
extension = full_extension[1:]
137144
settings = get_settings(view)
138145
if extension in settings.get(FILE_TEMPLATES_SETTING):
139146
template = settings.get(FILE_TEMPLATES_SETTING)[extension]

0 commit comments

Comments
 (0)