2012-12-20 14 views
8

私はorg-modeとorg-attachを広く使用しています。つまり、 は、1つのorgファイルに関連付けられた多くの添付ファイルディレクトリが存在する可能性があります。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

ファイルサブツリーまたはorgサブツリーの添付ファイルを含めるかどうか尋ねますか? –

+1

私はfunktionにorgサブツリーのみを考慮させたいと思います。 –

答えて

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)は、対話的にコマンドを起動したキー列の前に前置引数を意味するのマジックナンバーに一度C-Uと前置引数回C-U C-Uとおりです。

+0

これはお返事ありがとうございました。しかし、残念ながら私はあなたの仕事を得ることができません。 アタッチメントディレクトリを持つ見出しにいるときは、org-attachとo(現在のタスクの添付ファイルを開く)と同じことをします。親見出しで呼び出されたときは何も起きませんでしたが、私は子見出しのすべての添付を見つけることが予想されました。 私は窓の上にいると言わなければなりませんが、 org-attachが完璧に機能するので、それは関係ないと思います。 –

+0

'M-x ido-locate-org-attach'で起動して、機能が動作することを確認してください。 'C-c C-a o'のorg-attachキーコンボを使用するのではなく、' C-c o'を使用して起動していますか?私は、org-attach-in-emacsのデフォルトのキーをオーバーライドしているわけではなく、org-attachプレフィックスの外側に別のキーバインディングを追加するだけです。 – aculich

+0

私はすでにこれをしました。 'C-C o'と' M-x ido-locate-org-attach'の両方で同じ結果が得られます。 BTW私はEmacs 24.2.1とorgバージョン7.9.2(ELPAから) –

関連する問題