summaryrefslogtreecommitdiff
path: root/elisp/erbot/erbedit.el
blob: 88314448fef292fc049123862ae68319bf5bc38b (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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
;;; erbedit.el --- quicker operator editing of bots' bbdb
;; Time-stamp: <2007-11-23 11:30:12 deego>
;; Copyright (C) 2003 D. Goel
;; Emacs Lisp Archive entry
;; Filename: erbedit.el
;; Package: erbedit
;; Author: D. Goel <deego@gnufans.org>
;; Keywords:  
;; Version:  
;; URL:  http://www.emacswiki.org/cgi-bin/wiki.pl?ErBot
;; For latest version: 

(defconst erbedit-home-page
  "http://gnufans.net/~deego")


 
;; This file is NOT (yet) part of GNU Emacs.
 
;; This 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 3, or (at your option)
;; any later version.
 
;; This 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.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
 


(defconst erbedit-version "0.0dev")

;;==========================================
;;; Requires:
(eval-when-compile (require 'cl))

;;; Code:

(defgroup erbedit nil 
  "The group erbedit."
  :group 'applications)
(defcustom erbedit-before-load-hook nil 
  "Hook to run before loading erbedit."
  :group 'erbedit)
(defcustom erbedit-after-load-hook nil 
  "Hook to run after loading erbedit."
  :group 'erbedit)
(run-hooks 'erbedit-before-load-hook)

(defcustom erbedit-verbosity 0
  "How verbose to be.  
Once you are experienced with this lib, 0 is the recommended
value.  Values between -90 to +90 are \"sane\".  The
rest are for debugging."
  :type 'integer
  :group 'erbedit)
(defcustom erbedit-interactivity 0
  "How interactive to be.  
Once you are experienced with this lib, 0 is the recommended
value.  Values between -90 and +90 are \"sane\".  The rest are for
debugging."
  :type 'integer
  :group 'erbedit)
(defcustom erbedit-y-or-n-p-function 'erbedit-y-or-n-p
  "Function to use for interactivity-dependent  `y-or-n-p'.
Format same as that of `erbedit-y-or-n-p'."
  :type 'function
  :group 'erbedit)
(defcustom erbedit-n-or-y-p-function 'erbedit-y-or-n-p
  "Function to use for interactivity-dependent `n-or-y-p'.
Format same as that of `erbedit-n-or-y-p'."
  :type 'function
  :group 'erbedit)
(defun erbedit-message (points &rest args)
  "Signal message, depending on POINTS anderbedit-verbosity.
ARGS are passed to `message'."
  (unless (minusp (+ points erbedit-verbosity))
    (apply #'message args)))
(defun erbedit-y-or-n-p (add prompt)
  "Query or assume t, based on `erbedit-interactivity'.
ADD is added to `erbedit-interactivity' to decide whether
to query using PROMPT, or just return t."
  (if (minusp (+ add erbedit-interactivity))
        t
      (funcall 'y-or-n-p prompt)))
(defun erbedit-n-or-y-p (add prompt)
  "Query or assume t, based on `erbedit-interactivity'.
ADD is added to `erbedit-interactivity' to decide whether
to query using PROMPT, or just return t."
  (if (minusp (+ add erbedit-interactivity))
        nil
      (funcall 'y-or-n-p prompt)))

;;; Real Code:



(provide 'erbedit)
(run-hooks 'erbedit-after-load-hook)


(defun erbedit-replace-string (from to)
  "Like fs-replace-string, but acts across the entire bbdb"
  "Forget all terms containing occurrence of regexp REG. 

REMINDER: DO NOT FORGET TO exclude terms like fsbot hbot erbot deego
Deepak (author) <and of courser, terms like emacs> in prevent-reg
when using this command.
\\(bot\\|emacs\\|deego\\|goel\\|deepak\\|alex\\|bpt\\|oddmuse\\|iam\\)
.. for example..
"
  (let* 
      ((lenterms
	(fs-search-basic (regexp-quote from)
			 nil nil 'describe))
       (len (first lenterms))
       (terms (second lenterms)))
    (cond
     ((= len 0 ) (message "No terms. "))
     (t 
      (when (y-or-n-p (format "Act on these %S terms? " len))
	(erbedit-replace-string-slowly terms from to))))))

(defun erbedit-replace-string-slowly (terms from to)
  (let 
      ((len (length terms))
       (ctr 0)
       thisterm 
       skipp
       notes
       )
    (while terms
      (setq thisterm (car terms) terms (cdr terms))
      (setq ctr (+ ctr 1))
      (message "Acting on term %S of %S: %S" ctr len thisterm)
      (sleep-for 0.1)
      (fs-replace-string from to thisterm "all")
      (message "Acting on term %S of %S: %S ... done" ctr len thisterm)
      (sleep-for 0.1)
      )))



;;; erbedit.el ends here