: Looking for this pkg that allows you to find bbdb addresses from the
: unix shell prompt without starting emacs....
Here 'tis, updated for emacs 19:
Bng
;;; BBDB FROM THE SHELL!
;;; Boris Goldowsky, original version 7/92
;;; $Revision: 1.9 $ $Date: 94/01/21 08:18:45 $
;;;
;;; INSTALLATION:
;;; Adjust the pathnames in the 2nd and 3rd lines of code for your system.
;;; Then compile with the v.19 emacs byte compiler (It MUST be compiled!)
;;; Doing so will create an executable shell script in ~/bin/addr
;;; which will get BBDB entries from the shell (you can change the
;;; executable's file name in the second line of code).
;;;
;;; USAGE:
;;; from the shell prompt:
;;; addr regexp
;;; will look up REGEXP in your BBDB, and output matching records.
;;; addr user regexp
;;; will look it up in USER's BBDB instead.
(eval-when-compile
(let* ((shell-script-file (expand-file-name "~/bin/addr"))
(elisp-file (expand-file-name "~/emacs/lisp/bbdb-addr.el"))
(shell-script-buf (find-file-noselect shell-script-file))
(program
(concat "if [ $# -eq 2 ]\n"
"then\n"
" WHOSE=$1 REGEXP=$2;\n"
"else\n"
" WHOSE=$USER REGEXP=$1;\n"
"fi\n"
"exec emacs -batch -q -l " elisp-file "c $WHOSE $REGEXP\n")))
(save-excursion
(set-buffer shell-script-buf)
(if (string-equal program (buffer-string))
nil
(if (and (file-exists-p shell-script-file)
(not (y-or-n-p (format "Overwrite %s? " shell-script-file))))
(error "Shell script not created."))
(erase-buffer)
(insert program)
(save-buffer))
(set-file-modes shell-script-file 493)))) ; rwxr-xr-x
; We COMPILE with bbdb loaded, so that all the defsubst's get incorporated in,
; and we don't need to load it at runtime...
(eval-when-compile
(require 'bbdb)
(require 'bbdb-com))
;; Since we don't load bbdb when this code runs, we need to inline all
;; references to bbdb functions. The following definition comes
;; directly out of bbdb.el, except for the noted changes and the
;; replacement of the following functions (x...) with (inline (x...)):
;; bbdb-phone-string
;; bbdb-address-zip-string
;; others are inlined by default.
(defun bbdb-format-record (record &optional brief)
;; bbdb-debug call deleted
(let ((name (concat (elt record 0) " " (elt record 1))); only line I changed
(comp (bbdb-record-company record)))
(cond ((and name comp) (insert name " - " comp))
((or name comp) (insert (or name comp)))
(t (insert "???")))
(cond ((eq brief t)
(let ((p (point)))
(beginning-of-line)
(if (<= (- p (point)) 47)
(goto-char p)
(goto-char (+ (point) 44))
(setq p (point))
(end-of-line)
(delete-region p (point))
(insert "...")))
(let ((phone (car (bbdb-record-phones record)))
(net (car (bbdb-record-net record)))
(notes (bbdb-record-raw-notes record)))
(if (or phone net notes)
(progn (indent-to 48)
(insert (if notes ". " " "))))
(cond (phone (insert (inline (bbdb-phone-string phone)))
(indent-to 70)
(insert " ("); don't ask, it compiles better
(insert (bbdb-phone-location phone))
(insert ")"))
(net (insert net))))
(insert "\n"))
(t
(insert "\n")
(let* ((bbdb-elided-display brief) ;pfeh.
(aka (bbdb-record-aka record))
(phones (and (bbdb-field-shown-p 'phone)
(bbdb-record-phones record)))
(addrs (and (bbdb-field-shown-p 'address)
(bbdb-record-addresses record)))
phone)
(while phones
(setq phone (car phones))
(insert (format " %14s: " (bbdb-phone-location phone)))
(insert (inline (bbdb-phone-string phone)) "\n")
(setq phones (cdr phones)))
(let (addr c s)
(while addrs
(setq addr (car addrs))
(insert (format " %14s: " (bbdb-address-location addr)))
(if (= 0 (length (setq s (bbdb-address-street1 addr)))) nil
(indent-to 17) (insert s "\n"))
(if (= 0 (length (setq s (bbdb-address-street2 addr)))) nil
(indent-to 17) (insert s "\n"))
(if (= 0 (length (setq s (bbdb-address-street3 addr)))) nil
(indent-to 17) (insert s "\n"))
(indent-to 17)
(insert (setq c (bbdb-address-city addr)))
(setq s (bbdb-address-state addr))
(if (and (> (length c) 0) (> (length s) 0)) (insert ", "))
(insert s " ")
(insert (inline (bbdb-address-zip-string addr)) "\n")
(setq addrs (cdr addrs))))
(if (and (bbdb-record-net record)
(bbdb-field-shown-p 'net))
(insert (format " %14s: %s\n" "net"
(mapconcat (function identity)
(bbdb-record-net record)
", "))))
(if (and aka
(bbdb-field-shown-p 'aka))
(insert (format " %14s: %s\n" "AKA"
(mapconcat (function identity)
aka ", "))))
(let ((notes (bbdb-record-raw-notes record)))
(if (stringp notes)
(setq notes (list (cons 'notes notes))))
(while notes
(if (bbdb-field-shown-p (car (car notes)))
(progn
(insert (format " %14s: " (car (car notes))))
(let ((p (point)))
(insert (cdr (car notes)))
(save-excursion
(save-restriction
(narrow-to-region p (1- (point)))
(goto-char (1+ p))
(while (search-forward "\n" nil t)
(insert (make-string 17 ?\ )))))
(insert "\n"))))
(setq notes (cdr notes)))))
(insert "\n")))))
(defun message-buffer (buf)
"Output each line of BUFFER as a message.
Useful to output stuff in batch-mode."
(save-excursion
(set-buffer buf)
(goto-char (point-min))
(let (begin)
(while (not (eobp))
(setq begin (point))
(beginning-of-line 2)
(message "%s" (buffer-substring begin (1- (point))))))))
(defun fake-bbdb (regexp)
(set-buffer (find-file-noselect
(expand-file-name
(concat "~" (elt command-line-args
(- (length command-line-args) 2))
"/.bbdb"))))
(let ((bbdb-buf (current-buffer))
(outbuf (get-buffer-create "output")))
(goto-char (point-min))
(while (re-search-forward regexp (point-max) t)
(beginning-of-line)
(let ((record (read (current-buffer))))
(set-buffer outbuf)
(bbdb-format-record record)
(set-buffer bbdb-buf))
(beginning-of-line 2))
(message-buffer outbuf)))
(fake-bbdb (elt command-line-args (- (length command-line-args) 1)))