summaryrefslogtreecommitdiff
path: root/bits/bbdb-adapt-ispell.el
blob: e3745376d91de8b5d9809bf53f9dda20727ce8b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
;;; bbdbadapt-ispell.el --- Use the BBDB to insert a  gcc field

;; Copyright (C) 2009 Uwe Brauer

;; Author: Uwe Brauer oub@mat.ucm.es
;; Maintainer: Uwe Brauer oub@mat.ucm.es
;; Created: 17 Mar 2009
;; Version: 1.0
;; Keywords:

 
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 1, or (at your option)
;; any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; A copy of the GNU General Public License can be obtained from this
;; program's author (send electronic mail to oub@mat.ucm.es) or from
;; the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
;; 02139, USA.

;; LCD Archive Entry:
;; bbdbadpt-gcc|Uwe Brauer|oub@mat.ucm.es
;; |Use the BBDB to insert a  gcc field
;; |Date|Revision|~/packages/bbdbadpt-gcc.el

;;; Commentary:
;; I wanted to have the ispell dict selected 
;; based on a relevant bbdb entry which I call ispell-dict.
;; This is what the code does. 

;; The starting point was some code provided to me by Robert
;; Fenk. However the problem with that code was that it took the gcc
;; field from some entry of the BBDB buffer and if there was more than
;; on entry often the wrong string was inserted. So I had to use code
;; which extracted the correct BBDB entry from the TO field .  I
;; succeeded by using to a large extend code from sigadapt.el written
;; by by C.Queinnec (University of Paris 6 & INRIA)
;; 

;;; Change log:
;; Revision 1.1  2009/03/17 17:27:31  oub
;; Initial revision
;;
;; Revision 1.2  2009/03/17 16:50:20  oub
;; modify the central function
;;
;; Revision 1.1  2009/03/17 16:32:26  oub
;; Initial revision
;;

;;; Code:




(defun bbdbispelladpt-search-record (to)
  "Search a BBDB record associated to TO or return NIL."
  (let* ((data (mail-extract-address-components to))
         (name (car data))
         (net  (car (cdr data))))
    (if (equal name net) (setq name nil))
    (if (and net bbdb-canonicalize-net-hook)
        (setq net (bbdb-canonicalize-address net)))
    (bbdb-search-simple name net)))

(defun bbdbispelladpt-try-bbdbispell-new ()
  "Try to adapt non-interactively the current bbdbispell. 
This function looks silently in the current message to find how to
choose the bbdbispell. It does nothinng if not enough information is
present. This function is useful in a hook."
  (save-excursion
    (condition-case nil
        (progn
          (goto-char (point-min))
          (let ((record (bbdbispelladpt-search-record 
                         (bbdb-extract-field-value "To"))))
			(if record
				(let ((signame (bbdbispelladpt-retrieve-bbdbispell record)))
				  (when (and (stringp signame) (string= signame "castellano8"))
					(ispell-change-dictionary    "castellano8"       nil))
			  (when (and (stringp signame) (string= signame "english"))
				(ispell-change-dictionary "american" nil	))
			  (when (and (stringp signame) (string= signame "deutsch"))
				(ispell-change-dictionary "deutsch8" nil))
			  (when (and (stringp signame) (string= signame "french"))
				(ispell-change-dictionary "francais" nil)))))))))




(defun bbdbispelladpt-retrieve-bbdbispell (&optional record) 
  "Retrieve the bbdbispell (a symbol) associated to a mailee.
The search is done through a BBDB record. "
  (if (not record)
      (save-excursion
        (goto-char (point-min))
        (let* ((to  (bbdb-extract-field-value "To"))
               (rec (bbdbispelladpt-search-record to)) )
          (if rec (bbdbispelladpt-do-retrieve-bbdbispell rec)
            (progn (message "No bound record")
                   nil))))
    (bbdbispelladpt-do-retrieve-bbdbispell record) ) )

(defun bbdbispelladpt-do-retrieve-bbdbispell (record)
  (let ((signame
	 (bbdb-record-getprop record 'ispell-dict)))
    (if (stringp signame)
        (setq signame signame))
    signame))


(provide 'bbdbadapt-ispell)

;;; BBDBADPT-ISPELL.EL ends here