org-iswitchb.el 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. ;;; org-iswitchb.el --- use iswitchb to select Org buffer
  2. ;;
  3. ;; Copyright 2007 2008 Bastien Guerry
  4. ;;
  5. ;; Author: bzg AT altern DOT org
  6. ;; Version: 0.1
  7. ;; Keywords: Org buffer
  8. ;; URL: http://www.cognition.ens.fr/~guerry/u/org-iswitchb.el
  9. ;;
  10. ;; This file is NOT part of GNU Emacs.
  11. ;;
  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)
  15. ;; any later version.
  16. ;;
  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.
  21. ;;
  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.
  25. ;;
  26. ;;; Commentary:
  27. ;;
  28. ;; Put this file into your load-path and the following into your ~/.emacs:
  29. ;; (require 'org-iswitchb)
  30. ;;
  31. ;;; Code:
  32. (defun org-iswitchb (&optional arg)
  33. "Use `iswitchb-read-buffer' to prompt for an Org buffer to switch to.
  34. With a prefix argument, restrict available to files.
  35. With two prefix arguments, restrict available buffers to agenda files.
  36. Due to some yet unresolved reason, global function
  37. `iswitchb-mode' needs to be active for this function to work."
  38. (interactive "P")
  39. (eval-when-compile
  40. (require 'iswitchb))
  41. (let ((enabled iswitchb-mode) blist)
  42. (or enabled (iswitchb-mode 1))
  43. (setq blist (cond ((equal arg '(4)) (org-buffer-list 'files))
  44. ((equal arg '(16)) (org-buffer-list 'agenda))
  45. (t (org-buffer-list))))
  46. (unwind-protect
  47. (let ((iswitchb-make-buflist-hook
  48. (lambda ()
  49. (setq iswitchb-temp-buflist
  50. (mapcar 'buffer-name blist)))))
  51. (switch-to-buffer
  52. (iswitchb-read-buffer
  53. "Switch-to: " nil t))
  54. (or enabled (iswitchb-mode -1))))))
  55. (defun org-buffer-list (&optional predicate tmp)
  56. "Return a list of Org buffers.
  57. PREDICATE can be either 'export, 'files or 'agenda.
  58. 'export restrict the list to Export buffers.
  59. 'files restrict the list to buffers visiting Org files.
  60. 'agenda restrict the list to buffers visiting agenda files.
  61. If TMP is non-nil, don't include temporary buffers."
  62. (let (filter blist)
  63. (setq filter
  64. (cond ((eq predicate 'files) "\.org$")
  65. ((eq predicate 'export) "\*Org .*Export")
  66. (t "\*Org \\|\.org$")))
  67. (setq blist
  68. (mapcar
  69. (lambda(b)
  70. (let ((bname (buffer-name b))
  71. (bfile (buffer-file-name b)))
  72. (if (and (string-match filter bname)
  73. (if (eq predicate 'agenda)
  74. (member bfile
  75. (mapcar (lambda(f) (file-truename f))
  76. org-agenda-files)) t)
  77. (if tmp (not (string-match "tmp" bname)) t)) b)))
  78. (buffer-list)))
  79. (delete nil blist)))
  80. (provide 'org-iswitchb)
  81. ;;; User Options, Variables
  82. ;;; org-iswitchb.el ends here