1 ;;; org-iswitchb.el --- use iswitchb to select Org buffer
3 ;; Copyright 2007 2008 Bastien Guerry
5 ;; Author: bzg AT altern DOT org
7 ;; Keywords: Org buffer
8 ;; URL: http://www.cognition.ens.fr/~guerry/u/org-iswitchb.el
10 ;; This file is NOT part of GNU Emacs.
12 ;; This program is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
17 ;; This program is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with this program; if not, write to the Free Software
24 ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 ;; Put this file into your load-path and the following into your ~/.emacs:
29 ;; (require 'org-iswitchb)
33 (defun org-iswitchb (&optional arg
)
34 "Use `iswitchb-read-buffer' to prompt for an Org buffer to switch to.
35 With a prefix argument, restrict available to files.
36 With two prefix arguments, restrict available buffers to agenda files.
38 Due to some yet unresolved reason, global function
39 `iswitchb-mode' needs to be active for this function to work."
43 (let ((enabled iswitchb-mode
) blist
)
44 (or enabled
(iswitchb-mode 1))
45 (setq blist
(cond ((equal arg
'(4)) (org-buffer-list 'files
))
46 ((equal arg
'(16)) (org-buffer-list 'agenda
))
47 (t (org-buffer-list))))
49 (let ((iswitchb-make-buflist-hook
51 (setq iswitchb-temp-buflist
52 (mapcar 'buffer-name blist
)))))
56 (or enabled
(iswitchb-mode -
1))))))
58 (defun org-buffer-list (&optional predicate tmp
)
59 "Return a list of Org buffers.
60 PREDICATE can be either 'export, 'files or 'agenda.
62 'export restrict the list to Export buffers.
63 'files restrict the list to buffers visiting Org files.
64 'agenda restrict the list to buffers visiting agenda files.
66 If TMP is non-nil, don't include temporary buffers."
69 (cond ((eq predicate
'files
) "\.org$")
70 ((eq predicate
'export
) "\*Org .*Export")
71 (t "\*Org \\|\.org$")))
75 (let ((bname (buffer-name b
))
76 (bfile (buffer-file-name b
)))
77 (if (and (string-match filter bname
)
78 (if (eq predicate
'agenda
)
80 (mapcar (lambda(f) (file-truename f
))
82 (if tmp
(not (string-match "tmp" bname
)) t
)) b
)))
86 (provide 'org-iswitchb
)
88 ;;; User Options, Variables
90 ;;; org-iswitchb.el ends here