Note that there are some explanatory texts on larger screens.

plurals
  1. POSublime text: How to get the file name of the current view
    primarykey
    data
    text
    <p>I'm trying to write a tiny plugin to delete the current file and close the active view. For some reason self.view.file_name() always returns None.</p> <p>I'm new to Python and I've no idea why it doesn't work like this. According to the <a href="http://www.sublimetext.com/docs/2/api_reference.html#sublime.View" rel="nofollow">API Reference</a> file_name() returns the file name of the current view.</p> <pre><code>import sublime, sublime_plugin, send2trash class DeleteCurrentFileCommand(sublime_plugin.TextCommand): def run(self, edit): f = self.view.file_name() if (f is None): return send2trash.send2trash(f) self.view.window().run_command('close') </code></pre> <p>Output of dir(self.view):</p> <blockquote> <p>['<strong>class</strong>', '<strong>delattr</strong>', '<strong>dict</strong>', '<strong>doc</strong>', '<strong>format</strong>', '<strong>getattribute</strong>', '<strong>hash</strong>', '<strong>init</strong>', '<strong>len</strong>', '<strong>module</strong>', '<strong>new</strong>', '<strong>reduce</strong>', '<strong>reduce_ex</strong>', '<strong>repr</strong>', '<strong>setattr</strong>', '<strong>sizeof</strong>', '<strong>str</strong>', '<strong>subclasshook</strong>', '<strong>weakref</strong>', 'add_regions', 'begin_edit', 'buffer_id', 'classify', 'command_history', 'em_width', 'encoding', 'end_edit', 'erase', 'erase_regions', 'erase_status', 'extract_completions', 'extract_scope', 'file_name', 'find', 'find_all', 'find_all_results', 'find_by_selector', 'fold', 'folded_regions', 'full_line', 'get_regions', 'get_status', 'get_symbols', 'has_non_empty_selection_region', 'id', 'indentation_level', 'indented_region', 'insert', 'is_dirty', 'is_folded', 'is_loading', 'is_read_only', 'is_scratch', 'layout_extent', 'layout_to_text', 'line', 'line_endings', 'line_height', 'lines', 'match_selector', 'meta_info', 'name', 'replace', 'retarget', 'rowcol', 'run_command', 'scope_name', 'score_selector', 'sel', 'set_encoding', 'set_line_endings', 'set_name', 'set_read_only', 'set_scratch', 'set_status', 'set_syntax_file', 'set_viewport_position', 'settings', 'show', 'show_at_center', 'size', 'split_by_newlines', 'substr', 'syntax_name', 'text_point', 'text_to_layout', 'unfold', 'viewport_extent', 'viewport_position', 'visible_region', 'window', 'word']</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload