2012-12-20 14 views
8

我正在使用組織模式和org-attach這意味着 可能有多個與一個組織文件關聯的連接目錄。如何將函數限制在emacs org-mode中的子樹上?

在worg上,我發現了一個來自Matt Lundi的函數,它允許查看屬於整個文件的所有 附件並使用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

我希望funktion只考慮組織子樹。 –

回答

3

也許我失去了一些東西,但調用org-narrow-to-subtree首先應該做你想做的(叫widen後便可還原)。

+0

'my-ido-find-org-attach'寫成'org-narrow-to-subtree'的方式沒有效果,因爲它盲目地使用'org-attach-directory'的值。 – aculich

0

我認爲這將是非常有用的自己所以,受你的問題啓發,我寫了一個版本,做你想要的,再加上一些其他的花裏胡哨的。要調用它,你必須輸入C-c o。注意:這不是通常的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)是神奇數字意味着前綴ARG一次C-ù和前綴ARG兩次C-ùC-ü是交互調用命令的按鍵序列之前。

+0

感謝您的回覆,並對此抱歉。但不幸的是,我無法讓你上班。 當我在一個帶有附件目錄的標題上時,它與org-attach和o(打開當前任務的附件)一樣。當在父標題上調用什麼都沒有發生時,我希望能夠找到所有子標題的附件。 我必須說我在窗戶上,但我認爲這並不關係,因爲 org-attach完美無缺地工作。 –

+0

嘗試使用'M-x ido-locate-org-attach'調用它以確保該函數有效。你是用'C-c o'來調用它而不是使用'C-c C-a o'的組織鍵組合嗎?我不覆蓋org-attach-open-in-emacs的默認密鑰,只是在org-attach前綴之外添加一個不同的密鑰綁定。 – aculich

+0

我已經這樣做了。 'C-C o'和'M-x ido-locate-org-attach'都給出相同的結果。順便說一句我在Emacs 24.2.1和組織版本7.9.2(來自ELPA) –

相關問題