;;;; sylpheed-mode.el --- Major mode for writing email with Sylpheed! ;; ;; Copyright (c) 2006 Ryosuke SEKIDO, some rights reserved. ;; ;; Author: Ryosuke SEKIDO ;; Web: http://c--v.net/ ;; Mail: ryosuke (a) sekido dot info -- JAPANESE ONLY ;-) ;; Version: 1.0.1 ;; Keywords: mail, email, edit, sylpheed, highlight ;; License: Creative Commons License by 2.1 Japan ;; http://creativecommons.org/licenses/by/2.1/jp/ ;; ;;;; ;; ;; Installing sylpheed-mode ;; ======================== ;; ;; Save sylpheed-mode.el in a convenient directory, preferbly in your ;; `load-path'. And add the following to your `user-init-file': ;; ;; (autoload 'sylpheed-mode ;; "sylpheed-mode.el" ;; "Major mode for writing email with Sylpheed!" t) ;; ;; If you use Japanese language in mail body, you may set `sylpheed-encoding' ;; to like the following: ;; ;; ;; use Windows OS ;; (setq 'sylpheed-encoding 'shift_jis) ;; ;; use Fedora Core ;; (setq 'sylpheed-encoding 'utf-8) ;; ;; When you write any mail, type Ctrl-Shift-X: runs Emacs. Before write ;; something, you may change major mode to sylpheed-mode, so type: ;; ;; M-x sylpheed-mode ;; ;; ;; Features of sylpheed-mode ;; ========================= ;; ;; Highlighting text ;; ----------------- ;; ;; Highlight quoted text, email/homepage address, and sign part. Following ;; is for example. ;; ;; Here is base level text. ;; > First level text. ;; > Here will be highlighted with `sylpheed-quote-level1-face'. ;; > > Second level text. ;; > > Here will be highlighted with `sylpheed-quote-level2-face'. ;; > > > > > > Therefore, here is the max, sixth level text. ;; sekido> Quoted text like this type is not supported, sorry. ;; ;; Email address, like sekido@example.com, and homepage address, like ;; http://c--v.net/, will be colored with `sylpheed-email-face' and ;; `sylpheed-address-face'. ;; -- ;; After of `sylpheed-sign-separator' is colored with `sylpheed-signature-face'. ;; Default is "--". ;; ;; ;; Insert signature ;; ---------------- ;; Key bind: C-c C-g ;; ;; This is can from either text file or constant value. Key bind is same ;; as Sylpheed, however, pay attention for the sylpheed-mode has C-c prefix. ;; You can set signature file or strings in your .emacs file as: ;; ;; (autoload 'sylpheed-mode ...) ;; (setq 'sylpheed-sign-file "/home/sekido/.sylpheed/signature") ;; (setq 'sylpheed-signature "Ryosuke SEKIDO ") ;; ;; ;; End editing simply ;; ------------------ ;; ;; When you end editing with Emacs, you can type C-return, same as ;; Sylpheed send mail key bind. This will save buffer, and exit Emacs. ;; ;;;; ;; ;; History ;; ======= ;; Time zone: JST (+09:00) ;; ;; v1.0.0 2006-02-21 ;; o First release. ;; ;; v1.0.1 2006-03-04 ;; o Change `sylpheed-sign-separator' to DASH DASH SP. ;; According to http://www.kanzaki.com/memo/2006/03/03-1 (Japanese), ;; RFC 3676 define traditional signature separator, sig-dashes as ;; DASH DASH SP. ;; (provide 'sylpheed-mode) (require 'font-lock) ;; config (defvar sylpheed-signature "" "Signature string for Sylpheed-mode") (defvar sylpheed-sign-file "" "signature file for sylpheed-mode. CANNOT execute command! This is very simply because it will be insert a file where path is. 1) Unix like OS \"/home/sekido/.sylpheed/signature\" 2) Windows OS: pay attention to the separator required two back slashes. \"C:\\Documents and Settings\\sekido\\My Documents\\signature.txt\" 3) Do not include any file \"\"") (defvar sylpheed-quote-char-list '(">" "|") "used to highlight quoted sentences") (defvar sylpheed-sign-separator "-- " "signature separator") (defvar sylpheed-encoding 'utf-8 "mail body encoding") ;; variable init (defvar sylpheed-mode-map nil "Keymap for Sylpheed-mode") (defvar sylpheed-mode-syntax-table nil "Syntax table for Sylpheed-mode") (defvar sylpheed-mode-abbrev-table nil "Abbrev table for Sylpheed-mode") (defvar sylpheed-mode-hook nil "Normal hook run when entering Sylpheed-mode") ;; color settings ;; -- you can use M-x list-colors-display! (defface sylpheed-signature-face '((t (:foreground "gray"))) "`sylpheed-mode' face used to highlight signature") (defvar sylpheed-signature-face 'sylpheed-signature-face) (defface sylpheed-email-face '((t (:inherit bold :foreground "firebrick" :underline t))) "email highlighing") (defvar sylpheed-email-face 'sylpheed-email-face) (defvar sylpheed-address-face 'sylpheed-email-face) (defface sylpheed-quote-level1-face '((t (:inherit italic :foreground "medium blue"))) "quote level1 face") (defvar sylpheed-quote-level1-face 'sylpheed-quote-level1-face) (defface sylpheed-quote-level2-face '((t (:inherit italic :foreground "blue"))) "quote level2 face") (defvar sylpheed-quote-level2-face 'sylpheed-quote-level2-face) (defface sylpheed-quote-level3-face '((t (:inherit italic :foreground "dodger blue"))) "quote level3 face") (defvar sylpheed-quote-level3-face 'sylpheed-quote-level3-face) (defface sylpheed-quote-level4-face '((t (:inherit italic :foreground "deep sky blue"))) "quote level4 face") (defvar sylpheed-quote-level4-face 'sylpheed-quote-level4-face) (defface sylpheed-quote-level5-face '((t (:inherit italic :foreground "sky blue"))) "quote level5 face") (defvar sylpheed-quote-level5-face 'sylpheed-quote-level5-face) (defface sylpheed-quote-level6-face '((t (:inherit italic :foreground "light sky blue"))) "quote level6 face") (defvar sylpheed-quote-level6-face 'sylpheed-quote-level6-face) ;; syntax list (defvar sylpheed-font-lock-keywords (list ;; Quoted highlighting (list (concat "^" (regexp-opt sylpheed-quote-char-list t) " *\\(.*\\)$") '(1 font-lock-string-face t t) '(2 sylpheed-quote-level1-face t t)) (list (concat "^" (regexp-opt sylpheed-quote-char-list t) " *" (regexp-opt sylpheed-quote-char-list t) " *\\(.*\\)$") '(1 font-lock-string-face t t) '(2 font-lock-string-face t t) '(3 sylpheed-quote-level2-face t t)) (list (concat "^" (regexp-opt sylpheed-quote-char-list t) " *" (regexp-opt sylpheed-quote-char-list t) " *" (regexp-opt sylpheed-quote-char-list t) " *\\(.*\\)$") '(1 font-lock-string-face t t) '(2 font-lock-string-face t t) '(3 font-lock-string-face t t) '(4 sylpheed-quote-level3-face t t)) (list (concat "^" (regexp-opt sylpheed-quote-char-list t) " *" (regexp-opt sylpheed-quote-char-list t) " *" (regexp-opt sylpheed-quote-char-list t) " *" (regexp-opt sylpheed-quote-char-list t) " *\\(.*\\)$") '(1 font-lock-string-face t t) '(2 font-lock-string-face t t) '(3 font-lock-string-face t t) '(4 font-lock-string-face t t) '(5 sylpheed-quote-level4-face t t)) (list (concat "^" (regexp-opt sylpheed-quote-char-list t) " *" (regexp-opt sylpheed-quote-char-list t) " *" (regexp-opt sylpheed-quote-char-list t) " *" (regexp-opt sylpheed-quote-char-list t) " *" (regexp-opt sylpheed-quote-char-list t) " *\\(.*\\)$") '(1 font-lock-string-face t t) '(2 font-lock-string-face t t) '(3 font-lock-string-face t t) '(4 font-lock-string-face t t) '(5 font-lock-string-face t t) '(6 sylpheed-quote-level5-face t t)) (list (concat "^" (regexp-opt sylpheed-quote-char-list t) " *" (regexp-opt sylpheed-quote-char-list t) " *" (regexp-opt sylpheed-quote-char-list t) " *" (regexp-opt sylpheed-quote-char-list t) " *" (regexp-opt sylpheed-quote-char-list t) " *" (regexp-opt sylpheed-quote-char-list t) " *\\(.*\\)$") '(1 font-lock-string-face t t) '(2 font-lock-string-face t t) '(3 font-lock-string-face t t) '(4 font-lock-string-face t t) '(5 font-lock-string-face t t) '(6 font-lock-string-face t t) '(7 sylpheed-quote-level6-face t t)) ;; E-mail address highlighting (cons "[\-\.\+_/A-Za-z0-9]+@[\-\.A-Za-z0-9]+\\.[a-zA-Z][a-zA-Z]+" '(0 sylpheed-email-face t t)) ;; URL highlighting (cons "[A-Za-z]+://[\-\.\+_%&#?!=()@/A-Za-z0-9]+" '(0 sylpheed-address-face t t)) ;; Signature highlighting (cons (concat "^" sylpheed-sign-separator "[\r\n]+\\([\r\n]\\|.\\)*") '(0 sylpheed-signature-face t t)) )) ;; default keymap (if sylpheed-mode-map nil (setq sylpheed-mode-map (make-sparse-keymap)) (define-key sylpheed-mode-map [C-return] 'sylpheed-editing-end) (define-key sylpheed-mode-map "\C-c\C-g" 'sylpheed-insert-signature)) ;; ;; MODE MAIN FUNCTION ;; (defun sylpheed-mode () "Major mode for writing email with Sylpheed! This is UN-official major mode :-p # Sylpheed: http://sylpheed.good-day.net/ \\{sylpheed-mode-map} When turning on Sylpheed-mode, runs the normal hook `sylpheed-mode-hook'. This major mode provides two function: quoted text highlighting, and insert signature string. * User settings variables o `sylpheed-signature' o `sylpheed-sign-file' o `sylpheed-sign-separator' o `sylpheed-quote-char-list' o `sylpheed-encoding' * Define colors using highlight o `sylpheed-address-face' o `sylpheed-email-face' o `sylpheed-quote-level1-face' o `sylpheed-quote-level2-face' o `sylpheed-quote-level3-face' o `sylpheed-quote-level4-face' o `sylpheed-quote-level5-face' o `sylpheed-quote-level6-face'" (interactive) (kill-all-local-variables) (use-local-map sylpheed-mode-map) (setq local-abbrev-table sylpheed-mode-abbrev-table) (setq mode-name "Sylpheed") (setq major-mode 'sylpheed-mode) ; (set (make-local-variable 'font-lock-keywords-only) t) (set (make-local-variable 'font-lock-multiline) t) (set (make-local-variable 'font-lock-defaults) '(sylpheed-font-lock-keywords)) (set-buffer-file-coding-system sylpheed-encoding) (abbrev-mode t) (let ((map (make-sparse-keymap "Sylpheed"))) (define-key sylpheed-mode-map [menu-bar sylpheed] (cons "Sylpheed" map)) (define-key map [editing-end] '("Exit Emacs" . sylpheed-editing-end)) (define-key map [insert-signature] '("Insert Signature" . sylpheed-insert-signature))) (run-hooks 'sylpheed-mode-hook)) ;;;; highlighting signature phrase ;;(defun sylpheed-highlight-signature () ;; "search and highlight signature sentences" ;; (interactive) ;; (progn ;; (message "now %d" ;; (progn ;; (goto-char (point-max)) ;; (re-search-forward "^-- *$" nil nil -1) ;; (point))) ;; (next-line 1) ;; )) ;; insert signature to the end of mail body (defun sylpheed-insert-signature () "Insert signature. This function tries to insert a signature at the end of mail body. If the last line has any charactor, This function will be make a new line. After this, this executes 2 task. Firstly, to insert `sylpheed-sign-separator' and line-break charactor. Secondly, to insert a signature. The signature is detected by 2 variables: `sylpheed-sign-file' and `sylpheed-signature'. If having any charactor in `sylpheed-sign-file', it will be insert from the file which path is `sylpheed-sign-file'. If not set path in `sylpheed-sign-file', check to set some string in `sylpheed-signature'. `sylpheed-signature' has any string, will be insert `sylpheed-signature' string. However, it does not have any string, will be ask user to input signature string(use `read-string')." (interactive) (save-excursion ;; search end of mail body (goto-char (point-max)) (next-line -1) (next-line 1) ;; checking the last line having some charactor (if (not (= (point) (point-max))) (progn (goto-char (point-max)) (insert "\n")) nil) (insert (concat sylpheed-sign-separator "\n")) (if (< 0 (length sylpheed-sign-file)) (progn (insert-file sylpheed-sign-file) (message "Insert from local file")) (progn (insert sylpheed-signature) (message "Insert from sylpheed-signature variable") (if (= 0 (length sylpheed-signature)) (progn (goto-char (point-max)) (insert (read-string "Signature strings: "))) nil))) )) ;; exit Emacs editing (defvar sylpheed-exit-hook nil "Normal hook runs when exit `sylpheed-mode'.") (defun sylpheed-editing-end () "Finalization. This function has 3 tasks: runs `sylpheed-exit-hook', save buffer, and exit emacs. Sylpheed v2.2.0 makes new process for a new mail, so this function try to kill this process." (interactive) (progn (run-hooks 'sylpheed-exit-hook) (save-buffer) (save-buffers-kill-emacs))) ;;; end of sylpheed-mode.el