Commits

jason kirtland committed bef8161

Checkpoint; lots of changes.

Comments (0)

Files changed (46)

 aside/
 
 backups/
+var/
 auto-save-list/
 tramp
-recent-files
+customizations-private\.el
+url/
 
 # external repositories
 js2-mode/
 nxhtml/
 python-mode/
 yasnippet/
+drag-stuff/
+emacs-w3m/
+eproject/
+python-mode-src/
+anything-config/
+org-mode/
+org-\d+\.\d+/
+org-icons/
+
 
 auto-complete
 color-theme-.*

customizations.el

   ;; If you edit it by hand, you could mess it up, so be careful.
   ;; Your init file should contain only one such instance.
   ;; If there is more than one, they won't work right.
+ '(ac-auto-start 3)
+ '(ac-trigger-key "<C-tab>")
+ '(adaptive-fill-mode nil)
  '(aquamacs-additional-fontsets nil t)
  '(aquamacs-customization-version-id 172 t)
+ '(bmkp-auto-light-when-jump (quote any-bookmark))
+ '(bmkp-bmenu-commands-file "~/.emacs.d/var/bmk-bmenu-commands.el")
+ '(bmkp-bmenu-state-file "~/.emacs.d/var/bmk-bmenu-state.el")
+ '(bmkp-prompt-for-tags-flag t)
+ '(buffer-stack-show-position (quote buffer-stack-show-position-buffers))
  '(column-number-mode t)
  '(confirm-kill-emacs (quote y-or-n-p))
  '(dabbrev-case-fold-search nil)
  '(default-frame-alist (quote ((tool-bar-lines . 0) (menu-bar-lines . 1) (foreground-color . "Black") (background-color . "White") (cursor-type . box) (cursor-color . "Red") (fringe) (left-fringe . 5) (right-fringe . 5))))
  '(enable-recursive-minibuffers nil)
+ '(eproject-completing-read-function (quote eproject--ido-completing-read))
  '(espresso-indent-level 4)
  '(flymake-allowed-file-name-masks (quote (("\\.py" flymake-pycheckers-init))))
  '(focus-follows-mouse nil)
  '(global-hl-line-mode t)
+ '(ibuffer-display-summary nil)
+ '(ibuffer-eliding-string "…")
+ '(ido-everywhere t)
+ '(ido-max-prospects 8)
+ '(ido-mode (quote both) nil (ido))
+ '(ido-save-directory-list-file "~/.emacs.d/var/ido.last")
+ '(ido-use-url-at-point t)
  '(iedit-occurrence-face (quote match))
  '(indent-tabs-mode nil)
  '(indicate-buffer-boundaries (quote left))
  '(indicate-empty-lines t)
  '(inhibit-startup-screen t)
  '(initial-buffer-choice "~/TODO")
+ '(markdown-command "~/bin/markdown")
+ '(org-src-fontify-natively t)
+ '(org-todo-keywords (quote ((sequence "TODO" "DONE" "WAITING" "SOMEDAY"))))
  '(overflow-newline-into-fringe t)
  '(pabbrev-read-only-error nil)
+ '(pocoo-always-private t)
  '(py-continuation-offset 2)
+ '(py-import-check-point-max 200)
  '(python-continuation-offset 2)
  '(recentf-mode t)
- '(recentf-save-file "~/.emacs.d/recent-files")
+ '(recentf-save-file "~/.emacs.d/var/recent-files")
  '(require-final-newline nil)
  '(scroll-bar-mode nil)
  '(show-paren-mode t)
  '(show-trailing-whitespace t)
+ '(simplenote-directory "/Users/jek/.emacs.d/var/simplenote/")
+ '(simplenote-email "jek@discorporate.us")
+ '(simplenote-notes-mode (quote markdown-mode))
+ '(simplenote-password "agbd2LSB.snc")
  '(todoo-file-name "~/TODO")
  '(track-eol t)
  '(truncate-partial-width-windows nil)
  '(uniquify-buffer-name-style (quote reverse) nil (uniquify))
  '(uniquify-separator ":")
