[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-womb] addressbook ChangeLog addressbook.el
From: |
Jose E. Marchesi |
Subject: |
[Commit-womb] addressbook ChangeLog addressbook.el |
Date: |
Sun, 06 May 2007 22:49:22 +0000 |
CVSROOT: /cvsroot/womb
Module name: addressbook
Changes by: Jose E. Marchesi <jemarch> 07/05/06 22:49:22
Modified files:
. : ChangeLog addressbook.el
Log message:
Summary buffer/window management.
New startup routine M-xaddressbook
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/addressbook/ChangeLog?cvsroot=womb&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/addressbook/addressbook.el?cvsroot=womb&r1=1.6&r2=1.7
Patches:
Index: ChangeLog
===================================================================
RCS file: /cvsroot/womb/addressbook/ChangeLog,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- ChangeLog 6 May 2007 18:16:42 -0000 1.7
+++ ChangeLog 6 May 2007 22:49:21 -0000 1.8
@@ -4,6 +4,14 @@
(addrbook-build-custom-property-group): New function.
(addrbook-set-custom-properties): New function.
(addrbook-set-custom-properties): Added doc string.
+ (addrbook-ask-for-search): New customizable variable.
+ (addrbook-attr-matches-p): New function.
+ (addrbook-search-cards): New function.
+ (addressbook-summary): Made non-interactive.
+ (addrbook-summary-get-current-card): New function.
+ (addrbook-summary-next-card): New function.
+ (addrbook-summary-previous-card): New function.
+ (addrbook-contact): New function.
2007-05-05 Xavier Maillard <address@hidden>
Index: addressbook.el
===================================================================
RCS file: /cvsroot/womb/addressbook/addressbook.el,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- addressbook.el 6 May 2007 18:16:42 -0000 1.6
+++ addressbook.el 6 May 2007 22:49:22 -0000 1.7
@@ -5,7 +5,7 @@
;; Maintainer: Jose E. Marchesi
;; Keywords: contacts, applications
-;; $Id: addressbook.el,v 1.6 2007/05/06 18:16:42 jemarch Exp $
+;; $Id: addressbook.el,v 1.7 2007/05/06 22:49:22 jemarch Exp $
;; This file is NOT part of GNU Emacs.
@@ -91,16 +91,10 @@
:type 'integer
:group 'addrbook)
-(defcustom addrbook-summary-format
- '("fn")
- "Fields in summary lines"
- :type 'sexp
- :group 'addrbook)
-
-(defcustom addrbook-summary-max-height
- 8
- "Maximum height of the summary buffer"
- :type 'integer
+(defcustom addrbook-ask-for-search
+ t
+ "Whether the addressbook should ask for a search upon `addressbook'
invocation"
+ :type 'boolean
:group 'addrbook)
(defface addrbook-summary-card-number
@@ -117,6 +111,34 @@
"Face for summary card numbers"
:group 'addrbook)
+(defface addrbook-summary-modified-flag
+ '((((min-colors 88) (class color) (background light))
+ :foreground "red1")
+ (((class color) (background light))
+ :foreground "red")
+ (((min-colors 88) (class color) (background dark))
+ :foreground "red")
+ (((class color) (background dark))
+ :foreground "red")
+ (t
+ :weight bold))
+ "Face for summary modified flag"
+ :group 'addrbook)
+
+(defface addrbook-summary-match-flag
+ '((((min-colors 88) (class color) (background light))
+ :foreground "brown")
+ (((class color) (background light))
+ :foreground "brown")
+ (((min-colors 88) (class color) (background dark))
+ :foreground "brown")
+ (((class color) (background dark))
+ :foreground "brown")
+ (t
+ :weight bold))
+ "Face for summary match flag"
+ :group 'addrbook)
+
(defface addrbook-properties-group-name
'((((min-colors 88) (class color) (background light))
:foreground "red1")
@@ -191,6 +213,24 @@
"Face for attribute values"
:group 'addrbook)
+(defface addrbook-summary-selected-card
+ '((((min-colors 88) (class color) (background light))
+ :background "grey"
+ :foreground "black")
+ (((class color) (background light))
+ :background "grey"
+ :foreground "black")
+ (((min-colors 88) (class color) (background dark))
+ :background "grey"
+ :foreground "black"
+ :weight bold)
+ (((class color) (background dark))
+ :weight bold)
+ (t
+ :weight bold))
+ "Face for selected summary contact line"
+ :group 'addrbook)
+
;;;; Variables
(defvar addrbook-image-types
@@ -384,12 +424,6 @@
'(("url" "value") ("content-id" "value"))
"General vCard parameters")
-(defvar addrbook-buffer nil
- "Actual addressbook buffer")
-
-(defvar addrbook-summary-buffer nil
- "Actual summary buffer")
-
(defvar addrbook-mode-line-string " AddressBook"
"String to display on the mode line when in the addressbook mode.
If `nil', do not show anything.")
@@ -630,7 +664,16 @@
(setcar (nthcdr 2 custom-group) props-data)))
-;;;; Display functions
+;;;; Addrbook contact
+
+(defun addrbook-contact ()
+ "Create a new addressbook buffer to show contact information"
+ (setq buffer (get-buffer-create addrbook-buffer-name))
+ (set-buffer buffer)
+ (addrbook-mode))
+
+(defun addrbook-show-contact ()
+ (switch-to-buffer-other-window (get-buffer addrbook-buffer-name)))
(defun addrbook-display-card (numcard)
"Display the NUMCARD card into the addressbook buffer"
@@ -1386,21 +1429,33 @@
(set-buffer-modified-p nil)
(message "addressbook saved"))))
-(defun addrbook-next-card ()
+(defun addrbook-next-contact ()
"Display the next card"
(interactive)
- (let (buffer-read-only)
+ (let (buffer-read-only window-list win)
(if (equal addrbook-current-card (- (length addrbook-cards) 1))
(message "No more cards")
- (addrbook-display-card (+ addrbook-current-card 1)))))
+ (addrbook-display-card (+ addrbook-current-card 1))
+ (let ((summary-buffer (get-buffer addrbook-summary-buffer)))
+ (when summary-buffer
+ (setq window-list (get-buffer-window-list summary-buffer nil t))
+ (dolist (win window-list)
+ (with-selected-window (get-buffer-window summary-buffer t)
+ (addrbook-summary-goto-contact addrbook-current-card nil))))))))
-(defun addrbook-previous-card ()
+(defun addrbook-previous-contact ()
"Display the previous card"
(interactive)
(let (buffer-read-only)
(if (equal addrbook-current-card 0)
(message "First card")
- (addrbook-display-card (- addrbook-current-card 1)))))
+ (addrbook-display-card (- addrbook-current-card 1))
+ (let ((summary-buffer (get-buffer addrbook-summary-buffer)))
+ (when summary-buffer
+ (setq window-list (get-buffer-window-list summary-buffer nil t))
+ (dolist (win window-list)
+ (with-selected-window (get-buffer-window summary-buffer t)
+ (addrbook-summary-goto-contact addrbook-current-card nil))))))))
(defun addrbook-quit ()
"Exit the addressbook"
@@ -1408,12 +1463,16 @@
(if (and (not (equal (length addrbook-modified-cards) 0))
(yes-or-no-p "Save addressbook? "))
(addrbook-save-cards nil))
+ (let ((contact-buffer (get-buffer addrbook-buffer-name))
+ (summary-buffer (get-buffer addrbook-summary-buffer-name)))
+ (if summary-buffer
+ (kill-buffer summary-buffer))
+ (if contact-buffer
(if (equal (length (window-list)) 1)
(progn
(kill-buffer addrbook-buffer)
(delete-frame))
- (kill-buffer-and-window))
- (setq addrbook-buffer nil))
+ (kill-buffer-and-window)))))
(defun addrbook-edit-attribute ()
(interactive)
@@ -1694,25 +1753,41 @@
;;;; Summary management
-(defun addrbook-summarize (&optional display raise)
+
+(defun addrbook-make-summary-buffer ()
+ (save-excursion
+ (let ((buffer (get-buffer-create addrbook-summary-buffer-name)))
+ (set-buffer buffer)
+ (addrbook-summary-mode)
+ (addrbook-display-summary)
+ (setq buffer-read-only t)
+ (setq addrbook-summary-buffer buffer)
+ buffer)))
+
+(defun addrbook-summary ()
+ "Open the addressbook and show the summary window"
+ (let ((buffer (get-buffer addrbook-summary-buffer-name)))
+ (when (not buffer)
+ (when (not (get-buffer addrbook-buffer-name))
+ (addrbook-open))
+ (setq buffer (addrbook-make-summary-buffer)))
+ (switch-to-buffer-other-window addrbook-summary-buffer)
+ (addrbook-summary-goto-contact 0 t)))
+
+(defun addrbook-summarize ()
"Summarize the contents of the addressbook in a summary buffer.
The format is as described in the variable `addrbook-summary-format'"
(interactive)
- (if (not addrbook-summary-buffer)
+ (if (not (get-buffer addrbook-summary-buffer-name))
(save-excursion
- (setq addrbook-summary-buffer (get-buffer-create
addrbook-summary-buffer-name))
- (set-buffer addrbook-summary-buffer)
- (addrbook-display-summary)
- (addrbook-summary-mode)))
+ (addrbook-get-create-summary-buffer)
+ (set-buffer (get-buffer addrbook-summary-buffer-name))
+ (addrbook-summary-goto-contact addrbook-current-card nil)))
(addrbook-show-summary))
(defun addrbook-show-summary ()
- (delete-other-windows)
- (split-window-vertically)
- (switch-to-buffer addrbook-summary-buffer)
- (fit-window-to-buffer nil addrbook-summary-max-height)
- (switch-to-buffer-other-window addrbook-buffer))
+ (switch-to-buffer-other-window (get-buffer addrbook-summary-buffer-name)))
(defun addrbook-get-create-summary-buffer ()
(if (not addrbook-summary-buffer)
@@ -1725,29 +1800,117 @@
(defun addrbook-display-summary ()
(erase-buffer)
- (let (i card attr spec-item)
- (dotimes (i (length addrbook-cards))
+ (let (card-index card name)
+ (dotimes (card-index (length addrbook-cards))
+ (insert " ")
(insert " ")
- (insert (propertize (number-to-string i)
+ (insert (propertize (number-to-string (+ card-index 1))
'face 'addrbook-summary-card-number)
" ")
- (insert (make-string (- 4 (length (number-to-string i))) ?\ ))
- (setq card (addrbook-get-card i))
- (dolist (spec-item addrbook-summary-format)
- (setq attr (vcard-get-named-attribute card spec-item))
- (cond ((equal spec-item "fn")
- (insert (propertize (addrbook-get-card-fn nil i)
- 'face 'addrbook-attribute-value)))
+ (insert (make-string (- 4 (length (number-to-string card-index))) ?\ ))
+ (setq card (addrbook-get-card card-index))
+ (setq name (vcard-get-named-attribute card "n"))
+ (insert (propertize (addrbook-get-card-fn t card-index)
+ 'face 'addrbook-attribute-value))
+ (insert (make-string (- 80 (- (point) (line-beginning-position))) ?\ ))
+ (add-text-properties (line-beginning-position)
+ (line-end-position)
+ (list 'card-index card-index))
+ (if (not (equal card-index (- (length addrbook-cards) 1)))
+ (insert (propertize "\n"
+ 'card-index card-index))))))
+
+(defun addrbook-summary-goto-contact (numcard update-contact-buffer)
+ (let (new-pos temp-new-pos found)
+ (remove-overlays (point-min) (point-max))
+ (if (equal (get-text-property (point-min) 'card-index) numcard)
+ (setq new-pos (point-min))
+ (setq temp-new-pos (point-min))
+ (while (and (not found)
+ (setq temp-new-pos (next-single-property-change temp-new-pos
'card-index)))
+ (when (equal (get-text-property temp-new-pos 'card-index) numcard)
+ (setq new-pos temp-new-pos)
+ (setq found t))))
+ (when new-pos
+ (goto-char new-pos)
+ (beginning-of-line)
+ (let ((highlight-overlay (make-overlay (line-beginning-position)
+ (line-end-position))))
+ (overlay-put highlight-overlay 'face 'addrbook-summary-selected-card))
+ (addrbook-summary-set-mode-line (+ numcard 1) (length addrbook-cards))
+ (when (and update-contact-buffer
+ (get-buffer addrbook-buffer-name))
+ (save-excursion
+ (set-buffer (get-buffer addrbook-buffer-name))
+ (addrbook-display-card numcard))))))
+
+(defun addrbook-summary-get-current-card ()
+ (get-text-property (point) 'card-index))
+
+(defun addrbook-summary-next-contact ()
+ "Select the next card in the summary buffer"
+ (interactive)
+ (let ((card-index (addrbook-summary-get-current-card)))
+ (cond
+ ((equal card-index (- (length addrbook-cards) 1))
+ (addrbook-summary-goto-contact 0 t))
(t
- (insert "fixme"))))
- (insert "\n"))))
+ (addrbook-summary-goto-contact (+ card-index 1) t)))))
-(defun addrbook-summary-goto (numcard)
- (goto-line (+ numcard 1))
- (forward-char 5)
- (addrbook-summary-set-mode-line (+ numcard 1)
- (+ (length addrbook-cards) 1)))
+(defun addrbook-summary-previous-contact ()
+ "Select the previous card in the summary buffer"
+ (interactive)
+ (let ((card-index (addrbook-summary-get-current-card)))
+ (cond
+ ((equal card-index 0)
+ (addrbook-summary-goto-contact (- (length addrbook-cards) 1) t))
+ (t
+ (addrbook-summary-goto-contact (- card-index 1) t)))))
+(defun addrbook-summary-show-contact ()
+ "Open an addressbook buffer to show the current selected card"
+ (interactive)
+ (let ((card-index (addrbook-summary-get-current-card)))
+ (when (not (get-buffer addrbook-buffer-name))
+ (save-excursion
+ (addrbook-contact)
+ (addrbook-display-card card-index)))
+ (addrbook-show-contact)))
+
+(defun addrbook-summary-quit ()
+ "Close the addressbook"
+ (interactive)
+ (addrbook-quit))
+
+;;;; Searching
+
+(defun addrbook-attr-matches-p (attr regexp)
+ (let (result value
+ (attr-values (vcard-attr-get-values attr)))
+ (if (listp attr-values)
+ (dolist (value attr-values)
+ (if (string-match regexp value)
+ (setq result t)))
+ (setq result (string-match regexp attr-values)))
+ result))
+
+(defun addrbook-search-cards (regexp &optional properties)
+ "Search for REGEXP in card data and return a list with the indexes
+of matching cards.
+
+PROPERTIES is a list of property names.
+If PROPERTIES is specified and non-nil, the search is performed only in those
+attributes."
+ (let (card prop attr card-index attr-index result)
+ (dotimes (card-index (length addrbook-cards))
+ (setq card (addrbook-get-card card-index))
+ (dotimes (attr-index (vcard-get-num-attributes card))
+ (setq attr (vcard-get-attribute card attr-index))
+ (if (and (or (not properties)
+ (member (vcard-attr-get-name attr) properties))
+ (addrbook-attr-matches-p attr regexp))
+ (add-to-list 'result card-index))))
+ (reverse result)))
@@ -1763,8 +1926,8 @@
(setq addrbook-mode-map (make-keymap))
(define-key addrbook-mode-map "c" 'addrbook-create-card)
(define-key addrbook-mode-map "D" 'addrbook-delete-card)
- (define-key addrbook-mode-map "n" 'addrbook-next-card)
- (define-key addrbook-mode-map "p" 'addrbook-previous-card)
+ (define-key addrbook-mode-map "n" 'addrbook-next-contact)
+ (define-key addrbook-mode-map "p" 'addrbook-previous-contact)
(define-key addrbook-mode-map "s" 'addrbook-save-cards)
(define-key addrbook-mode-map "x" 'addrbook-export-card)
(define-key addrbook-mode-map "q" 'addrbook-quit)
@@ -1791,8 +1954,10 @@
(interactive)
(kill-all-local-variables)
(setq addrbook-summary-mode-map (make-keymap))
- (define-key addrbook-summary-mode-map "n" 'addrbook-summary-next-card)
- (define-key addrbook-summary-mode-map "p" 'addrbook-summary-previous-card)
+ (define-key addrbook-summary-mode-map "n" 'addrbook-summary-next-contact)
+ (define-key addrbook-summary-mode-map "p" 'addrbook-summary-previous-contact)
+ (define-key addrbook-summary-mode-map "h" 'addrbook-summary-show-contact)
+ (define-key addrbook-summary-mode-map "q" 'addrbook-summary-quit)
(use-local-map addrbook-summary-mode-map)
(setq mode-name "AddressBook Summary")
(setq major-mode 'addrbook-summary-mode))
@@ -1801,22 +1966,33 @@
(defun addressbook ()
"Open the addressbook"
(interactive)
- (setq addrbook-modified-cards nil)
(if (and addrbook-force-addressbook-creation
(not (file-exists-p addrbook-file)))
(with-temp-file addrbook-file))
(catch 'exit
(let ((buffer (get-buffer addrbook-buffer-name)))
(when (not buffer)
+ (let ((show-card-index 0)
+ (user-input (when addrbook-ask-for-search
+ (read-from-minibuffer "Search for contact [RET
goes to the summary]: "))))
(unless (addrbook-open)
(throw 'exit t))
- (setq buffer (get-buffer-create addrbook-buffer-name))
- (set-buffer buffer)
- (addrbook-mode)
- (addrbook-display-card 0))
- (switch-to-buffer-other-window buffer)
+ (if (not (equal user-input ""))
+ (let ((found-cards (addrbook-search-cards user-input)))
+ (if found-cards
+ (setq show-card-index (car found-cards))
+ (message "No contacts found")
+ (throw 'exit t))
+ ;; Goto the first card with matched data
+ (addrbook-contact)
+ (addrbook-display-card show-card-index)
+ (setq addrbook-modified-cards nil)
+ (switch-to-buffer-other-window (get-buffer
addrbook-buffer-name))
(setq buffer-read-only t)
- (setq addrbook-buffer buffer))))
+ (setq addrbook-buffer buffer))
+ ;; Goto the summary
+ (addrbook-summary)))))))
+
;;;###autoload
(defun addressbook-create ()
@@ -1827,23 +2003,6 @@
(if new-card-index
(addrbook-save-cards nil))))
-;;;###autoload
-(defun addressbook-summary ()
- "Open the addressbook and show the summary window"
- (interactive)
- (catch 'exit
- (let ((buffer (get-buffer addrbook-summary-buffer-name)))
- (when (not buffer)
- (unless (addrbook-open)
- (throw 'exit t))
- (setq buffer (get-buffer-create addrbook-summary-buffer-name))
- (set-buffer buffer)
- (addrbook-summary-mode)
- (addrbook-display-summary)
- (addrbook-summary-goto 0))
- (switch-to-buffer-other-window buffer)
- (setq buffer-read-only t)
- (setq addrbook-summary-buffer buffer))))
(provide 'addressbook)
- [Commit-womb] addressbook ChangeLog addressbook.el, Jose E. Marchesi, 2007/05/04
- [Commit-womb] addressbook ChangeLog addressbook.el, Jose E. Marchesi, 2007/05/05
- [Commit-womb] addressbook ChangeLog addressbook.el, Jose E. Marchesi, 2007/05/05
- [Commit-womb] addressbook ChangeLog addressbook.el, Jose E. Marchesi, 2007/05/06
- [Commit-womb] addressbook ChangeLog addressbook.el, Jose E. Marchesi, 2007/05/06
- [Commit-womb] addressbook ChangeLog addressbook.el,
Jose E. Marchesi <=
- [Commit-womb] addressbook ChangeLog addressbook.el, Jose E. Marchesi, 2007/05/06
- [Commit-womb] addressbook ChangeLog addressbook.el, Jose E. Marchesi, 2007/05/07
- [Commit-womb] addressbook ChangeLog addressbook.el, Jose E. Marchesi, 2007/05/07
- [Commit-womb] addressbook ChangeLog addressbook.el, Jose E. Marchesi, 2007/05/07
- [Commit-womb] addressbook ChangeLog addressbook.el, Jose E. Marchesi, 2007/05/08
- [Commit-womb] addressbook ChangeLog addressbook.el, Jose E. Marchesi, 2007/05/08
- [Commit-womb] addressbook ChangeLog addressbook.el, Jose E. Marchesi, 2007/05/08
- [Commit-womb] addressbook ChangeLog addressbook.el, Jose E. Marchesi, 2007/05/08
- [Commit-womb] addressbook ChangeLog addressbook.el, Jose E. Marchesi, 2007/05/08
- [Commit-womb] addressbook ChangeLog addressbook.el, Jose E. Marchesi, 2007/05/08