PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/cedet/speedbar/sb-rmail.el

http://github.com/spastorino/my_emacs_for_rails
Emacs Lisp | 157 lines | 92 code | 16 blank | 49 comment | 2 complexity | d1a25fa37cd070ddbdca5611a1f12a48 MD5 | raw file
Possible License(s): GPL-2.0
  1. ;;; sb-rmail --- Speedbar support for rmail
  2. ;; Copyright (C) 1997, 1998, 1999, 2001, 2002, 2003 Free Software Foundation
  3. ;;
  4. ;; Author: Eric M. Ludlam <zappo@gnu.ai.mit.edu>
  5. ;; Version: 0.1
  6. ;; Keywords: file, tags, tools
  7. ;; X-RCS: $Id: sb-rmail.el,v 1.12 2003/02/21 18:04:30 zappo Exp $
  8. ;;
  9. ;; This file is part of GNU Emacs.
  10. ;;
  11. ;; This program is free software; you can redistribute it and/or modify
  12. ;; it under the terms of the GNU General Public License as published by
  13. ;; the Free Software Foundation; either version 2, or (at your option)
  14. ;; any later version.
  15. ;;
  16. ;; This program is distributed in the hope that it will be useful,
  17. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. ;; GNU General Public License for more details.
  20. ;;
  21. ;; You should have received a copy of the GNU General Public License
  22. ;; along with this program; if not, you can either send email to this
  23. ;; program's author (see below) or write to:
  24. ;;
  25. ;; The Free Software Foundation, Inc.
  26. ;; 675 Mass Ave.
  27. ;; Cambridge, MA 02139, USA.
  28. ;;
  29. ;; Please send bug reports, etc. to zappo@gnu.ai.mit.edu.
  30. ;;
  31. ;;; Commentary:
  32. ;;
  33. ;; Speedbar provides a frame in which files, and locations in
  34. ;; files are displayed. These functions provide rmail specific support,
  35. ;; showing links and addresses in the side-bar.
  36. ;;
  37. ;; To enable in emacs 20.2 or earlier, add this to your .emacs file.
  38. ;; (autoload 'rmail-speedbar-buttons "sb-rmail"
  39. ;; "Rmail specific speedbar button generator.")
  40. ;;
  41. ;; This file requires speedbar.
  42. ;;; Change log:
  43. ;; 0.1 - first revision copied from speedbspec.el V 0.1.1
  44. ;; 0.1.1 - removed require speedbspec.
  45. ;; 0.1.2 - Changed to handle new keymap feature.
  46. ;;; Code:
  47. (defvar rmail-speedbar-match-folder-regexp "^[A-Z0-9]+\\(\\.[A-Z0-9]+\\)?$"
  48. "*This regex is used to match folder names to be displayed in speedbar.
  49. Enabling this will permit speedbar to display your folders for easy
  50. browsing, and moving of messages.")
  51. (defvar rmail-speedbar-last-user nil
  52. "The last user to be displayed in the speedbar.")
  53. (defvar rmail-speedbar-key-map nil
  54. "Keymap used when in rmail display mode.")
  55. (defun rmail-install-speedbar-variables ()
  56. "Install those variables used by speedbar to enhance rmail."
  57. (if rmail-speedbar-key-map
  58. nil
  59. (setq rmail-speedbar-key-map (speedbar-make-specialized-keymap))
  60. (define-key rmail-speedbar-key-map "e" 'speedbar-edit-line)
  61. (define-key rmail-speedbar-key-map "r" 'speedbar-edit-line)
  62. (define-key rmail-speedbar-key-map "\C-m" 'speedbar-edit-line)
  63. (define-key rmail-speedbar-key-map "M"
  64. 'rmail-speedbar-move-message-to-folder-on-line)))
  65. (defvar rmail-speedbar-menu-items
  66. '(["Read Folder" speedbar-edit-line t]
  67. ["Move message to folder" rmail-speedbar-move-message-to-folder-on-line
  68. (save-excursion (beginning-of-line)
  69. (looking-at "<M> "))])
  70. "Additional menu-items to add to speedbar frame.")
  71. ;; Make sure our special speedbar major mode is loaded
  72. (if (featurep 'speedbar)
  73. (rmail-install-speedbar-variables)
  74. (add-hook 'speedbar-load-hook 'rmail-install-speedbar-variables))
  75. ;;;###autoload
  76. (defun rmail-speedbar-buttons (buffer)
  77. "Create buttons for BUFFER containing rmail messages.
  78. Click on the address under Reply to: to reply to this person.
  79. Under Folders: Click a name to read it, or on the <M> to move the
  80. current message into that RMAIL folder."
  81. (let ((from nil))
  82. (save-excursion
  83. (set-buffer buffer)
  84. (goto-char (point-min))
  85. (if (not (re-search-forward "^Reply-To: " nil t))
  86. (if (not (re-search-forward "^From:? " nil t))
  87. (setq from t)))
  88. (if from
  89. nil
  90. (setq from (buffer-substring (point) (save-excursion
  91. (end-of-line)
  92. (point))))))
  93. (goto-char (point-min))
  94. (if (and (looking-at "\\(//\\)?Reply to:")
  95. (equal from rmail-speedbar-last-user))
  96. nil
  97. (setq rmail-speedbar-last-user from)
  98. (erase-buffer)
  99. (speedbar-insert-separator "Reply To")
  100. (if (stringp from)
  101. (speedbar-insert-button from 'speedbar-directory-face 'highlight
  102. 'rmail-speedbar-button 'rmail-reply))
  103. (speedbar-insert-separator "Folders")
  104. (let* ((case-fold-search nil)
  105. (df (directory-files (save-excursion (set-buffer buffer)
  106. default-directory)
  107. nil rmail-speedbar-match-folder-regexp)))
  108. (while df
  109. (speedbar-insert-button "<M>" 'speedbar-button-face 'highlight
  110. 'rmail-speedbar-move-message (car df))
  111. (speedbar-insert-button (car df) 'speedbar-file-face 'highlight
  112. 'rmail-speedbar-find-file nil t)
  113. (setq df (cdr df)))))))
  114. (defun rmail-speedbar-button (text token indent)
  115. "Execute an rmail command specified by TEXT.
  116. The command used is TOKEN. INDENT is not used."
  117. (speedbar-with-attached-buffer
  118. (funcall token t)))
  119. (defun rmail-speedbar-find-file (text token indent)
  120. "Load in the rmail file TEXT.
  121. TOKEN and INDENT are not used."
  122. (speedbar-with-attached-buffer
  123. (speedbar-message "Loading in RMAIL file %s..." text)
  124. (find-file text)))
  125. (defun rmail-speedbar-move-message-to-folder-on-line ()
  126. "If the current line is a folder, move current message to it."
  127. (interactive)
  128. (save-excursion
  129. (beginning-of-line)
  130. (if (re-search-forward "<M> " (save-excursion (end-of-line) (point)) t)
  131. (progn
  132. (forward-char -2)
  133. (speedbar-do-function-pointer)))))
  134. (defun rmail-speedbar-move-message (text token indent)
  135. "From button TEXT, copy current message to the rmail file specified by TOKEN.
  136. TEXT and INDENT are not used."
  137. (speedbar-with-attached-buffer
  138. (message "Moving message to %s" token)
  139. (rmail-output-to-rmail-file token)))
  140. (provide 'sb-rmail)
  141. ;;; sb-rmail.el ends here