diff --git a/Default.sublime-keymap b/Default.sublime-keymap index f238ca2..804bea9 100644 --- a/Default.sublime-keymap +++ b/Default.sublime-keymap @@ -331,7 +331,7 @@ "context": [ { "key": "selector", "operator": "equal", "operand": "text.dired" }, { "key": "setting.dired_rename_mode", "operand": true }, - { "key": "preceding_text", "operator": "regex_contains", "operand": "[≡▸▾]\\s*$|^\\s*$|^⠤.*$"} + { "key": "preceding_text", "operator": "regex_contains", "operand": "[≡▸▾]\\s*$|^\\s*$|^\\s*\\S\\s$|^⠤.*$"} ] }, { diff --git a/common.py b/common.py index dcef4ed..1b6ccb1 100644 --- a/common.py +++ b/common.py @@ -418,6 +418,7 @@ def prepare_filelist(self, names, path, goto, indent): files = [] index_dirs = [] index_files = [] + icons = sublime.load_settings('dired.sublime-settings').get('dired_icons', {}) for name in names: full_name = join(path, goto, name) if isdir(full_name): @@ -425,7 +426,8 @@ def prepare_filelist(self, names, path, goto, indent): items.append(''.join([level, u"▸ ", name, os.sep])) else: index_files.append(full_name) - files.append(''.join([level, u"≡ ", name])) + icon = icons.get(name.split('.')[-1], '≡') + files.append(''.join([level, icon, ' ', name])) index = index_dirs + index_files self.index = self.index[:self.number_line] + index + self.index[self.number_line:] items += files @@ -535,7 +537,7 @@ def _find_in_view(self, item): pattern = u'^\s*[▸▾] ' sep = re.escape(os.sep) else: - pattern = u'^\s*≡ ' + pattern = r'^\s*\S ' sep = '' return self.view.find_all(u'%s%s%s' % (pattern, fname, sep)) diff --git a/dired.hidden-tmLanguage b/dired.hidden-tmLanguage index 428670a..aae4dcc 100644 --- a/dired.hidden-tmLanguage +++ b/dired.hidden-tmLanguage @@ -52,7 +52,7 @@ match - ^(\s*)(≡ )(\S.*?(\.[^\.\n]+)?)$ + ^(\s*)(\S )(\S.*?(\.[^\.\n]+)?)$ name dired.item.file captures diff --git a/dired.py b/dired.py index d12ca3d..307dfda 100644 --- a/dired.py +++ b/dired.py @@ -291,6 +291,7 @@ def traverse_tree(self, root, path, indent, tree, expanded): tree[~0] += '\t' return + icons = sublime.load_settings('dired.sublime-settings').get('dired_icons', {}) files = [] index_files = [] for f in items: @@ -304,7 +305,10 @@ def traverse_tree(self, root, path, indent, tree, expanded): tree.append(u'%s▸ %s%s' % (indent, f.rstrip(os.sep), os.sep)) else: index_files.append(new_path) - files.append(u'%s≡ %s' % (indent, f)) + icon = icons.get(f.split(".")[-1], "≡") + # Ensure icon are 1 char long + icon = icon[0] + files.append(u'%s%s %s' % (indent, icon, f)) self.index += index_files tree += files @@ -681,6 +685,9 @@ def apply_change_into_view(self, edit, line, indented_region): end_line = start_line + removed_count self.index = self.index[:start_line] + self.index[end_line:] v.settings().set('dired_index', self.index) + else: + # I'm not sure this is the right behavior. + start_line = 1 + v.rowcol(line.a)[0] if self.marked or self.seled: path = self.path @@ -691,7 +698,11 @@ def apply_change_into_view(self, edit, line, indented_region): self.seled[0].append(folded_name) name_point = self._get_name_point(line) - icon_region = Region(name_point - 2, name_point - 1) + if v.substr(name_point) == "▾": + # I'm not sure why but sometimes get_name_point returns the icon + icon_region = Region(name_point, name_point + 1) + else: + icon_region = Region(name_point - 2, name_point - 1) v.set_read_only(False) v.replace(edit, icon_region, u'▸') diff --git a/dired.sublime-settings b/dired.sublime-settings index 2e59ba8..6b7ce18 100644 --- a/dired.sublime-settings +++ b/dired.sublime-settings @@ -70,6 +70,11 @@ // Only for OSX and Linux. "dired_dup_separator": " — ", + // Map file extensions to a specific icon. + // Works best with an extended font from https://www.nerdfonts.com/ + // Example: "dired_icons": { "json": "", "md": "", "py": "", "zip": ""}, + "dired_icons": {}, + // Automatically disable Vintageous to avoid keybindings incompatibilities; // note it is Vintageous setting, if it does not work you should report into // appropriate repository https://github.com/guillermooo/Vintageous/issues diff --git a/dired.sublime-syntax b/dired.sublime-syntax index f78d39d..562c448 100644 --- a/dired.sublime-syntax +++ b/dired.sublime-syntax @@ -15,7 +15,7 @@ contexts: 3: string.name.directory.dired 4: punctuation.definition.directory.slash.dired 5: string.error.dired - - match: '^(\s*)(≡ )(\S.*?(\.[^\.\n]+)?)$' + - match: '^(\s*)(\S )(\S.*?(\.[^\.\n]+)?)$' scope: dired.item.file captures: 1: indent diff --git a/dired_file_operations.py b/dired_file_operations.py index 51db479..ada0b1d 100644 --- a/dired_file_operations.py +++ b/dired_file_operations.py @@ -255,7 +255,7 @@ def run(self, edit): before = self.view.settings().get('rename') # We marked the set of files with a region. Make sure the region still has the same # number of files. - after = self.get_after() + after = self.get_after() if len(after) != len(before): return sublime.error_message('You cannot add or remove lines') @@ -276,7 +276,10 @@ def get_after(self): self.index = self.get_all() path = self.path lines = self._get_lines(self.view.get_regions('rename'), self.fileregion()) - return [self._new_name(line, path=path) for line in lines] + lines = [self._new_name(line, path=path) for line in lines] + assert '[RENAME MODE]' in lines[0], "Please don't edit the header '[RENAME MODE]' '" + lines[0] + "'" + lines = lines[1:] + return lines def _new_name(self, line, path=None, full=False): '''Return new name for line