- '(vline-face (quote hl-line)))
+ '(visible-mark-faces (quote (visible-mark-face-5 visible-mark-face-4 visible-mark-face-3 visible-mark-face-2 visible-mark-face)))
+ '(visible-mark-max 5)
+ '(visual-line-fringe-indicators (quote (left-curly-arrow nil)))
+ '(vline-face (quote hl-line))
+ '(w3m-arrived-file "/Users/jek/.emacs.d/var/w3m/.arrived")
+ '(w3m-bookmark-file "/Users/jek/.emacs.d/var/w3m/bookmark.html")
+ '(w3m-default-save-directory "~/Downloads")
+ '(w3m-form-textarea-directory "/Users/jek/.emacs.d/var/w3m/.textarea")
+ '(w3m-init-file "~/.emacs.d/var/w3m-init")
+ '(w3m-profile-directory "~/.emacs.d/var/w3m")
+ '(w3m-session-file "/Users/jek/.emacs.d/var/w3m/.sessions")
+ '(w3m-use-cookies t))
 (custom-set-faces
   ;; custom-set-faces was added by Custom.
   ;; If you edit it by hand, you could mess it up, so be careful.
   ;; If there is more than one, they won't work right.
  '(diff-added ((t (:inherit diff-changed :foreground "blue"))))
  '(diff-removed ((t (:inherit diff-changed :foreground "red"))))
+ '(dropdown-list-selection-face ((t (:inherit region))))
  '(flyspell-duplicate ((t (:foreground "Gold3" :underline t))))
  '(flyspell-incorrect ((t (:foreground "OrangeRed" :underline t))))
  '(fringe ((((class color) (background light)) (:background "grey97"))))
  '(mode-line ((((class color) (min-colors 88)) (:background "grey75" :foreground "black" :box (:line-width -1 :style released-button) :height 1.1 :family "optima"))))
+ '(py-builtins-face ((t (:foreground "indian red"))) t)
+ '(py-exception-name-face ((t (:foreground "firebrick" :weight bold))) t)
+ '(py-pseudo-keyword-face ((t (:foreground "dodger blue"))) t)
  '(rst-mode-default ((t (:inherit text-mode-default :slant normal :weight normal :height 120 :family "monaco"))) t)
  '(sml-modeline-end-face ((t nil)))
  '(sml-modeline-vis-face ((t nil)))
- '(trailing-whitespace ((((class color) (background light)) (:background "#eeeeaa")))))
+ '(trailing-whitespace ((((class color) (background light)) (:background "#eeeeaa"))))
+ '(visible-mark-face ((((class color) (background light)) (:background "yellow")))))
 
 (put 'downcase-region 'disabled nil)
+EMACS=~/Applications/Emacs.app/Contents/MacOS/Emacs -q --no-site-file
+export LOAD_PATH=auto-complete:bookmarkp:emacs-goodies-el:emacs-w3m:eproject:yasnippet
+
+BLACKLIST = fringe-helper.el buffer-stack.el
+ELS = $(filter-out $(BLACKLIST),$(shell ls -1 *.el))
+ELCS = $(ELS:.el=.elc)
+
+all: $(ELCS)
+	make $(ELCS)
+
+autoloads: install.el
+	emacs -q --no-site-file -batch -L . -l install.el \
+		-eval '(install-update-autoloads "autoloads")'
+
+.el.elc:
+	$(EMACS) -batch -L . \
+		-eval "(setq max-lisp-eval-depth 1500 max-specpdl-size 3000)" \
+		-eval "(mapc (lambda (dir) (add-to-list 'load-path dir)) (parse-colon-path (getenv \"LOAD_PATH\")))" \
+		-f batch-byte-compile $*.el
+
 ;;; autopair.el --- Automagically pair braces and quotes like TextMate
 
-;; Copyright (C) 2009 Joao Tavora
+;; Copyright (C) 2009,2010 Joao Tavora
 
 ;; Author: Joao Tavora <joaotavora [at] gmail.com>
 ;; Keywords: convenience, emulations
 ;; X-URL: http://autopair.googlecode.com
 ;; URL: http://autopair.googlecode.com
 ;; EmacsWiki: AutoPairs
-;; Version: 0.3
+;; Version: 0.4
 ;; Revision: $Rev$ ($LastChangedDate$)
 
 ;; This program is free software; you can redistribute it and/or modify
 ;; If you find the paren-blinking annoying, turn `autopair-blink' to
 ;; nil.
 ;;
+;; For lisp-programming you might also like `autopair-skip-whitespace'.
+;;
 ;; For further customization have a look at `autopair-dont-pair',
 ;; `autopair-handle-action-fns' and `autopair-extra-pair'.
 ;;
 ;;                     (list #'autopair-default-handle-action
 ;;                           #'autopair-python-triple-quote-action))))
 ;;
+;; It's also useful to deal with latex's mode use of the "paired
+;; delimiter" syntax class.
+;;
+;; (add-hook 'latex-mode-hook
+;;           #'(lambda ()
+;;               (set (make-local-variable 'autopair-handle-action-fns)
+;;                    (list #'autopair-default-handle-action
+;;                          #'autopair-latex-mode-paired-delimiter-action))))
+;;
 ;; `autopair-extra-pairs' lets you define extra pairing and skipping
 ;; behaviour for pairs not programmed into the syntax table. Watch
 ;; out, this is work-in-progress, a little unstable and does not help
 ;;; Bugs:
 ;;
 ;; * Quote pairing/skipping inside comments is not perfect...
-;; * Autopair is perfectly compatible with `delete-selection-mode'. To
-;;   do so, add the following to your .emacs.
-;; 
-;;   (put 'autopair-insert-opening 'delete-selection t)
-;;   (put 'autopair-skip-close-maybe 'delete-selection t)
-;;   (put 'autopair-insert-or-skip-quote 'delete-selection t)
-;;   (put 'autopair-extra-insert-opening 'delete-selection t)
-;;   (put 'autopair-extra-skip-close-maybe 'delete-selection t)
-;;   (put 'autopair-backspace 'delete-selection 'supersede)
-;;   (put 'autopair-newline 'delete-selection t)
 ;;
-;;  you will, however, lose the `autopair-autowrap'
-;;  behaviour. Autopair is compatible with `cua-mode' though, which
-;;  also provides the same behaviour.
+;; * See the last section on monkey-patching for the `defadvice'
+;;   tricks used to make `autopair-autowrap' work with `cua-mode' and
+;;   `delete-selection-mode'.
 ;;
 ;;; Credit:
 ;;
 
 ;; variables
 (defvar autopair-pair-criteria 'help-balance
-  "If non-nil, be more criterious when pairing opening brackets.")
+  "How to decide whether to pair opening brackets or quotes.
+
+Set this to 'always to always pair, or 'help-balance to be more
+criterious when pairing.")
 
 (defvar autopair-skip-criteria 'help-balance
-  "If non-nil, be more criterious when skipping closing brackets.")
+  "How to decide whether to skip closing brackets or quotes.
+
+Set this to 'always to always skip, or 'help-balance to be more
+criterious when skipping.")
 
 (defvar autopair-emulation-alist nil
   "A dinamic keymap for autopair set mostly from the current
 
 
 Note that this does *not* work for single characters,
-e.x. characters you want to behave as quotes.  To have quote-like
-behaviour consider using something else, for example:
+e.x. characters you want to behave as quotes.  See the
+docs/source comments for more details.")
 
-(add-hook 'latex-mode-hook
-          #'(lambda ()
-              (modify-syntax-entry ?$ \"\\\"\")))
-
-")
 (make-variable-buffer-local 'autopair-extra-pairs)
 
 (defvar autopair-dont-pair `(:string (?') :comment  (?'))
 three elements are (ACTION PAIR POS-BEFORE).
 
 ACTION is one of `opening', `insert-quote', `skip-quote',
-`backspace' or `newline'. PAIR is the pair of `last-input-event'
-delimiter. POS-BEFORE is value of point before action command
-took place .")
+`backspace', `newline' or `paired-delimiter'. PAIR is the pair of
+the `autopair-inserted' character, if applicable. POS-BEFORE is
+value of point before action command took place .")
 
 
 (defvar autopair-wrap-action nil
 to specify special behaviour. To also run the default behaviour,
 be sure to include `autopair-default-handle-action' in the
 list, or call it from your handlers.")
+(make-variable-buffer-local 'autopair-handle-action-fns)
 
 (defvar autopair-handle-wrap-action-fns '()
   "Autopair wrap handlers to run *instead* of the default handler.
 variable to specify special behaviour. To also run the default
 behaviour, be sure to include `autopair-default-handle-wrap-action' in
 the list, or call it in your handlers.")
+(make-variable-buffer-local 'autopair-handle-wrap-action-fns)
+
+(defvar autopair-inserted nil
+  "Delimiter inserted by last interactive autopair command.
+
+This is calculated with `autopair-calculate-inserted', which see.")
+
+(defun autopair-calculate-inserted ()
+  "Attempts to guess the delimiter the current command is inserting.
+
+For now, simply returns `last-command-event'"
+  last-command-event)
 
 ;; minor mode and global mode
 ;;
 (define-globalized-minor-mode autopair-global-mode autopair-mode autopair-on)
 
-(defun autopair-on () (unless autopair-dont-activate (autopair-mode 1)))
+(defun autopair-on () (unless (or buffer-read-only autopair-dont-activate) (autopair-mode 1)))
 
 (define-minor-mode autopair-mode
   "Automagically pair braces and quotes like in TextMate."
            (define-key map (kbd "DEL") 'autopair-backspace)
            (define-key map (kbd "RET") 'autopair-newline)
            (dotimes (char 256) ;; only searches the first 256 chars,
-                               ;; TODO: is this enough/toomuch/stupid?
+             ;; TODO: is this enough/toomuch/stupid?
              (unless (member char
                              (getf autopair-dont-pair :never))
                (let* ((syntax-entry (aref (syntax-table) char))
                       (pair (and syntax-entry
                                  (cdr syntax-entry))))
                  (cond ((eq class (car (string-to-syntax "(")))
+                        ;; syntax classes "opening parens" and "close parens"
                         (define-key map (string char) 'autopair-insert-opening)
                         (define-key map (string pair) 'autopair-skip-close-maybe))
-                       ((or (eq class (car (string-to-syntax "\"")))
-                            (eq class (car (string-to-syntax "$"))))
-                        (define-key map (string char) 'autopair-insert-or-skip-quote))))))
+                       ((eq class (car (string-to-syntax "\"")))
+                        ;; syntax class "string quote
+                        (define-key map (string char) 'autopair-insert-or-skip-quote))
+                       ((eq class (car (string-to-syntax "$")))
+                        ;; syntax class "paired-delimiter" 
+                        ;;
+                        ;; Apropos this class, see Issues 18, 25 and
+                        ;; elisp info node "35.2.1 Table of Syntax
+                        ;; Classes". The fact that it supresses
+                        ;; syntatic properties in the delimited region
+                        ;; dictates that deciding to autopair/autoskip
+                        ;; can't really be as clean as the string
+                        ;; delimiter.
+                        ;;
+                        ;; Apparently, only `TeX-mode' uses this, so
+                        ;; the best is to bind this to
+                        ;; `autopair-insert-or-skip-paired-delimiter'
+                        ;; which defers any decision making to
+                        ;; mode-specific post-command handler
+                        ;; functions.
+                        ;;
+                        (define-key map (string char) 'autopair-insert-or-skip-paired-delimiter))))))
            ;; read `autopair-extra-pairs'
            (dolist (pairs-list (remove-if-not #'listp autopair-extra-pairs))
              (dolist (pair pairs-list)
                  quick-syntax-info)))))
 
 (defun autopair-find-pair (delim)
-  (when delim
+  (when (and delim
+             (integerp delim))
     (let ((syntax-entry (aref (syntax-table) delim)))
       (cond ((eq (syntax-class syntax-entry) (car (string-to-syntax "(")))
              (cdr syntax-entry))
-            ((eq (syntax-class syntax-entry) (car (string-to-syntax "\"")))
+            ((or (eq (syntax-class syntax-entry) (car (string-to-syntax "\"")))
+                 (eq (syntax-class syntax-entry) (car (string-to-syntax "$"))))
              delim)
             ((eq (syntax-class syntax-entry) (car (string-to-syntax ")")))
              (cdr syntax-entry))
                              pair-list))
                    (remove-if-not #'listp autopair-extra-pairs)))))))
 
-(defun autopair-set-wrapping-action ()
-  (when mark-active
+(defun autopair-calculate-wrap-action ()
+  (when (region-active-p)
     (save-excursion
       (let* ((region-before (cons (region-beginning)
                                   (region-end)))
              (end-syntax   (syntax-ppss (cdr region-before))))
         (when (and (eq (nth 0 start-syntax) (nth 0 end-syntax))
                    (eq (nth 3 start-syntax) (nth 3 end-syntax)))
-          (setq autopair-wrap-action (list 'wrap (or (second autopair-action)
-                                                     (autopair-find-pair last-input-event))
-                                           point-before
-                                           region-before)))))))
+          (list 'wrap (or (second autopair-action)
+                          (autopair-find-pair autopair-inserted))
+                point-before
+                region-before))))))
+
+(defun autopair-original-binding ()
+  (or (key-binding `[,autopair-inserted])
+      (key-binding (this-single-command-keys))
+      (key-binding fallback-keys)))
 
 (defun autopair-fallback (&optional fallback-keys)
   (let* ((autopair-emulation-alist nil)
          (beyond-cua (let ((cua--keymap-alist nil))
-                       (or (key-binding (this-single-command-keys))
-                           (key-binding fallback-keys))))
-         (beyond-autopair (or (key-binding (this-single-command-keys))
-                              (key-binding fallback-keys))))
+                       (autopair-original-binding)))
+         (beyond-autopair (autopair-original-binding)))
     (when autopair-autowrap
-      (autopair-set-wrapping-action))
+      (setq autopair-wrap-action (autopair-calculate-wrap-action)))
     
     (setq this-original-command beyond-cua)
     ;; defer to "paredit-mode" if that is installed and running
 
 This is also done in an optimistic \"try-to-balance\" fashion.")
 
+(defvar autopair-skip-whitespace nil
+  "If non-nil also skip over whitespace when skipping closing delimiters.
+
+This will be most useful in lisp-like languages where you want
+lots of )))))....")
+
 (defvar autopair-blink (if (boundp 'blink-matching-paren)
                            blink-matching-paren
                          t)
 (defun autopair-exception-p (where-sym exception-where-sym blacklist &optional fn)
   (and (or (eq exception-where-sym :everywhere)
            (eq exception-where-sym where-sym))
-       (member last-input-event
+       (member autopair-inserted
                (if fn
                    (mapcar fn (getf blacklist exception-where-sym))
                  (getf blacklist exception-where-sym)))))
       (let ((howmany (car syntax-info))
             (retval (cons (point)
                           (point))))
-        (while (and (/= howmany 0)
+        (while (and (> howmany 0)
                     (condition-case err
                         (progn
                           (scan-sexps (point) (- (point-max)))
 ;; 
 (defun autopair-insert-or-skip-quote ()
   (interactive)
+  (setq autopair-inserted (autopair-calculate-inserted))
   (let* ((syntax-triplet (autopair-syntax-ppss))
          (syntax-info (first syntax-triplet))
          (where-sym (second syntax-triplet))
     (cond (;; decides whether to skip the quote...
            ;;
            (and (not escaped-p)
-                (eq last-input-event (char-after (point)))
+                (eq autopair-inserted (char-after (point)))
                 (or
                  ;; ... if we're already inside a string and the
                  ;; string starts with the character just inserted,
                  ;; or it's a generically terminated string
                  (and inside-string
                       (or (eq inside-string t)
-                          (eq last-input-event inside-string)))
+                          (eq autopair-inserted inside-string)))
                  ;; ... if we're in a comment and ending a string
                  ;; (the inside-string criteria does not work
                  ;; here...)
                  (and (eq where-sym :comment)
                       (condition-case nil
-                          (eq last-input-event (char-after (scan-sexps (1+ (point)) -1)))
+                          (eq autopair-inserted (char-after (scan-sexps (1+ (point)) -1)))
                         (error nil)))))
-           (setq autopair-action (list 'skip-quote last-input-event (point))))
+           (setq autopair-action (list 'skip-quote autopair-inserted (point))))
           (;; decides whether to pair, i.e do *not* pair the quote if...
            ;;
            (not
              ;; ... comment-disable or string-disable are true here.
              ;; The latter is only useful if we're in a string
              ;; terminated by a character other than
-             ;; `last-input-event'.
+             ;; `autopair-inserted'.
              (some #'(lambda (sym)
                        (autopair-exception-p where-sym sym autopair-dont-pair))
                    '(:comment :string))))
-           (setq autopair-action (list 'insert-quote last-input-event (point)))))
+           (setq autopair-action (list 'insert-quote autopair-inserted (point)))))
     (autopair-fallback)))
 
-  (put 'autopair-insert-or-skip-quote 'function-documentation
+(put 'autopair-insert-or-skip-quote 'function-documentation
      '(concat "Insert or possibly skip over a quoting character.\n\n"
               (autopair-document-bindings)))
 
 (defun autopair-in-unterminated-string-p (autopair-triplet)
-  (and (eq last-input-event (fourth (third autopair-triplet)))
+  (and (eq autopair-inserted (fourth (third autopair-triplet)))
        (condition-case nil (progn (scan-sexps (ninth (third autopair-triplet)) 1) nil) (error t))))     
 
 
 (defun autopair-insert-opening ()
   (interactive)
+  (setq autopair-inserted (autopair-calculate-inserted))
   (when (autopair-pair-p)
-    (setq autopair-action (list 'opening (autopair-find-pair last-input-event) (point))))
+    (setq autopair-action (list 'opening (autopair-find-pair autopair-inserted) (point))))
   (autopair-fallback))
 (put 'autopair-insert-opening 'function-documentation
      '(concat "Insert opening delimiter and possibly automatically close it.\n\n"
 
 (defun autopair-skip-close-maybe ()
   (interactive)
+  (setq autopair-inserted (autopair-calculate-inserted))
   (when (autopair-skip-p)
-    (setq autopair-action (list 'closing (autopair-find-pair last-input-event) (point))))
+    (setq autopair-action (list 'closing (autopair-find-pair autopair-inserted) (point))))
   (autopair-fallback))
 (put 'autopair-skip-close-maybe 'function-documentation
      '(concat "Insert or possibly skip over a closing delimiter.\n\n"
-               (autopair-document-bindings)))
+              (autopair-document-bindings)))
 
 (defun autopair-backspace ()
   (interactive)
-    (when (char-before)
-      (setq autopair-action (list 'backspace (autopair-find-pair (char-before)) (point))))
+  (setq autopair-inserted (autopair-calculate-inserted))
+  (when (char-before)
+    (setq autopair-action (list 'backspace (autopair-find-pair (char-before)) (point))))
   (autopair-fallback (kbd "DEL")))
 (put 'autopair-backspace 'function-documentation
      '(concat "Possibly delete a pair of paired delimiters.\n\n"
 
 (defun autopair-newline ()
   (interactive)
+  (setq autopair-inserted (autopair-calculate-inserted))
   (let ((pair (autopair-find-pair (char-before))))
     (when (eq (char-after) pair)
       (setq autopair-action (list 'newline pair (point))))
               (autopair-document-bindings (kbd "RET"))))
 
 (defun autopair-skip-p ()
-  (interactive)
   (let* ((syntax-triplet (autopair-syntax-ppss))
          (syntax-info (first syntax-triplet))
          (orig-point (point)))
     (cond ((eq autopair-skip-criteria 'help-balance)
            (save-excursion
-             (let ((pos-pair (autopair-up-list syntax-info last-input-event)))
+             (let ((pos-pair (autopair-up-list syntax-info autopair-inserted)))
                ;; if `autopair-up-list' returned something valid, we
                ;; probably want to skip but only if on of the following is true.
                ;;
                     (or (eq (car pos-pair) (cdr pos-pair))
                         (< orig-point (cdr pos-pair))
                         (eq (char-after (car pos-pair))
-                            (autopair-find-pair last-input-event)))))))
+                            (autopair-find-pair autopair-inserted)))))))
           ((eq autopair-skip-criteria 'need-opening)
            (save-excursion
              (condition-case err
                      (save-excursion
                        (let ((pos-pair (autopair-up-list syntax-info))
                              (prev-point (point-max))
-                             (expected-closing (autopair-find-pair last-input-event)))
+                             (expected-closing (autopair-find-pair autopair-inserted)))
                          (condition-case err
                              (progn
                                (while (not (eq prev-point (point)))
                                    ;; autopair if we're in a mixed parens situation,
                                    ;; i.e. the last list jumped over was started by
                                    ;; the paren we're trying to match
-                                   ;; (`last-input-event') and ended by a different
+                                   ;; (`autopair-inserted') and ended by a different
                                    ;; parens, or the closing paren we stopped at is
                                    ;; also different from the expected. The second
                                    ;; `scan-lists' places point at the closing of the
                                    (condition-case err
                                        (prog1
                                            (eq (char-after (scan-lists (point) -1 0))
-                                               last-input-event)
+                                               autopair-inserted)
                                          (goto-char (scan-lists (point) -1 -1)))
                                      (error t))
                                    
 `autopair-wrap-action'. "
   (when (and autopair-wrap-action
              (notany #'null autopair-wrap-action))
-    (condition-case err
-        (if autopair-handle-wrap-action-fns
+    
+    (if autopair-handle-wrap-action-fns
+        (condition-case err
             (mapc #'(lambda (fn)
                       (apply fn autopair-wrap-action))
                   autopair-handle-wrap-action-fns)
-          (apply #'autopair-default-handle-wrap-action autopair-wrap-action))
-      (error (progn
-               (message "[autopair] error running `autopair-handle-wrap-action-fns', switching autopair off")
-               (autopair-mode -1))))
+          (error (progn
+                   (message "[autopair] error running custom `autopair-handle-wrap-action-fns', switching autopair off")
+                   (autopair-mode -1))))
+      (apply #'autopair-default-handle-wrap-action autopair-wrap-action))
     (setq autopair-wrap-action nil))
   
   (when (and autopair-action
              (notany #'null autopair-action))
-    (condition-case err
-        (if autopair-handle-action-fns
+    (if autopair-handle-action-fns
+        (condition-case err
             (mapc #'(lambda (fn)
                       (funcall fn (first autopair-action) (second autopair-action) (third autopair-action)))
                   autopair-handle-action-fns)
-          (apply #'autopair-default-handle-action autopair-action))
-      (error (progn
-               (message "[autopair] error running `autopair-handle-action-fns', switching autopair off")
-               (autopair-mode -1))))
+          (error (progn
+                   (message "[autopair] error running custom `autopair-handle-action-fns', switching autopair off")
+                   (autopair-mode -1))))
+      (apply #'autopair-default-handle-action autopair-action))
     (setq autopair-action nil)))
 
 (defun autopair-blink-matching-open ()
         (blink-matching-delay autopair-blink-delay))
     (blink-matching-open)))
 
-(defun autopair-blink ()
+(defun autopair-blink (&optional pos)
   (when autopair-blink
-    (sit-for autopair-blink-delay)))
+    (if pos
+        (save-excursion
+          (goto-char pos)
+          (sit-for autopair-blink-delay))
+      (sit-for autopair-blink-delay))))
 
 (defun autopair-default-handle-action (action pair pos-before)
   ;;(message "action is %s" action)
-  (cond (;; automatically insert closing delimiter
-         (and (eq 'opening action)
-              (not (eq pair (char-before))))
-         (insert pair)
-         (autopair-blink)
-         (backward-char 1))
-        (;; automatically insert closing quote delimiter
-         (eq 'insert-quote action)
-         (insert pair)
-         (autopair-blink)
-         (backward-char 1))
-        (;; automatically skip oper closer quote delimiter
-         (and (eq 'skip-quote action)
-              (eq pair (char-after (point))))
-         (delete-char 1)
-         (autopair-blink-matching-open))
-        (;; skip over newly-inserted-but-existing closing delimiter
-         ;; (normal case)
-         (and (eq 'closing action)
-              (eq last-input-event (char-after (point))))
-         (delete-char 1)
-         (autopair-blink-matching-open))
-        (;; autodelete closing delimiter
-         (and (eq 'backspace action)
-              (eq pair (char-after (point))))
-         (delete-char 1))
-        (;; opens an extra line after point, then indents
-         (and (eq 'newline action)
-              (eq pair (char-after (point))))
-         (save-excursion
-           (newline-and-indent))
-         (indent-according-to-mode)
-         (when (or (and (boundp 'global-hl-line-mode)
-                        global-hl-line-mode)
-                   (and (boundp 'hl-line-mode)
-                        hl-line-mode))
-           (hl-line-unhighlight) (hl-line-highlight)))))
+  (condition-case err
+      (cond (;; automatically insert closing delimiter
+             (and (eq 'opening action)
+                  (not (eq pair (char-before))))
+             (insert pair)
+             (autopair-blink)
+             (backward-char 1))
+            (;; automatically insert closing quote delimiter
+             (eq 'insert-quote action)
+             (insert pair)
+             (autopair-blink)
+             (backward-char 1))
+            (;; automatically skip oper closer quote delimiter
+             (and (eq 'skip-quote action)
+                  (eq pair (char-after (point))))
+             (delete-char 1)
+             (autopair-blink-matching-open))
+            (;; skip over newly-inserted-but-existing closing delimiter
+             ;; (normal case)
+             (eq 'closing action)
+             (let ((skipped 0))
+               (when autopair-skip-whitespace
+                 (setq skipped (save-excursion (skip-chars-forward "\s\n\t"))))
+               (when (eq autopair-inserted (char-after (+ (point) skipped)))
+                 (unless (zerop skipped) (autopair-blink (+ (point) skipped)))
+                 (if (zerop skipped)
+                     (progn (backward-char 1) (delete-char 1) (forward-char))
+                   (delete-char (1+ skipped)))
+                 (autopair-blink-matching-open))))
+            (;; autodelete closing delimiter
+             (and (eq 'backspace action)
+                  (eq pair (char-after (point))))
+             (delete-char 1))
+            (;; opens an extra line after point, then indents
+             (and (eq 'newline action)
+                  (eq pair (char-after (point))))
+             (save-excursion
+               (newline-and-indent))
+             (indent-according-to-mode)
+             (when (or (and (boundp 'global-hl-line-mode)
+                            global-hl-line-mode)
+                       (and (boundp 'hl-line-mode)
+                            hl-line-mode))
+               (hl-line-unhighlight) (hl-line-highlight))))
+    (error
+     (message "[autopair] Ignored error in `autopair-default-handle-action'"))))
 
 (defun autopair-default-handle-wrap-action (action pair pos-before region-before)
   "Default handler for the wrapping action in `autopair-wrap'"
-  (when (eq 'wrap action)
-    (let ((reverse-selected (= (car region-before) pos-before)))
-      (cond
-       ((eq 'opening (first autopair-action))
-        ;; (message "wrap-opening!")
-        (cond (reverse-selected
-               (goto-char (1+ (cdr region-before)))
-               (insert pair)
-               (goto-char (1+ (car region-before))))
-              (t
-               (delete-backward-char 1)
-               (insert pair)
-               (goto-char (car region-before))
-               (insert last-input-event)))
-        (setq autopair-action nil) )
-       (;; wraps
-        (eq 'closing (first autopair-action))
-        ;; (message "wrap-closing!")
-        (cond (reverse-selected
-               (delete-backward-char 1)
-               (insert pair)
-               (goto-char (1+ (cdr region-before)))
-               (insert last-input-event))
-              (t
-               (goto-char (car region-before))
-               (insert pair)
-               (goto-char (+ 2 (cdr region-before)))))
-        (setq autopair-action nil))
-       ((eq 'insert-quote (first autopair-action))
-        (cond (reverse-selected
-               (goto-char (1+ (cdr region-before)))
-               (insert pair))
-              (t
-               (goto-char (car region-before))
-               (insert last-input-event)))
-        (setq autopair-action nil))
-       (reverse-selected
-        (delete-backward-char 1)
-        (goto-char (cdr region-before))
-        (insert last-input-event))))))
+  (condition-case err
+      (when (eq 'wrap action)
+        (let ((reverse-selected (= (car region-before) pos-before)))
+          (cond
+           ((eq 'opening (first autopair-action))
+            ;; (message "wrap-opening!")
+            (cond (reverse-selected
+                   (goto-char (1+ (cdr region-before)))
+                   (insert pair)
+                   (autopair-blink)
+                   (goto-char (1+ (car region-before))))
+                  (t
+                   (delete-backward-char 1)
+                   (insert pair)
+                   (goto-char (car region-before))
+                   (insert autopair-inserted)))
+            (setq autopair-action nil) )
+           (;; wraps
+            (eq 'closing (first autopair-action))
+            ;; (message "wrap-closing!")
+            (cond (reverse-selected
+                   (delete-backward-char 1)
+                   (insert pair)
+                   (goto-char (1+ (cdr region-before)))
+                   (insert autopair-inserted))
+                  (t
+                   (goto-char (car region-before))
+                   (insert pair)
+                   (autopair-blink)
+                   (goto-char (+ 2 (cdr region-before)))))
+            (setq autopair-action nil))
+           ((eq 'insert-quote (first autopair-action))
+            (cond (reverse-selected
+                   (goto-char (1+ (cdr region-before)))
+                   (insert pair)
+                   (autopair-blink))
+                  (t
+                   (goto-char (car region-before))
+                   (insert autopair-inserted)
+                   (autopair-blink)))
+            (setq autopair-action nil))
+           (reverse-selected
+            (delete-backward-char 1)
+            (goto-char (cdr region-before))
+            (insert autopair-inserted)))))
+    (error
+     (message "[autopair] Ignored error in `autopair-default-handle-wrap-action'"))))
 
 
 ;; example python triple quote helper
         (t
          t)))
 
-;; Commands, predicates and tests for the autopair-extra* feature
+;; example latex paired-delimiter helper 
+;;
+(defun autopair-latex-mode-paired-delimiter-action (action pair pos-before)
+  "Pair or skip latex's \"paired delimiter\" syntax in math mode."
+  (when (eq action 'paired-delimiter)
+    (when (eq (char-before) pair)
+      (if (and (eq (get-text-property pos-before 'face) 'tex-math)
+               (eq (char-after) pair))
+          (cond ((and (eq (char-after) pair)
+                      (eq (char-after (1+ (point))) pair))
+                 ;; double skip
+                 (delete-char 1)
+                 (forward-char))
+                ((eq (char-before pos-before) pair)
+                 ;; doube insert
+                 (insert pair)
+                 (backward-char))
+                (t
+                 ;; simple skip
+                 (delete-char 1)))
+        (insert pair)
+        (backward-char)))))
+
+;; Commands and predicates for the autopair-extra* feature 
 ;;
 
 (defun autopair-extra-insert-opening ()
   (interactive)
+  (setq autopair-inserted (autopair-calculate-inserted))
   (when (autopair-extra-pair-p)
-    (setq autopair-action (list 'opening (autopair-find-pair last-input-event) (point))))
+    (setq autopair-action (list 'opening (autopair-find-pair autopair-inserted) (point))))
   (autopair-fallback))
 (put 'autopair-extra-insert-opening 'function-documentation
      '(concat "Insert (an extra) opening delimiter and possibly automatically close it.\n\n"
 
 (defun autopair-extra-skip-close-maybe ()
   (interactive)
+  (setq autopair-inserted (autopair-calculate-inserted))
   (when (autopair-extra-skip-p)
-    (setq autopair-action (list 'closing last-input-event (point))))
+    (setq autopair-action (list 'closing autopair-inserted (point))))
   (autopair-fallback))
 (put 'autopair-extra-skip-close-maybe 'function-documentation
      '(concat "Insert or possibly skip over a (and extra) closing delimiter.\n\n"
          (syntax-info (first syntax-triplet))
          (where-sym (second syntax-triplet))
          (orig-point (point)))
-    (and (eq (char-after (point)) last-input-event)
+    (and (eq (char-after (point)) autopair-inserted)
          (some #'(lambda (sym)
                    (autopair-exception-p where-sym sym autopair-extra-pairs #'cdr))
                '(:comment :string :code :everywhere))
                (backward-sexp (point-max))
              (error
               (goto-char (third err))))
-           (search-forward (make-string 1 (autopair-find-pair last-input-event))
+           (search-forward (make-string 1 (autopair-find-pair autopair-inserted))
                            orig-point
                            'noerror)))))
 
+;; Commands and tex-mode specific handler functions for the "paired
+;; delimiter" syntax class.
+;; 
+(defun autopair-insert-or-skip-paired-delimiter ()
+  " insert or skip a character paired delimiter"
+  (interactive)
+  (setq autopair-inserted (autopair-calculate-inserted))
+  (setq autopair-action (list 'paired-delimiter autopair-inserted (point)))
+  (autopair-fallback))
+
+(put 'autopair-insert-or-skip-paired-delimiter 'function-documentation
+     '(concat "Insert or possibly skip over a character with a syntax-class of \"paired delimiter\"."
+              (autopair-document-bindings)))
+
+
+
+;; monkey-patching: Compatibility with delete-selection-mode and cua-mode
+;;
+;; Ideally one would be able to use functions as the value of the
+;; 'delete-selection properties of the autopair commands. The function
+;; would return non-nil when no wrapping should/could be performed.
+;;
+;; Until then use some `defadvice' i.e. monkey-patching, which relies
+;; on these features' implementation details.
+;;
+(put 'autopair-insert-opening 'delete-selection t)
+(put 'autopair-skip-close-maybe 'delete-selection t)
+(put 'autopair-insert-or-skip-quote 'delete-selection t)
+(put 'autopair-extra-insert-opening 'delete-selection t)
+(put 'autopair-extra-skip-close-maybe 'delete-selection t)
+(put 'autopair-backspace 'delete-selection 'supersede)
+(put 'autopair-newline 'delete-selection t)
+
+(defun autopair-should-autowrap ()
+  (let ((name (symbol-name this-command)))
+    (and autopair-mode
+         (not (eq this-command 'autopair-backspace))
+         (string-match "^autopair" (symbol-name this-command))
+         (autopair-calculate-wrap-action))))
+
+(defadvice cua--pre-command-handler-1 (around autopair-override activate)
+  "Don't actually do anything if autopair is about to autowrap. "
+  (unless (autopair-should-autowrap) ad-do-it))
+
+(defadvice delete-selection-pre-hook (around autopair-override activate)
+  "Don't actually do anything if autopair is about to autowrap. "
+  (unless (autopair-should-autowrap) ad-do-it))
+
+
 (provide 'autopair)
 ;;; autopair.el ends here
 ;;
 ;; Copyrigth (C) 2000-2010  Jo Odland
 
 ;; Author: Jo Odland <jo.odland(at)gmail.com>
-;; Version: $Id: bm.el,v 1.43 2010/04/14 20:23:05 jood Exp $
+;; Version: $Id: bm.el,v 1.50 2010/06/19 16:52:33 jood Exp $
 ;; Keywords; bookmark, highlight, faces, persistent
 ;; URL: http://www.nongnu.org/bm/
 ;; Project page: https://savannah.nongnu.org/projects/bm/
 ;;
 ;;    - List bookmarks with annotations and context in a separate buffer,
 ;;      see `bm-show' (current buffer) and `bm-show-all' (all buffers).
+;;      See `bm-show-mode-map' for key bindings.
 ;;
 ;;    - Remove all bookmarks in current buffer with `bm-remove-all-current-buffer' and
 ;;      all bookmarks in all open buffers with `bm-remove-all-all-buffers'.
 
 ;;; Known limitations:
 ;;
-;;   This package is developed and testet on GNU Emacs 22.x. It should
+;;   This package is developed and tested on GNU Emacs 22.x. It should
 ;;   work on all GNU Emacs 21.x, GNU Emacs 23.x and also on XEmacs
 ;;   21.x with some limitations.
 ;;
-;;   There are some incompabilities with lazy-lock when using
+;;   There are some incompatibilities with lazy-lock when using
 ;;   fill-paragraph. All bookmark below the paragraph being filled
 ;;   will be lost. This issue can be resolved using the `jit-lock-mode'
 ;;   introduced in GNU Emacs 21.1
 ;;    (http://www.emacswiki.org/cgi-bin/wiki/bm-ext.el)
 ;;  - Thanks to Jonathan Kotta <jpkotta(at)gmail.com> for mouse support and fringe
 ;;    markers on left or right side.
+;;  - Thanks to Juanma Barranquero <lekktu(at)gmail.com> for making `bm-show' an
+;;    electric window, cleaning up the code, fixing bugs and fixing spelling errors.
 
 
 ;;; Change log:
 
+;;  Changes in 1.49
+;;   - Removed used of `goto-line' due to compile warning in GNU Emacs 23.2.1.
+;;     Thanks to Juanma Barranquero for patch.
+;;   - Fixed bug in `bm-bookmark-regexp-region'. Thanks to Juanma Barranquero for patch.
+;;
+;;  Changes in 1.48
+;;   - Removed support for repository file format version 1.
+;;   - Cleaned up some code.
+;;
+;;  Changes in 1.45
+;;   - Changed `bm-show' to an electric window. Thanks to Juanma Barranquero for patch.
+;; 
+;;  Changes in 1.44
+;;   - Fixed spelling. Cleaned up some code. Thanks to Juanma Barranquero for patch.
+;;
 ;;  Changes in 1.43
-;;   - Fixed spelling. Thanks to Juanma Barranquero <lekktu(at)gmail.com> for patch.
+;;   - Fixed spelling. Thanks to Juanma Barranquero for patch.
 ;;
 ;;  Changes in 1.42
 ;;   - Fixed bug(#29536) - Next/previous does not wrap when `bm-cycle-all-buffers' t
 ;;
 
 (eval-and-compile
-  ;; avoid compile waring on unbound variable
+  ;; avoid compile warning on unbound variable
   (require 'info)
 
   ;; xemacs needs overlay emulation package
     (require 'overlay)))
 
 
-(defconst bm-version "$Id: bm.el,v 1.43 2010/04/14 20:23:05 jood Exp $"
+(defconst bm-version "$Id: bm.el,v 1.50 2010/06/19 16:52:33 jood Exp $"
   "CVS version of bm.el.")
 
 (defconst bm-bookmark-repository-version 2
   "*Specify bm overlay priority.
 
 Higher integer means higher priority, so bm overlay will have precedence
-over overlays with lower priority.  *Don't* use negative number."
+over overlays with lower priority.  *Don't* use a negative number."
   :type 'integer
   :group 'bm)
 
 
 
 (defcustom bm-wrap-search t
- "*Specify if bookmark search should wrap.
+  "*Specify if bookmark search should wrap.
 
 nil, don't wrap when there are no more bookmarks.
 t, wrap."
- :type 'boolean
- :group 'bm)
+  :type 'boolean
+  :group 'bm)
 
 
 (defcustom bm-wrap-immediately t
   :type 'boolean
   :group 'bm)
 
+
 (defcustom bm-cycle-all-buffers nil
- "*Specify if bookmark search is done across buffers.
+  "*Specify if bookmark search is done across buffers.
 This will ignore the `bm-wrap-search' setting.
 
 nil, only search in current buffer.
 t, search in all open buffers."
- :type 'boolean
- :group 'bm)
+  :type 'boolean
+  :group 'bm)
 
 (defcustom bm-recenter nil
   "*Specify if the buffer should be recentered after jumping to a bookmark."
   :group 'bm)
 
 
+(defcustom bm-electric-show t
+  "*If t, `bm-show' acts like an electric buffer."
+  :type 'boolean
+  :group 'bm)
+
+
 (defcustom bm-repository-file (expand-file-name "~/.bm-repository")
   "*Filename to store persistent bookmarks across sessions.
 
   :group 'bm)
 (make-variable-buffer-local 'bm-buffer-persistence)
 
-
-(defcustom bm-restore-on-mismatch nil
-  "*Specify if bookmarks should be restored if there is a buffer size mismatch.
-DEPRECATED: Only in use for version 1 of repository.
-
-nil, don't restore.
-t, restore if possible."
-  :type 'boolean
-  :group 'bm)
-
-
 (defvar bm-restore-repository-on-load nil
   "Specify if repository should be restored when loading bm.
 
   "State variable to support wrapping.")
 (make-variable-buffer-local 'bm-wrapped)
 
+(defconst bm-show-buffer-name "*bm-bookmarks*"
+  "The name of the buffer used to show bookmarks by `bm-show'.")
+
+(defconst bm-show-line-format "%-20s %-20s %s"
+  "The format string used by `bm-header' and `bm-show-extract-bookmarks'.")
+
 (defvar bm-marker 'bm-marker-left
   "Fringe marker side. Left of right.")
 
       (progn
         (if (null annotation)
             (setq annotation (read-from-minibuffer "Annotation: " nil nil nil 'bm-annotation-history)))
-        (overlay-put bookmark 'annotation annotation))    (if (interactive-p) (message "No bookmark at point"))))
-    
+        (overlay-put bookmark 'annotation annotation))
+    (if (interactive-p) (message "No bookmark at point"))))
+
 
 (defun bm-bookmark-show-annotation (&optional bookmark)
   "Show annotation for bookmark.
       (setq bookmark (bm-bookmark-at (point))))
 
   (if (bm-bookmarkp bookmark)
-      (progn
-        (let ((annotation (overlay-get bookmark 'annotation)))
-          (if annotation
-              (message annotation)
-            (message "No annotation for current bookmark."))))
+      (message (or (overlay-get bookmark 'annotation)
+                   "No annotation for current bookmark."))
     (message "No bookmark at current line.")))
 
 (defun bm-line-highlighted ()
 Only used if `bm-annotate-on-create' is true.
 
 Do nothing if bookmark is present."
-  (if (bm-bookmark-at (point))
-      nil				; bookmark exists
+  (unless (bm-bookmark-at (point))
     (let ((bookmark (make-overlay (bm-start-position) (bm-end-position)))
           (hlface (if bm-buffer-persistence bm-persistent-face bm-face))
           (hlface-fringe (if bm-buffer-persistence bm-fringe-persistent-face bm-fringe-face)))
   "Return a pair of lists giving all the bookmarks of the current buffer.
 The car has all the bookmarks before the overlay center;
 the cdr has all the bookmarks after the overlay center.
-A bookmark implementation of `overlay-list'.
+A bookmark implementation of `overlay-lists'.
 
 If optional argument DIRECTION is provided, only return bookmarks
 in the specified direction."
     (setq bm-wrapped t)       ; wrap on next goto
     (message "Failed: No next bookmark.")))
 
-  
+
 ;;;###autoload
 (defun bm-next-mouse (ev)
   "Go to the next bookmark with the scroll wheel.
       (if bm-cycle-all-buffers
           (bm-last-in-previous-buffer)
         (message "No bookmarks defined."))
-  (let ((bm-list-backward (car (bm-lists 'backward))))
-    ;; remove bookmark at point
-    (if (bm-equal (bm-bookmark-at (point)) (car bm-list-backward))
-        (setq bm-list-backward (cdr bm-list-backward)))
+    (let ((bm-list-backward (car (bm-lists 'backward))))
+      ;; remove bookmark at point
+      (if (bm-equal (bm-bookmark-at (point)) (car bm-list-backward))
+          (setq bm-list-backward (cdr bm-list-backward)))
 
       (if bm-list-backward
           (bm-goto (car bm-list-backward))
 (defun bm-first-in-next-buffer nil
   "Goto first bookmark in next buffer."
   (interactive)
-  (let ((buffers
+  (let ((current (current-buffer))
+        (buffers
          (save-excursion
            (remq nil (mapcar '(lambda (buffer)
                                 (set-buffer buffer)
     (if buffers
         (progn
           (switch-to-buffer (car buffers))
+          (bury-buffer current)
           (message "Switched to '%s'" (car buffers))
           (bm-first))
       ;; no bookmarks found in other open buffers,
         (message "No bookmarks found in other open buffers.")))))
 
 
-
 (defun bm-last-in-previous-buffer nil
   "Goto last bookmark in previous buffer."
   (interactive)
 (defun bm-first nil
   "Goto first bookmark in buffer."
   (goto-char (point-min))
-  (if (bm-bookmark-at (point))
-      ;; bookmark at beginning of buffer, stop looking
-      nil
-    (bm-next)))
+  (unless (bm-bookmark-at (point)) ; bookmark at beginning of buffer, stop looking
+      (bm-next)))
 
 
 (defun bm-last nil
-  "Goto first bookmark in buffer."
+  "Goto last bookmark in buffer."
   (goto-char (point-max))
-  (if (bm-bookmark-at (point))
-      ;; bookmark at end of buffer, stop looking
-      nil
+  (unless (bm-bookmark-at (point)) ; bookmark at end of buffer, stop looking
     (bm-previous)))
 
 
                             "Annotation: " nil nil nil 'bm-annotation-history)))
 
       (goto-char beg)
-      (while (re-search-forward regexp end t)
+      (while (and (< (point) end)
+                  (re-search-forward regexp end t))
 	(bm-bookmark-add annotation)
         (setq count (1+ count))
 	(forward-line 1)))
 (defun bm-bookmark-line (line)
   "Set a bookmark on the specified LINE."
   (interactive "nSet a bookmark on line: ")
-  (let ((lines (count-lines (point-min) (point-max))))
-    (if (> line lines)
-	(message "Unable to set bookmark at line %d. Only %d lines in buffer."
-		 line lines)
-      (goto-line line)
-      (bm-bookmark-add))))
-  
+  (let* ((here (point))
+         (remaining (progn
+                      (goto-char (point-min))
+                      (forward-line (1- line)))))
+    (if (zerop remaining)
+        (bm-bookmark-add)
+      (message "Unable to set bookmark at line %d. Only %d lines in the buffer." line (- line remaining 1))
+      (goto-char here))))
+
+
+(defun bm-show-quit-window nil
+  "Quit the window displaying `bm-show-buffer-name'."
+  (interactive)
+  (quit-window nil (get-buffer-window bm-show-buffer-name)))
+
 
 (defun bm-show-all nil
   "Show bookmarked lines in all buffers."
     (mapconcat
      '(lambda (bm)
         (let ((string
-               (format "%-20s %-20s %s"
+               (format bm-show-line-format
                        (format "%s:%d" (buffer-name) (count-lines (point-min) (overlay-start bm)))
-                       (let ((annotation (overlay-get bm 'annotation)))
-                         (if (null annotation) "" annotation))
+                       (or (overlay-get bm 'annotation) "")
                        (buffer-substring (overlay-start bm) (overlay-end bm)))))
           (put-text-property 0 (length string) 'bm-buffer  (buffer-name)  string)
           (put-text-property 0 (length string) 'bm-bookmark  bm  string)
 
 
 (defun bm-show-display-lines (lines)
-  "Show bookmarked LINES to the *bm-bookmarks* buffer."
+  "Show bookmarked LINES to the `bm-show-buffer-name' buffer."
   (if (= (length lines) 0)
       (message "No bookmarks defined.")
-    (with-output-to-temp-buffer "*bm-bookmarks*"
+    (with-output-to-temp-buffer bm-show-buffer-name
       (set-buffer standard-output)
       (insert lines)
       (bm-show-mode)
-      (setq buffer-read-only t))))
+      (setq buffer-read-only t)
+      (when bm-electric-show
+        (pop-to-buffer (current-buffer))))))
 
 
 (defun bm-show-goto-bookmark nil
-  "Goto the bookmark on current line in the *bm-bookmarks* buffer."
+  "Goto the bookmark on current line in the `bm-show-buffer-name' buffer."
   (interactive)
   (let ((buffer-name (get-text-property (point) 'bm-buffer))
 	(bookmark (get-text-property (point) 'bm-bookmark)))
     (if (null buffer-name)
 	(message "No bookmark at this line.")
       (pop-to-buffer (get-buffer buffer-name))
-      (bm-goto bookmark))))
+      (bm-goto bookmark)
+      (when bm-electric-show (bm-show-quit-window)))))
 
 
 (defun bm-show-bookmark nil
-  "Show the bookmark on current line in the *bm-bookmarks* buffer."
+  "Show the bookmark on current line in the `bm-show-buffer-name' buffer."
   (interactive)
   (let ((buffer-name (get-text-property (point) 'bm-buffer))
 	(bookmark (get-text-property (point) 'bm-bookmark)))
   (let ((map (make-sparse-keymap)))
     (define-key map (kbd "RET") 'bm-show-goto-bookmark)
     (define-key map (kbd "SPC") 'bm-show-bookmark)
+    (define-key map (kbd "M-n") 'bm-show-next)
+    (define-key map (kbd "M-p") 'bm-show-prev)
+    (define-key map "q"         'bm-show-quit-window)
     map)
   "Keymap for `bm-show-mode'.")
 
 
+(defconst bm-header
+  (concat
+   (propertize " " 'display '(space :align-to (+ left-margin 1)))
+   (format bm-show-line-format "File:Line" "Annotation" "Contents"))
+  "Format for `header-line-format' in `bm-show-buffer-name' buffer.")
+
+
+(defun bm-show-next (lines)
+  "Goto next bookmark in `bm-show' buffer.
+LINES the number of lines to move forward."
+  (interactive "p")
+  (forward-line lines)
+  (bm-show-bookmark))
+
+
+(defun bm-show-prev (lines)
+  "Goto previous bookmark in `bm-show' buffer.
+LINES the number of lines to move backwards."
+  (interactive "p")
+  (forward-line (- lines))
+  (bm-show-bookmark))
+
+
 (defun bm-show-mode nil
   "Major mode for `bm-show' buffers."
   (interactive)
   (kill-all-local-variables)
+  (setq header-line-format bm-header)
   (setq major-mode 'bm-show-mode)
   (setq mode-name "bm-bookmarks")
   (use-local-map bm-show-mode-map))
           (progn
             (goto-char (match-beginning 0))
             (setq point (point))))
-        
+      
       ;; search backward for context
       (if (and before (search-backward before (point-min) t))
           (progn
           (cond ((= version 2)
                  (bm-buffer-restore-2 buffer-data))
                 (t
-                 (bm-buffer-restore-1 buffer-data))))
-    (if (interactive-p) (message "No bookmarks in repository.")))))
+                 (message "Unknown data format. Version %d" version))))
+      (if (interactive-p) (message "No bookmarks in repository.")))))
 
 
 (defun bm-buffer-restore-all nil
 	     (bm-buffer-restore))
 	  (buffer-list))))
 
-(defun bm-buffer-restore-1 (buffer-data)
-  "Restore bookmarks from version 1 format.
-BUFFER-DATA is the content of `bm-repository-file'."
-  (let ((buffer-size-match (equal (point-max) (cdr (assoc 'size buffer-data))))
-        (positions (cdr (assoc 'positions buffer-data))))
-      
-    ;; validate buffer size
-    (if (or buffer-size-match
-            bm-restore-on-mismatch)
-        ;; restore bookmarks
-        (let ((pos nil)
-              (count 0))
-          
-          (setq bm-buffer-persistence t) ; enable persistence
-          (save-excursion
-            (while positions
-              (setq pos (car positions))
-              
-              (if (and (< pos (point-min))
-                       (> (point-max) pos))
-                  nil		; outside buffer, skip bookmark
-                (goto-char pos)
-                (bm-bookmark-add)
-                (setq count (1+ count))
-                (setq positions (cdr positions)))))
-          
-          (if buffer-size-match
-              (message "%d bookmark(s) restored." count)
-            (message "Buffersize mismatch. %d bookmarks restored." count)))
-	
-      ;; size mismatch
-      (bm-repository-remove (buffer-file-name))
-      (message "Buffersize mismatch. No bookmarks restored."))))
-
 
 (defun bm-buffer-restore-2 (buffer-data)
   "Restore bookmarks from version 2 format.
 BUFFER-DATA is the content of `bm-repository-file'."
   (let ((buffer-size-match (equal (point-max) (cdr (assoc 'size buffer-data))))
-        (bookmarks (cdr (assoc 'bookmarks buffer-data))))
-      
-    ;; restore bookmarks
-    (let ((pos nil)
-          (count 0))
-      
+        (bookmarks (cdr (assoc 'bookmarks buffer-data)))
+        (count 0))
+    
       (setq bm-buffer-persistence t) ; enable persistence
       (save-excursion
         (while bookmarks
-          (let ((pos
-                 (if buffer-size-match
-                     (cdr (assoc 'position (car bookmarks)))
-                   (bm-get-position-from-context (car bookmarks))))
-                (bm nil)
+          (let ((pos (if buffer-size-match
+                         (cdr (assoc 'position (car bookmarks)))
+                       (bm-get-position-from-context (car bookmarks))))
                 (annotation (cdr (assoc 'annotation (car bookmarks)))))
             
-            (if (and (< pos (point-min))
-                     (> (point-max) pos))
-                nil		; outside buffer, skip bookmark
+            ;; create bookmark if is inside buffer
+            (when (and (<= (point-min) pos)
+                       (<= pos (point-max)))
               (goto-char pos)
-              (setq bm (bm-bookmark-add annotation))
-              (setq count (1+ count))
-              (setq bookmarks (cdr bookmarks))))))
+              (bm-bookmark-add annotation)
+              (setq count (1+ count)))
+            (setq bookmarks (cdr bookmarks)))))
       
       (if buffer-size-match
           (message "%d bookmark(s) restored." count)
-        (message "%d bookmark(s) restored based on context." count)))))
-    
+        (message "%d bookmark(s) restored based on context." count))))
+
 
 (defun bm-buffer-save nil
   "Save all bookmarks to repository."
   (interactive)
-  (if (not (null (bm-buffer-file-name)))
+  (if (bm-buffer-file-name)
       (if bm-buffer-persistence
           (let ((buffer-data
                  (list
                                  (cons 'position position)
                                  (cons 'annotation (overlay-get bm 'annotation))
                                  (cons 'before-context-string
-                                       (if (>= (point-min) (- position bm-bookmark-context-size))
-                                           nil
-                                         (buffer-substring-no-properties
-                                          (- position bm-bookmark-context-size) position)))
+                                       (let ((context-start
+                                              (max (point-min) (- position bm-bookmark-context-size))))
+                                         (buffer-substring-no-properties context-start position)))
                                  (cons 'after-context-string
-                                       (if (>= (+ position bm-bookmark-context-size) (point-max))
-                                           nil
-                                         (buffer-substring-no-properties
-                                          position (+ position bm-bookmark-context-size))))
-                                 )))
+                                       (let ((context-end
+                                              (min (+ position bm-bookmark-context-size) (point-max))))
+                                         (buffer-substring-no-properties position context-end))))))
                            (append (car bookmarks) (cdr bookmarks))))))))
             
             ;; remove if exists
   ;; remove oldest element if repository is too large
   (while (and bm-repository-size
 	      (> (length bm-repository) bm-repository-size))
-	(setq bm-repository (cdr bm-repository))))
+    (setq bm-repository (cdr bm-repository))))
 
 
 (defun bm-repository-remove (key)
   "Remove data for a buffer from the repository identified by KEY."
   (let ((repository nil))
-    (if (not (assoc key bm-repository))
-	;; don't exist in repository, do nothing
-	nil
+    (when (assoc key bm-repository)
       ;; remove all occurances
       (while bm-repository
 	(if (not (equal key (car (car bm-repository))))
   (interactive)
   (bm-buffer-save-all)
   (bm-repository-save))
-  
+
 
 (defun bm-buffer-file-name nil
   "Get a unique key for the repository, even for non-file buffers."

el/bookmarkp/bookmark+-1.el

+;;; bookmark+-1.el - First part of package Bookmark+.
+;; 
+;; Filename: bookmark+-1.el
+;; Description: First part of package Bookmark+.
+;; Author: Drew Adams, Thierry Volpiatto
+;; Maintainer: Drew Adams (concat "drew.adams" "@" "oracle" ".com")
+;; Copyright (C) 2000-2010, Drew Adams, all rights reserved.
+;; Copyright (C) 2009, Thierry Volpiatto, all rights reserved.
+;; Created: Mon Jul 12 13:43:55 2010 (-0700)
+;; Last-Updated: Fri Dec 10 09:38:24 2010 (-0800)
+;;           By: dradams
+;;     Update #: 922
+;; URL: http://www.emacswiki.org/cgi-bin/wiki/bookmark+-1.el
+;; Keywords: bookmarks, bookmark+, placeholders, annotations, search, info, url, w3m, gnus
+;; Compatibility: GNU Emacs: 20.x, 21.x, 22.x, 23.x
+;; 
+;; Features that might be required by this library:
+;;
+;;   `bookmark', `bookmark+-1', `bookmark+-mac', `dired',
+;;   `dired-aux', `dired-x', `ffap', `pp'.
+;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 
+;;; Commentary: 
+;;
+;;    The Bookmark+ libraries are these:
+;;
+;;    `bookmark+.el'     - main (driver) library
+;;    `bookmark+-mac.el' - Lisp macros
+;;    `bookmark+-lit.el' - (optional) code for highlighting bookmarks
+;;    `bookmark+-bmu.el' - code for the `*Bookmark List*' (bmenu)
+;;    `bookmark+-1.el'   - other (non-bmenu) required code (this file)
+;;    `bookmark+-doc.el' - documentation (comment-only file)
+;;    `bookmark+-chg.el' - change log (comment-only file)
+;;
+;;    The documentation (in `bookmark+-doc.el') includes how to
+;;    byte-compile and install Bookmark+.  The documentation is also
+;;    available in these ways:
+;;
+;;    1. From the bookmark list (`C-x r l'):
+;;       Use `?' to show the current bookmark-list status and general
+;;       help, then click link `Doc in Commentary' or link `Doc on the
+;;       Web'.
+;;
+;;    2. From the Emacs-Wiki Web site:
+;;       http://www.emacswiki.org/cgi-bin/wiki/BookmarkPlus.
+;;    
+;;    3. From the Bookmark+ group customization buffer:
+;;       `M-x customize-group bookmark-plus', then click link
+;;       `Commentary'.
+;;
+;;    (The commentary links in #1 and #3 work only if you have library
+;;    `bookmark+-doc.el' in your `load-path'.)
+ 
+;;(@> "Index")
+;;
+;;  Index
+;;  -----
+;;
+;;  If you have library `linkd.el' and Emacs 22 or later, load
+;;  `linkd.el' and turn on `linkd-mode' now.  It lets you easily
+;;  navigate around the sections of this doc.  Linkd mode will
+;;  highlight this Index, as well as the cross-references and section
+;;  headings throughout this file.  You can get `linkd.el' here:
+;;  http://dto.freeshell.org/notebook/Linkd.html.
+;;
+;;  (@> "Things Defined Here")
+;;  (@> "User Options (Customizable)")
+;;  (@> "Internal Variables")
+;;  (@> "Compatibility Code for Older Emacs Versions")
+;;  (@> "Core Replacements (`bookmark-*' except `bookmark-bmenu-*')")
+;;  (@> "Bookmark+ Functions (`bmkp-*')")
+;;    (@> "Search-and-Replace Locations of Marked Bookmarks")
+;;    (@> "Tags")
+;;    (@> "Bookmark Predicates")
+;;    (@> "Filter Functions")
+;;    (@> "General Utility Functions")
+;;    (@> "Bookmark Entry Access Functions")
+;;    (@> "Sorting - General Functions")
+;;    (@> "Sorting - Commands")
+;;    (@> "Sorting - General Predicates")
+;;    (@> "Sorting - File-Name Predicates")
+;;    (@> "Indirect Bookmarking Functions")
+;;    (@> "Other Bookmark+ Functions (`bmkp-*')")
+;;  (@> "Keymaps")
+ 
+;;(@* "Things Defined Here")
+;;
+;;  Things Defined Here
+;;  -------------------
+;;
+;;  Commands defined here:
+;;
+;;    `bmkp-add-tags', `bmkp-all-tags-jump',
+;;    `bmkp-all-tags-jump-other-window', `bmkp-all-tags-regexp-jump',
+;;    `bmkp-all-tags-regexp-jump-other-window', `bmkp-autonamed-jump',
+;;    `bmkp-autonamed-jump-other-window',
+;;    `bmkp-autonamed-this-buffer-jump',
+;;    `bmkp-autonamed-this-buffer-jump-other-window',
+;;    `bmkp-bookmark-file-jump', `bmkp-bookmark-list-jump',
+;;    `bmkp-choose-navlist-from-bookmark-list',
+;;    `bmkp-choose-navlist-of-type', `bmkp-compilation-target-set',
+;;    `bmkp-compilation-target-set-all', `bmkp-crosshairs-highlight',
+;;    `bmkp-cycle', `bmkp-cycle-autonamed',
+;;    `bmkp-cycle-autonamed-other-window', `bmkp-cycle-bookmark-list',
+;;    `bmkp-cycle-bookmark-list-other-window', `bmkp-cycle-desktop',
+;;    `bmkp-cycle-dired', `bmkp-cycle-dired-other-window',
+;;    `bmkp-cycle-file', `bmkp-cycle-file-other-window',
+;;    `bmkp-cycle-gnus', `bmkp-cycle-gnus-other-window',
+;;    `bmkp-cycle-info', `bmkp-cycle-info-other-window',
+;;    `bmkp-cycle-lighted', `bmkp-cycle-lighted-other-window',
+;;    `bmkp-cycle-local-file', `bmkp-cycle-local-file-other-window',
+;;    `bmkp-cycle-man', `bmkp-cycle-man-other-window',
+;;    `bmkp-cycle-non-file', `bmkp-cycle-non-file-other-window',
+;;    `bmkp-cycle-other-window', `bmkp-cycle-remote-file',
+;;    `bmkp-cycle-remote-file-other-window',
+;;    `bmkp-cycle-specific-buffers',
+;;    `bmkp-cycle-specific-buffers-other-window',
+;;    `bmkp-cycle-specific-files',
+;;    `bmkp-cycle-specific-files-other-window',
+;;    `bmkp-cycle-this-buffer', `bmkp-cycle-this-buffer-other-window',
+;;    `bmkp-cycle-variable-list', `bmkp-cycle-url',
+;;    `bmkp-cycle-url-other-window',
+;;    `bmkp-delete-all-autonamed-for-this-buffer',
+;;    `bmkp-delete-bookmarks', `bmkp-describe-bookmark',
+;;    `bmkp-describe-bookmark-internals', `bmkp-desktop-change-dir',
+;;    `bmkp-desktop-delete', `bmkp-desktop-jump', `bmkp-desktop-read',
+;;    `bmkp-dired-jump', `bmkp-dired-jump-current',
+;;    `bmkp-dired-jump-current-other-window',
+;;    `bmkp-dired-jump-other-window', `bmkp-edit-bookmark',
+;;    `bmkp-edit-bookmark-record', `bmkp-edit-bookmark-record-mode',
+;;    `bmkp-edit-bookmark-record-send', `bmkp-empty-file',
+;;    `bmkp-file-target-set', `bmkp-file-jump',
+;;    `bmkp-file-jump-other-window', `bmkp-gnus-jump',
+;;    `bmkp-gnus-jump-other-window', `bmkp-info-jump',
+;;    `bmkp-info-jump-other-window', `bmkp-jump-in-navlist',
+;;    `bmkp-jump-in-navlist-other-window', `bmkp-jump-to-type',
+;;    `bmkp-jump-to-type-other-window', `bmkp-list-all-tags',
+;;    `bmkp-list-defuns-in-commands-file', `bmkp-local-file-jump',
+;;    `bmkp-local-file-jump-other-window',
+;;    `bmkp-make-function-bookmark', `bmkp-man-jump',
+;;    `bmkp-man-jump-other-window', `bmkp-menu-jump-other-window'
+;;    (Emacs 20, 21), `bmkp-navlist-bmenu-list',
+;;    `bmkp-next-autonamed-bookmark',
+;;    `bmkp-next-autonamed-bookmark-repeat', `bmkp-next-bookmark',
+;;    `bmkp-next-bookmark-list-bookmark',
+;;    `bmkp-next-bookmark-list-bookmark-repeat',
+;;    `bmkp-next-bookmark-repeat', `bmkp-next-bookmark-this-buffer',
+;;    `bmkp-next-bookmark-this-buffer-repeat',
+;;    `bmkp-next-bookmark-w32', `bmkp-next-bookmark-w32-repeat',
+;;    `bmkp-next-desktop-bookmark',
+;;    `bmkp-next-desktop-bookmark-repeat', `bmkp-next-dired-bookmark',
+;;    `bmkp-next-dired-bookmark-repeat', `bmkp-next-file-bookmark',
+;;    `bmkp-next-file-bookmark-repeat', `bmkp-next-gnus-bookmark',
+;;    `bmkp-next-gnus-bookmark-repeat', `bmkp-next-info-bookmark',
+;;    `bmkp-next-info-bookmark-repeat', `bmkp-next-lighted-bookmark',
+;;    `bmkp-next-lighted-bookmark-repeat',
+;;    `bmkp-next-local-file-bookmark',
+;;    `bmkp-next-local-file-bookmark-repeat',
+;;    `bmkp-next-man-bookmark', `bmkp-next-man-bookmark-repeat',
+;;    `bmkp-next-non-file-bookmark',
+;;    `bmkp-next-non-file-bookmark-repeat',
+;;    `bmkp-next-remote-file-bookmark',
+;;    `bmkp-next-remote-file-bookmark-repeat',
+;;    `bmkp-next-specific-buffers-bookmark',
+;;    `bmkp-next-specific-buffers-bookmark-repeat',
+;;    `bmkp-next-specific-files-bookmark',
+;;    `bmkp-next-specific-files-bookmark-repeat',
+;;    `bmkp-next-variable-list-bookmark',
+;;    `bmkp-next-variable-list-bookmark-repeat',
+;;    `bmkp-next-url-bookmark', `bmkp-next-url-bookmark-repeat',
+;;    `bmkp-non-file-jump', `bmkp-non-file-jump-other-window',
+;;    `bmkp-occur-create-autonamed-bookmarks',
+;;    `bmkp-occur-target-set', `bmkp-occur-target-set-all',
+;;    `bmkp-previous-bookmark', `bmkp-previous-bookmark-repeat',
+;;    `bmkp-previous-bookmark-this-buffer',
+;;    `bmkp-previous-bookmark-this-buffer-repeat',
+;;    `bmkp-previous-bookmark-w32',
+;;    `bmkp-previous-bookmark-w32-repeat',
+;;    `bmkp-read-bookmark-for-type', `bmkp-region-jump',
+;;    `bmkp-region-jump-other-window', `bmkp-remote-file-jump',
+;;    `bmkp-remote-file-jump-other-window', `bmkp-remove-all-tags',
+;;    `bmkp-remove-tags', `bmkp-remove-tags-from-all',
+;;    `bmkp-rename-tag', `bmkp-send-bug-report',
+;;    `bmkp-set-autonamed-bookmark',
+;;    `bmkp-set-autonamed-bookmark-at-line',
+;;    `bmkp-set-autonamed-regexp-buffer',
+;;    `bmkp-set-autonamed-regexp-region',
+;;    `bmkp-set-bookmark-file-bookmark', `bmkp-set-desktop-bookmark',
+;;    `bmkp-set-restrictions-bookmark', `bmkp-set-tag-value',
+;;    `bmkp-set-tag-value-for-navlist',
+;;    `bmkp-set-variable-list-bookmark', `bmkp-some-tags-jump',
+;;    `bmkp-some-tags-jump-other-window',
+;;    `bmkp-some-tags-regexp-jump',
+;;    `bmkp-some-tags-regexp-jump-other-window',
+;;    `bmkp-specific-buffers-jump',
+;;    `bmkp-specific-buffers-jump-other-window',
+;;    `bmkp-specific-files-jump',
+;;    `bmkp-specific-files-jump-other-window',
+;;    `bmkp-switch-bookmark-file',
+;;    `bmkp-switch-to-last-bookmark-file',
+;;    `bmkp-this-buffer-bmenu-list', `bmkp-this-buffer-jump',
+;;    `bmkp-this-buffer-jump-other-window',
+;;    `bmkp-toggle-autonamed-bookmark-set/delete',
+;;    `bmkp-toggle-bookmark-set-refreshes',
+;;    `bmkp-toggle-saving-bookmark-file',
+;;    `bmkp-toggle-saving-menu-list-state',
+;;    `bmkp-toggle-bookmark-set-refreshes', `bmkp-unomit-all',
+;;    `bmkp-url-target-set', `bmkp-url-jump',
+;;    `bmkp-url-jump-other-window', `bmkp-use-bookmark-file-create',
+;;    `bmkp-variable-list-jump', `bmkp-version', `bmkp-w3m-jump',
+;;    `bmkp-w3m-jump-other-window', `old-bookmark-insert',
+;;    `old-bookmark-relocate'.
+;;
+;;  User options defined here:
+;;
+;;    `bmkp-autoname-bookmark-function', `bmkp-autoname-format',
+;;    `bmkp-bookmark-name-length-max', `bmkp-crosshairs-flag',
+;;    `bmkp-default-bookmark-name',
+;;    `bmkp-default-handler-associations',
+;;    `bmkp-desktop-no-save-vars', `bmkp-handle-region-function',
+;;    `bmkp-incremental-filter-delay', `bmkp-menu-popup-max-length',
+;;    `bmkp-other-window-pop-to-flag', `bmkp-prompt-for-tags-flag',
+;;    `bmkp-region-search-size', `bmkp-save-new-location-flag',
+;;    `bmkp-sequence-jump-display-function',
+;;    `bmkp-show-end-of-region', `bmkp-sort-comparer',
+;;    `bmkp-su-or-sudo-regexp',
+;;    `bmkp-this-buffer-cycle-sort-comparer', `bmkp-use-region',
+;;    `bmkp-w3m-allow-multi-tabs'.
+;;
+;;  Non-interactive functions defined here:
+;;
+;;    `bmkext-jump-gnus', `bmkext-jump-man', `bmkext-jump-w3m',
+;;    `bmkext-jump-woman', `bmkp-all-tags-alist-only',
+;;    `bmkp-all-tags-regexp-alist-only', `bmkp-alpha-cp',
+;;    `bmkp-alpha-p', `bmkp-annotated-alist-only',
+;;    `bmkp-autoname-bookmark', `bmkp-autonamed-alist-only',
+;;    `bmkp-autonamed-bookmark-for-buffer-p',
+;;    `bmkp-autonamed-bookmark-p',
+;;    `bmkp-autonamed-this-buffer-alist-only',
+;;    `bmkp-bookmark-creation-cp', `bmkp-bookmark-description',
+;;    `bmkp-bookmark-last-access-cp', `bmkp-bookmark-file-alist-only',
+;;    `bmkp-bookmark-list-alist-only',
+;;    `bmkp-bookmark-file-bookmark-p',
+;;    `bmkp-bookmark-list-bookmark-p', `bmkp-bookmark-type',
+;;    `bmkp-buffer-last-access-cp', `bmkp-buffer-names',
+;;    `bmkp-compilation-file+line-at', `bmkp-completing-read-1',
+;;    `bmkp-completing-read-buffer-name',
+;;    `bmkp-completing-read-file-name', `bmkp-completing-read-lax',
+;;    `bmkp-cp-not', `bmkp-create-variable-list-bookmark',
+;;    `bmkp-current-bookmark-list-state', `bmkp-current-sort-order',
+;;    `bmkp-cycle-1', `bmkp-default-bookmark-name',
+;;    `bmkp-default-handler-for-file', `bmkp-default-handler-user',
+;;    `bmkp-delete-autonamed-no-confirm',
+;;    `bmkp-delete-autonamed-this-buffer-no-confirm',
+;;    `bmkp-desktop-alist-only', `bmkp-desktop-bookmark-p',
+;;    `bmkp-desktop-kill', `bmkp-dired-alist-only',
+;;    `bmkp-dired-bookmark-p', `bmkp-dired-subdirs',
+;;    `bmkp-end-position-post-context',
+;;    `bmkp-end-position-pre-context', `bmkp-every', `bmkp-face-prop',
+;;    `bmkp-file-alist-only', `bmkp-file-alpha-cp',
+;;    `bmkp-file-attribute-0-cp', `bmkp-file-attribute-1-cp',
+;;    `bmkp-file-attribute-2-cp', `bmkp-file-attribute-3-cp',
+;;    `bmkp-file-attribute-4-cp', `bmkp-file-attribute-5-cp',
+;;    `bmkp-file-attribute-6-cp', `bmkp-file-attribute-7-cp',
+;;    `bmkp-file-attribute-8-cp', `bmkp-file-attribute-9-cp',
+;;    `bmkp-file-attribute-10-cp', `bmkp-file-attribute-11-cp',
+;;    `bmkp-file-bookmark-p', `bmkp-file-names', `bmkp-file-remote-p',
+;;    `bmkp-float-time', `bmkp-full-tag', `bmkp-function-bookmark-p',
+;;    `bmkp-get-buffer-name', `bmkp-get-end-position',
+;;    `bmkp-get-tag-value', `bmkp-get-tags', `bmkp-get-visit-time',
+;;    `bmkp-get-visits-count', `bmkp-gnus-alist-only',
+;;    `bmkp-gnus-bookmark-p', `bmkp-gnus-cp', `bmkp-goto-position',
+;;    `bmkp-handle-region-default', `bmkp-handler-cp',
+;;    `bmkp-has-tag-p', `bmkp-info-alist-only',
+;;    `bmkp-info-bookmark-p', `bmkp-info-cp', `bmkp-isearch-bookmarks'
+;;    (Emacs 23+), `bmkp-isearch-bookmarks-regexp' (Emacs 23+),
+;;    `bmkp-isearch-next-bookmark-buffer' (Emacs 23+), `bmkp-jump-1',
+;;    `bmkp-jump-bookmark-file', `bmkp-jump-bookmark-list',
+;;    `bmkp-jump-desktop', `bmkp-jump-dired', `bmkp-jump-function',
+;;    `bmkp-jump-gnus', `bmkp-jump-man', `bmkp-jump-sequence',
+;;    `bmkp-jump-url-browse', `bmkp-jump-variable-list',
+;;    `bmkp-jump-w3m', `bmkp-jump-w3m-new-session',
+;;    `bmkp-jump-w3m-only-one-tab', `bmkp-jump-woman',
+;;    `bmkp-last-specific-buffer-alist-only',
+;;    `bmkp-last-specific-buffer-p',
+;;    `bmkp-last-specific-file-alist-only',
+;;    `bmkp-last-specific-file-p', `bmkp-line-number-at-pos',
+;;    `bmkp-list-position', `bmkp-local-directory-bookmark-p',
+;;    `bmkp-local-file-accessed-more-recently-cp',
+;;    `bmkp-local-file-alist-only', `bmkp-local-file-bookmark-p',
+;;    `bmkp-local-file-size-cp', `bmkp-local-file-type-cp',
+;;    `bmkp-local-file-updated-more-recently-cp',
+;;    `bmkp-make-bookmark-file-record',
+;;    `bmkp-make-bookmark-list-record', `bmkp-make-desktop-record',
+;;    `bmkp-make-dired-record', `bmkp-make-gnus-record',
+;;    `bmkp-make-man-record', `bmkp-make-plain-predicate',
+;;    `bmkp-make-url-browse-record', `bmkp-make-variable-list-record',
+;;    `bmkp-make-w3m-record', `bmkp-make-woman-record' (Emacs 21+),
+;;    `bmkp-man-alist-only', `bmkp-man-bookmark-p',
+;;    `bmkp-marked-bookmark-p', `bmkp-marked-bookmarks-only',
+;;    `bmkp-marked-cp', `bmkp-maybe-save-bookmarks',
+;;    `bmkp-msg-about-sort-order', `bmkp-multi-sort',
+;;    `bmkp-non-autonamed-alist-only', `bmkp-non-file-alist-only',
+;;    `bmkp-non-file-bookmark-p', `bmkp-omitted-alist-only',
+;;    `bmkp-position-after-whitespace',
+;;    `bmkp-position-before-whitespace', `bmkp-position-cp',
+;;    `bmkp-position-post-context',
+;;    `bmkp-position-post-context-region',
+;;    `bmkp-position-pre-context', `bmkp-position-pre-context-region',
+;;    `bmkp-printable-p', `bmkp-printable-vars+vals',
+;;    `bmkp-read-bookmark-file-name', `bmkp-read-tag-completing',
+;;    `bmkp-read-tags', `bmkp-read-tags-completing',
+;;    `bmkp-read-variable', `bmkp-read-variables-completing',
+;;    `bmkp-record-visit', `bmkp-refresh-latest-bookmark-list',
+;;    `bmkp-refresh-menu-list',
+;;    `bmkp-regexp-filtered-annotation-alist-only',
+;;    `bmkp-regexp-filtered-bookmark-name-alist-only',
+;;    `bmkp-regexp-filtered-file-name-alist-only',
+;;    `bmkp-regexp-filtered-tags-alist-only',
+;;    `bmkp-region-alist-only', `bmkp-region-bookmark-p',
+;;    `bmkp-remote-file-alist-only', `bmkp-remote-file-bookmark-p',
+;;    `bmkp-remove-assoc-dups', `bmkp-remove-dups', `bmkp-remove-if',
+;;    `bmkp-remove-if-not', `bmkp-repeat-command',
+;;    `bmkp-root-or-sudo-logged-p', `bmkp-same-creation-time-p',
+;;    `bmkp-same-file-p', `bmkp-save-menu-list-state',
+;;    `bmkp-save-new-region-location',
+;;    `bmkp-select-buffer-other-window', `bmkp-sequence-bookmark-p',
+;;    `bmkp-set-tag-value-for-bookmarks', `bmkp-set-union',
+;;    `bmkp-some', `bmkp-some-marked-p', `bmkp-some-tags-alist-only',
+;;    `bmkp-some-tags-regexp-alist-only', `bmkp-some-unmarked-p'
+;;    `bmkp-sort-and-remove-dups', `bmkp-sound-jump',
+;;    `bmkp-specific-buffers-alist-only',
+;;    `bmkp-specific-files-alist-only', `bmkp-tag-name',
+;;    `bmkp-tags-list', `bmkp-this-buffer-alist-only',
+;;    `bmkp-this-buffer-p', `bmkp-this-file-alist-only',
+;;    `bmkp-this-file-p', `bmkp-unmarked-bookmarks-only',
+;;    `bmkp-upcase', `bmkp-update-autonamed-bookmark',
+;;    `bmkp-url-alist-only', `bmkp-url-bookmark-p',
+;;    `bmkp-url-browse-alist-only', `bmkp-url-browse-bookmark-p',
+;;    `bmkp-url-cp', `bmkp-variable-list-alist-only',
+;;    `bmkp-variable-list-bookmark-p', `bmkp-visited-more-cp',
+;;    `bmkp-w3m-alist-only', `bmkp-w3m-bookmark-p', `bmkp-w3m-cp',
+;;    `bmkp-w3m-set-new-buffer-name'.
+;;
+;;  Internal variables defined here:
+;;
+;;    `bmkp-after-set-hook', `bmkp-bookmark-file-history',
+;;    `bmkp-bookmark-list-history', `bmkp-current-bookmark-file',
+;;    `bmkp-current-nav-bookmark', `bmkp-desktop-history',
+;;    `bmkp-dired-history', `bmkp-edit-bookmark-record-mode-map',
+;;    `bmkp-file-history', `bmkp-gnus-history', `bmkp-highlight-menu',
+;;    `bmkp-info-history', `bmkp-isearch-bookmarks' (Emacs 23+),
+;;    `bmkp-jump-display-function', `bmkp-jump-map', `bmkp-jump-menu',
+;;    `bmkp-jump-other-window-map', `bmkp-last-bmenu-state-file',
+;;    `bmkp-last-bookmark-file', `bmkp-last-save-flag-value',
+;;    `bmkp-last-specific-buffer', `bmkp-last-specific-file',
+;;    `bmkp-latest-bookmark-alist', `bmkp-local-file-history',
+;;    `bmkp-man-history', `bmkp-nav-alist', `bmkp-non-file-filename',
+;;    `bmkp-non-file-history', `bmkp-options-menu',
+;;    `bmkp-region-history', `bmkp-remote-file-history',
+;;    `bmkp-reverse-multi-sort-p', `bmkp-reverse-sort-p',
+;;    `bmkp-sorted-alist', `bmkp-specific-buffers-history',
+;;    `bmkp-specific-files-history', `bmkp-tag-history',
+;;    `bmkp-tags-alist', `bmkp-types-alist', `bmkp-url-history',
+;;    `bmkp-use-w32-browser-p', `bmkp-variable-list-history',
+;;    `bmkp-version-number', `bmkp-w3m-history'.
+;;
+;;
+;;  ***** NOTE: The following commands defined in `bookmark.el'
+;;              have been REDEFINED HERE:
+;;
+;;    `bookmark-delete', `bookmark-edit-annotation',
+;;    `bookmark-edit-annotation-mode', `bookmark-insert',
+;;    `bookmark-insert-location', `bookmark-jump',
+;;    `bookmark-jump-other-window', `bookmark-load',
+;;    `bookmark-relocate', `bookmark-rename', `bookmark-save',
+;;    `bookmark-send-edited-annotation', `bookmark-set',
+;;    `bookmark-yank-word'.
+;;
+;;
+;;  ***** NOTE: The following non-interactive functions defined in
+;;              `bookmark.el' have been REDEFINED HERE:
+;;
+;;    `bookmark--jump-via', `bookmark-all-names',
+;;    `bookmark-completing-read', `bookmark-default-handler',
+;;    `bookmark-exit-hook-internal', `bookmark-get-bookmark' (Emacs
+;;    20-22), `bookmark-get-bookmark-record' (Emacs 20-22),
+;;    `bookmark-get-handler' (Emacs 20-22),
+;;    `bookmark-handle-bookmark', `bookmark-jump-noselect' (Emacs
+;;    20-22), `bookmark-location', `bookmark-make-record' (Emacs
+;;    20-22), `bookmark-make-record-default', `bookmark-maybe-message'
+;;    (Emacs 20-21), `bookmark-prop-get' (Emacs 20-22),
+;;    `bookmark-prop-set', `bookmark-show-annotation',
+;;    `bookmark-show-all-annotations', `bookmark-store' (Emacs 20-22),
+;;    `bookmark-write-file'.
+;;
+;;
+;;  ***** NOTE: The following variables defined in `bookmark.el'
+;;              have been REDEFINED HERE:
+;;
+;;    `bookmark-alist' (doc string only),
+;;    `bookmark-make-record-function' (Emacs 20-22).
+;;
+;;
+;;  ***** NOTE: The following functions defined in `info.el'
+;;              have been REDEFINED HERE:
+;;
+;;    `Info-bookmark-jump' (Emacs 20-22), `Info-bookmark-make-record'
+;;    (Emacs 20-22).
+;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;
+;; 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 3, 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.
+;;
+;; You should have received a copy of the GNU General Public License
+;; along with this program; see the file COPYING.  If not, write to
+;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
+;; Floor, Boston, MA 02110-1301, USA.
+;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;
+
+;;; Code:
+
+;;;;;;;;;;;;;;;;;;;;;;;
+
+(unless (fboundp 'file-remote-p) (require 'ffap)) ;; ffap-file-remote-p
+(eval-when-compile (require 'gnus)) ;; mail-header-id (really in `nnheader.el')
+(eval-when-compile (require 'gnus-sum)) ;; gnus-summary-article-header
+(eval-when-compile (require 'cl)) ;; case, multiple-value-bind
+
+(require 'bookmark)
+;; bookmark-alist, bookmark-alist-from-buffer,
+;; bookmark-alist-modification-count, bookmark-annotation-name,
+;; bookmark-automatically-show-annotations, bookmark-bmenu-bookmark,
+;; bookmark-bmenu-surreptitiously-rebuild-list,
+;; bookmark-bmenu-toggle-filenames, bookmark-buffer-file-name,
+;; bookmark-buffer-name, bookmark-completion-ignore-case,
+;; bookmark-current-bookmark, bookmark-default-file,
+;; bookmark-edit-annotation, bookmark-get-annotation,
+;; bookmark-get-bookmark, bookmark-get-bookmark-record,
+;; bookmark-get-filename, bookmark-get-front-context-string,
+;; bookmark-get-handler, bookmark-get-position,
+;; bookmark-get-rear-context-string, bookmark-import-new-list,
+;; bookmark-insert-file-format-version-stamp, bookmark-kill-line,
+;; bookmark-make-record, bookmark-maybe-historicize-string,
+;; bookmark-maybe-load-default-file, bookmark-maybe-message,
+;; bookmark-maybe-upgrade-file-format, bookmark-menu-popup-paned-menu,
+;; bookmark-name-from-full-record, bookmark-name-from-record,
+;; bookmark-popup-menu-and-apply-function, bookmark-prop-get,
+;; bookmarks-already-loaded, bookmark-save-flag, bookmark-search-size,
+;; bookmark-set-annotation, bookmark-set-filename, bookmark-set-name,
+;; bookmark-set-position, bookmark-store, bookmark-time-to-save-p,
+;; bookmark-use-annotations, bookmark-version-control,
+;; bookmark-yank-point
+
+;;; Fix incompatibility introduced by gratuitous Emacs name change.
+(cond ((and (fboundp 'bookmark-name-from-record) (not (fboundp 'bookmark-name-from-full-record)))
+       (defalias 'bookmark-name-from-full-record 'bookmark-name-from-record))
+      ((and (fboundp 'bookmark-name-from-full-record) (not (fboundp 'bookmark-name-from-record)))
+       (defalias 'bookmark-name-from-record 'bookmark-name-from-full-record)))
+
+(require 'bookmark+-mac)
+;; bmkp-define-cycle-command, bmkp-define-file-sort-predicate, bmkp-menu-bar-make-toggle,
+;; bmkp-replace-regexp-in-string
+
+(eval-when-compile (require 'bookmark+-bmu))
+;; bmkp-bmenu-before-hide-marked-alist,
+;; bmkp-bmenu-before-hide-unmarked-alist, bmkp-bmenu-commands-file,
+;; bmkp-bmenu-filter-function, bmkp-bmenu-filter-pattern,
+;; bmkp-bmenu-first-time-p, bmkp-bmenu-goto-bookmark-named,
+;; bmkp-bmenu-marked-bookmarks, bmkp-bmenu-menubar-menu,
+;; bmkp-bmenu-omitted-list, bmkp-bmenu-refresh-menu-list,
+;; bmkp-bmenu-show-all, bmkp-bmenu-state-file, bmkp-bmenu-title,
+;; bmkp-sort-orders-alist
+
+;; (eval-when-compile (require 'bookmark+-lit nil t))
+;; bmkp-light-bookmark, bmkp-light-bookmarks, bmkp-light-this-buffer
+
+
+;; For the redefinition of `bookmark-get-bookmark' in Emacs < 23.
+(provide 'bookmark+-1)                  ; Ensure this library is loaded before we compile it.
+(require 'bookmark+-1)                  ; So be sure to put this library in your `load-path' before
+                                        ; trying to byte-compile it.
+
+;;;;;;;;;;;;;;;;;;;;;;;
+
+;; Quiet the byte-compiler
+(defvar bookmark-current-point)         ; Defined in `bookmark.el', but not in Emacs 23+.
+(defvar bookmark-edit-annotation-text-func) ; Defined in `bookmark.el'.
+(defvar bookmark-read-annotation-text-func) ; Defined in `bookmark.el', but not in Emacs 23+.
+(defvar bookmark-make-record-function)  ; Defined in `bookmark.el'.
+(defvar desktop-buffer-args-list)       ; Defined in `desktop.el'.
+(defvar desktop-delay-hook)             ; Defined in `desktop.el'.
+(defvar desktop-dirname)                ; Defined in `desktop.el'.
+(defvar desktop-file-modtime)           ; Defined in `desktop.el'.
+(defvar desktop-globals-to-save)        ; Defined in `desktop.el'.
+(defvar desktop-save-mode)              ; Defined in `desktop.el'.
+(defvar desktop-save)                   ; Defined in `desktop.el'.
+(defvar dired-actual-switches)          ; Defined in `dired.el'.
+(defvar dired-buffers)                  ; Defined in `dired.el'.
+(defvar dired-directory)                ; Defined in `dired.el'.
+(defvar dired-guess-shell-case-fold-search) ; Defined in `dired-x.el'.
+(defvar dired-mode-map)                 ; Defined in `dired.el'.
+(defvar dired-subdir-alist)             ; Defined in `dired.el'.
+(defvar diredp-menu-bar-subdir-menu)    ; Defined in `dired+.el'.
+(defvar gnus-article-current)           ; Defined in `gnus-sum.el'.
+(defvar Info-current-node)              ; Defined in `info.el'.
+(defvar Info-current-file)              ; Defined in `info.el'.
+(defvar Info-mode-map)                  ; Defined in `info.el'.
+(defvar Info-mode-menu)                 ; Defined in `info.el'.
+(defvar Man-arguments)                  ; Defined in `man.el'.
+(defvar Man-mode-map)                   ; Defined in `man.el'.
+(defvar mouse-wheel-down-event)         ; Defined in `mwheel.el'.
+(defvar mouse-wheel-up-event)           ; Defined in `mwheel.el'.
+(defvar read-file-name-completion-ignore-case) ; Emacs 23+.
+(defvar last-repeatable-command)        ; Defined in `repeat.el'.
+(defvar repeat-previous-repeated-command) ; Defined in `repeat.el'.
+(defvar w3m-current-title)              ; Defined in `w3m.el'.
+(defvar w3m-current-url)                ; Defined in `w3m.el'.
+(defvar w3m-minor-mode-map)             ; Defined in `w3m.el'.
+(defvar w3m-mode-map)                   ; Defined in `w3m.el'.
+(defvar wide-n-restrictions)            ; Defined in `wide-n.el'.
+(defvar woman-last-file-name)           ; Defined in `woman.el'.
+(defvar woman-menu)                     ; Defined in `woman.el'.
+(defvar woman-mode-map)                 ; Defined in `woman.el'.
+ 
+;;(@* "User Options (Customizable)")
+;;; User Options (Customizable) --------------------------------------
+
+;;;###autoload
+(defcustom bmkp-autoname-bookmark-function 'bmkp-autoname-bookmark
+  "*Function to automatically name a bookmark at point (cursor position)."
+  :type 'function :group 'bookmark-plus)
+
+;;;###autoload
+(defcustom bmkp-autoname-format (if (> emacs-major-version 21) "^[0-9]\\{9\\} %s" "^[0-9]+ %s")
+  "*Format string to match an autonamed bookmark name.
+It must have a single `%s' that to accept the buffer name."
+  :type 'string :group 'bookmark-plus)
+
+;;;###autoload
+(defcustom bmkp-crosshairs-flag (> emacs-major-version 21)
+  "*Non-nil means highlight with crosshairs when you visit a bookmark.
+The highlighting is temporary - until your next action.
+You need library `crosshairs.el' for this feature, and you need Emacs
+22 or later.
+
+If you use this option in Lisp code, you will want to add/remove
+`bmkp-crosshairs-highlight' to/from `bookmark-after-jump-hook'."
+  :set (lambda (sym new-val)