2012-12-20 3 views
8

मैं ऑर्ग-मोड और ऑर्ग-संलग्न का उपयोग कर रहा हूं जिसका अर्थ है कि एक संगठन फ़ाइल से जुड़े कई अनुलग्नक निर्देशिकाएं हो सकती हैं।Emacs org-mode में किसी फ़ंक्शन को उप-स्ट्रीम में कैसे प्रतिबंधित करें?

worg पर मुझे मैट लुंडी से एक फ़ंक्शन मिला जो सभी संलग्नक को पूरी फ़ाइल से संबंधित देखने और उन्हें ido के साथ ब्राउज़ करने की अनुमति देता है।

मैं इस फ़ंक्शन को एक उप-धारा में प्रतिबंधित करना चाहता हूं जो इसे मेरे उपयोग के मामले के लिए और अधिक उपयोगी बना देगा।

चूंकि मैं emacs के लिए नया नहीं हूं लेकिन लगभग पूरी तरह से निरक्षर elisp मैं यहां पूछ रहा हूँ।

(defun my-ido-find-org-attach() 
    "Find files in org-attachment directory" 
    (interactive) 
    (let* ((enable-recursive-minibuffers t) 
     (files (find-lisp-find-files org-attach-directory ".")) 
     (file-assoc-list 
      (mapcar (lambda (x) 
        (cons (file-name-nondirectory x) 
          x)) 
        files)) 
     (filename-list 
      (remove-duplicates (mapcar #'car file-assoc-list) 
          :test #'string=)) 
     (filename (ido-completing-read "Org attachments: " filename-list nil t)) 
     (longname (cdr (assoc filename file-assoc-list)))) 
    (ido-set-current-directory 
    (if (file-directory-p longname) 
     longname 
     (file-name-directory longname))) 
    (setq ido-exit 'refresh 
      ido-text-init ido-text 
      ido-rotate-temp t) 
    (exit-minibuffer))) 
+0

क्या आप फ़ाइल उपट्री या ऑर्ग उपट्री के अनुलग्नक को शामिल करने के लिए कहते हैं? –

+1

मैं चाहता हूं कि फंकशन केवल एक संगठन उप-विचार पर विचार करें। –

उत्तर

3

शायद मैं कुछ याद कर रहा हूँ, लेकिन org-narrow-to-subtree पहले बुला आप क्या चाहते हैं क्या करना चाहिए (widen बाद में फोन है कि वापस लौटने के लिए):

यह कार्य है।

+0

जिस तरह से 'my-ido-find-org-attach' लिखा गया है' org-narrow-to-subtree' का कोई प्रभाव नहीं है क्योंकि यह 'org-attach-directory' के मान का अंधाधुंध उपयोग करता है। – aculich

0

मैंने सोचा कि यह बहुत उपयोगी होगा, इसलिए आपके प्रश्न से प्रेरित, मैंने एक संस्करण लिखा है जो आप चाहते हैं कि कुछ और घंटियां और सीटी। इसे आमंत्रित करने के लिए आपको सी-सी ओ टाइप करना होगा। नोट: यह सामान्य org-attach कुंजी उपसर्ग पर नहीं है क्योंकि उस फ़ंक्शन को बिना किसी कुंजीमैप के लिखा गया है, इसलिए कार्यक्षमता को मुख्य उपसर्ग पर जोड़ना मुश्किल है।

(autoload 'org-attach-dir "org-attach") 
(autoload 'find-lisp-find-files "find-lisp") 
(defcustom ido-locate-org-attach-all-files nil 
    "Non-nil means `ido-locate-org-attach' returns all files. 
Otherwise the default behavior only returns files attached to the 
current entry." 
    :group 'ido 
    :type 'boolean) 

(defun ido-locate-org-attach (&optional find-all) 
    "Find files in org-attachment directory for current entry. 
When called with a prefix argument, include all files in 
`org-attach-directory'. With a double `C-u' prefix arg the value 
of `ido-locate-org-attach-all-files' will be toggled for the 
session. If you want to save it permanently for future session 
then customize the variable `ido-locate-org-attach-all-files'." 
    (interactive "P") 
    (when (org-attach-dir nil) 
    (when (equal find-all '(16)) 
     (setq ido-locate-org-attach-all-files 
     (not ido-locate-org-attach-all-files))) 
    (let* ((enable-recursive-minibuffers t) 
     (dir (if (org-xor ido-locate-org-attach-all-files 
       (equal find-all '(4))) 
      org-attach-directory 
      (org-attach-dir nil))) 
     (files (find-lisp-find-files dir ".")) 
     (file-assoc-list 
     (mapcar (lambda (x) 
       (cons (file-name-nondirectory x) 
       x)) 
      files)) 
     (filename-list 
     (remove-duplicates (mapcar #'car file-assoc-list) 
        :test #'string=)) 
     (filename (ido-completing-read "Org attachments: " filename-list nil t)) 
     (longname (cdr (assoc filename file-assoc-list)))) 
     (ido-set-current-directory 
     (if (file-directory-p longname) 
     longname 
    (file-name-directory longname))) 
     (setq ido-exit 'refresh 
     ido-text-init ido-text 
     ido-rotate-temp t) 
     (exit-minibuffer)))) 

;; Run ido-locate-org-attach when using org-open-at-point (C-c C-o) in 
;; the current entry (except if you're on the header line itself it 
;; will use the default behavior to open/close the entry. 
(add-hook 'org-open-at-point-functions 'ido-locate-org-attach) 

;; C-c o   will locate files for the current entry 
;; C-u C-c o  will locate files for the whole file 
;; C-u C-u C-c o will toggle the default current entry/whole file 
(define-key org-mode-map "\C-co" 'ido-locate-org-attach) 

मैं org-attach.el का आधिकारिक हिस्सा बनने के लिए इसे प्रस्तुत करने में देखता हूं।

एक अलग रूप में के रूप में, '(4) और '(16) जादू संख्या इसका मतलब यह उपसर्ग आर्ग हैं एक बार सी-यू और उपसर्ग आर्ग दो बार सी-यू सी यू कुंजी अनुक्रम कि आदेश सहभागी लागू करने से पहले।

+0

इसके लिए धन्यवाद और देर से उत्तर के लिए खेद है। लेकिन दुर्भाग्य से मैं आपको काम नहीं कर सकता। जब मैं अनुलग्नक निर्देशिका के साथ शीर्षक पर हूं तो यह ऑर्ग-अटैच और ओ (वर्तमान कार्य के अनुलग्नक खोलें) के समान होता है। माता-पिता के शीर्षक पर आने पर कुछ भी नहीं होता है, जब मैं बच्चे के शीर्षकों के सभी अनुलग्नक को ढूंढने की अपेक्षा करता। मुझे कहना होगा कि मैं विंडोज़ पर हूं लेकिन मुझे नहीं लगता कि यह संगठन से जुड़ा हुआ है। –

+0

यह सुनिश्चित करने के लिए कि फ़ंक्शन काम करता है, इसे 'एम-एक्स ido-explore-org-attach' के साथ आवेदक करने का प्रयास करें। क्या आप इसे 'सी-सी सी-ओ' के ऑर्ग-अटैच कुंजी कॉम्बो का उपयोग करने के बजाय 'सी-सी ओ' के साथ आमंत्रित कर रहे हैं? मैं org-attach-open-in-emacs के लिए डिफ़ॉल्ट कुंजी ओवरराइड नहीं कर रहा हूं, बस ऑर्ग-संलग्न उपसर्ग के बाहर एक अलग कुंजी बाध्यकारी जोड़ रहा हूं। – aculich

+0

मैंने पहले ही यह किया है। दोनों 'सी-सी ओ' और 'एम-एक्स ido-explore-org-attach' दोनों एक ही परिणाम देते हैं। बीटीडब्ल्यू मैं Emacs 24.2.1 और संगठन संस्करण 7.9.2 (ELPA से) –

संबंधित मुद्दे