2012-11-13 37 views
10

मैं वर्तमान फ़ाइल को हटाने और सक्रिय दृश्य को बंद करने के लिए एक छोटी प्लगइन लिखने की कोशिश कर रहा हूं। किसी कारण से self.view.file_name() हमेशा कोई नहीं देता है।शानदार टेक्स्ट: वर्तमान दृश्य का फ़ाइल नाम कैसे प्राप्त करें

मैं पाइथन के लिए नया हूं और मुझे नहीं पता कि यह इस तरह क्यों काम नहीं करता है। API Reference फ़ाइल_नाम() के अनुसार वर्तमान दृश्य का फ़ाइल नाम देता है।

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') 

निर्देशिका के आउटपुट (self.view):

[ 'वर्ग', ' delattr', 'dict', 'डॉक', 'प्रारूप ',' getattribute ',' हैश ',' init ',' लेन ',' मॉड्यूल ',' नई ',' को कम ',' reduce_ex ',' रेपर ',' setattr ',' sizeof ',' str ',' subclasshook ',' weakref ',' add_regions ',' begin_edit ',' buffer_id ',' वर्गीकृत ',' command_history ',' em_width ',' एन्कोडिंग ',' end_edit ',' मिटा ' , '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', ' indent_region ',' insert ',' is_dirty ',' is_folded ',' is_loading ',' is_read_only ',' is_scratch ',' layout_extent ',' layout_to_text ',' line ',' line_endings ',' line_height ',' line ' , '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', 'visual_region', 'window', 'word']

+0

कंसोल में कोई त्रुटि संदेश? –

+0

नहीं। '(एफ कोई नहीं है)' के लिए चेक हमेशा सत्य है और इसलिए यह 'send2trash()' तक पहुंचने से पहले लौटाता है। 'Send2trash()' कॉल की जांच किए बिना विफल रहता है। जब मैं कंसोल में 'view.file_name()' निष्पादित करता हूं तो यह सही पथ देता है। – Felix

+0

प्रिंट डीआईआर (self.view) का आउटपुट क्या है? –

उत्तर

5

Plugins page of the unofficial documentation के अनुसार, उदात्त पाठ निम्नलिखित तरीके से आदेश नामों को सामान्य: "कमान" प्रत्यय बंद

  1. पट्टी
  2. अलग ऊंट अंडरस्कोर से वाक्यांशों मामलों

इस प्रकार, DeleteCurrentFileCommand होना चाहिए निम्न तरीके से बुलाया जाता है: view.run_command("delete_current_file")

इस आदेश के साथ, मैं पाइथन में ऊपर सूचीबद्ध अनुसार आपकी प्लगइन को चलाने में सक्षम था कंसोल।

हालांकि, अगर मैंने view.run_command("DeleteCurrentFile") चलाने का प्रयास किया, तो कंसोल एक खाली रेखा प्रदर्शित करेगा। इससे यह विचार हो सकता है कि self.view.file_name() कोई भी वापस नहीं कर रहा था।

+0

ओह मैन अब मुझे बेवकूफ लगता है। मैंने विंडो 'ऑब्जेक्ट' जैसे 'window.run_command (' delete_current_file ') पर कमांड चलाने की कोशिश की, जो स्पष्ट रूप से गलत है। यह तब काम करता है जब मैं 'view.run_command()' कहता हूं। धन्यवाद! – Felix

+0

आपका स्वागत है! :) – Talvalin