# HG changeset patch # User Stefan Monnier # Date 1258778590 0 # Node ID 0cc25cd9870d74e4f8c964f6f785a2d327941347 # Parent 3f65383da746db0ccf9cb6717d9fdaf2650b28b0 (bookmark-search-prompt, bookmark-search-timer): Remove. (bookmark-search-pattern): Move and leave unbound. (bookmark-bmenu-mode-map): Change binding. (bookmark-read-search-input): Simplify. Don't use text-char-description. Don't error on non-char events. (bookmark-filtered-alist-by-regexp-only): Remove by folding into the only caller (i.e. bookmark-bmenu-filter-alist-by-regexp). (bookmark-bmenu-search): Don't check we're in a bookmark-list buffer. Use a local var for the timer. (bookmark-bmenu-cancel-search): Remove by folding into the only caller (i.e. bookmark-bmenu-search). diff -r 3f65383da746 -r 0cc25cd9870d lisp/ChangeLog --- a/lisp/ChangeLog Sat Nov 21 02:36:54 2009 +0000 +++ b/lisp/ChangeLog Sat Nov 21 04:43:10 2009 +0000 @@ -1,11 +1,25 @@ +2009-11-21 Stefan Monnier + + * bookmark.el (bookmark-search-prompt, bookmark-search-timer): Remove. + (bookmark-search-pattern): Move and leave unbound. + (bookmark-bmenu-mode-map): Change binding. + (bookmark-read-search-input): Simplify. + Don't use text-char-description. Don't error on non-char events. + (bookmark-filtered-alist-by-regexp-only): Remove by folding into the + only caller (i.e. bookmark-bmenu-filter-alist-by-regexp). + (bookmark-bmenu-search): Don't check we're in a bookmark-list buffer. + Use a local var for the timer. + (bookmark-bmenu-cancel-search): Remove by folding into the only caller + (i.e. bookmark-bmenu-search). + 2009-11-21 Glenn Morris * mail/rmailmm.el (rmail-mime): Decode in fundamental-mode. (Bug#4993) 2009-11-20 Ken Brown (tiny change) - * net/browse-url.el (browse-url-default-windows-browser): Use - cygstart for cygwin. + * net/browse-url.el (browse-url-default-windows-browser): + Use cygstart for cygwin. 2009-11-20 Karl Fogel @@ -23,16 +37,16 @@ * subword.el (subword-forward, subword-backward, subword-mark) (subword-kill, subword-backward-kill, subword-transpose) (subword-downcase, subword-upcase, subword-capitalize) - (subword-forward-internal, subword-backward-internal): Renamed - from forward-subword, backward-subword, mark-subword kill-subword, - backward-kill-subword, transpose-subwords, downcase-subword, - upcase-subword, capitalize-subword forward-subword-internal, - backward-subword-internal. + (subword-forward-internal, subword-backward-internal): + Rename from forward-subword, backward-subword, mark-subword, + kill-subword, backward-kill-subword, transpose-subwords, + downcase-subword, upcase-subword, capitalize-subword, + forward-subword-internal, backward-subword-internal. 2009-11-20 Thierry Volpiatto - * bookmark.el (bookmark-search-delay, bookmark-search-prompt): New - options. + * bookmark.el (bookmark-search-delay, bookmark-search-prompt): + New options. (bookmark-search-pattern, bookmark-search-timer, bookmark-quit-flag): New vars. (bookmark-read-search-input, bookmark-filtered-alist-by-regexp-only) diff -r 3f65383da746 -r 0cc25cd9870d lisp/bookmark.el --- a/lisp/bookmark.el Sat Nov 21 02:36:54 2009 +0000 +++ b/lisp/bookmark.el Sat Nov 21 04:43:10 2009 +0000 @@ -196,19 +196,12 @@ :type 'integer :group 'bookmark) - +;; FIXME: Is it really worth a customization option? (defcustom bookmark-search-delay 0.2 - "*When searching bookmarks, redisplay every `bookmark-search-delay' seconds." + "Time before `bookmark-bmenu-search' updates the display." :group 'bookmark :type 'integer) - -(defcustom bookmark-search-prompt "Pattern: " - "*Prompt used for `bookmark-bmenu-search'." - :group 'bookmark - :type 'string) - - (defface bookmark-menu-heading '((t (:inherit font-lock-type-face))) "Face used to highlight the heading in bookmark menu buffers." @@ -332,18 +325,8 @@ This point is in `bookmark-curent-buffer'.") -(defvar bookmark-search-pattern "" - "Store keyboard input for incremental search.") - - -(defvar bookmark-search-timer nil - "Timer used for searching") - - (defvar bookmark-quit-flag nil "Non nil make `bookmark-bmenu-search' quit immediately.") - - ;; Helper functions. @@ -1549,7 +1532,9 @@ (define-key map "a" 'bookmark-bmenu-show-annotation) (define-key map "A" 'bookmark-bmenu-show-all-annotations) (define-key map "e" 'bookmark-bmenu-edit-annotation) - (define-key map "\M-g" 'bookmark-bmenu-search) + ;; The original binding of M-g hides the M-g prefix map. + ;; If someone has a better idea than M-g s, I'm open to suggestions. + (define-key map [?\M-g ?s] 'bookmark-bmenu-search) (define-key map [mouse-2] 'bookmark-bmenu-other-window-with-mouse) map)) @@ -2099,69 +2084,58 @@ ;;; Bookmark-bmenu search +;; Store keyboard input for incremental search. +(defvar bookmark-search-pattern) + (defun bookmark-read-search-input () "Read each keyboard input and add it to `bookmark-search-pattern'." - (setq bookmark-search-pattern "") ; Always reset pattern to empty string - (let ((prompt (propertize bookmark-search-prompt - 'face '((:foreground "cyan")))) - (inhibit-quit t) - (tmp-list ()) - char) - (catch 'break - (while 1 - (catch 'continue - (condition-case nil - (setq char (read-char (concat prompt bookmark-search-pattern))) - (error (throw 'break nil))) + (let ((prompt (propertize "Pattern: " 'face 'minibuffer-prompt)) + ;; (inhibit-quit t) ; inhibit-quit is evil. Use it with extreme care! + (tmp-list ())) + (while + (let ((char (read-key (concat prompt bookmark-search-pattern)))) (case char - ((or ?\e ?\r) ; RET or ESC break search loop and lead to [1]. - (throw 'break nil)) - (?\d (pop tmp-list) ; Delete last char of `bookmark-search-pattern' - (setq bookmark-search-pattern - (mapconcat 'identity (reverse tmp-list) "")) - (throw 'continue nil)) - (?\C-g (setq bookmark-quit-flag t) (throw 'break nil)) + ((?\e ?\r) nil) ; RET or ESC break the search loop. + (?\C-g (setq bookmark-quit-flag t) nil) + (?\d (pop tmp-list) t) ; Delete last char of pattern with DEL (t - (push (text-char-description char) tmp-list) - (setq bookmark-search-pattern - (mapconcat 'identity (reverse tmp-list) "")) - (throw 'continue nil)))))))) - - -(defun bookmark-filtered-alist-by-regexp-only (regexp) - "Return a filtered `bookmark-alist' with bookmarks matching REGEXP." - (loop for i in bookmark-alist - when (string-match regexp (car i)) collect i into new - finally return new)) + (if (characterp char) + (push char tmp-list) + (setq unread-command-events + (nconc (mapcar 'identity + (this-single-command-raw-keys)) + unread-command-events)) + nil)))) + (setq bookmark-search-pattern + (apply 'string (reverse tmp-list)))))) (defun bookmark-bmenu-filter-alist-by-regexp (regexp) "Filter `bookmark-alist' with bookmarks matching REGEXP and rebuild list." - (let ((bookmark-alist (bookmark-filtered-alist-by-regexp-only regexp))) + (let ((bookmark-alist + (loop for i in bookmark-alist + when (string-match regexp (car i)) collect i into new + finally return new))) (bookmark-bmenu-list))) + ;;;###autoload (defun bookmark-bmenu-search () - "Incrementally search bookmarks matching `bookmark-search-pattern'. -`bookmark-search-pattern' is built incrementally with -`bookmark-read-search-input'." + "Incremental search of bookmarks, hiding the non-matches as we go." (interactive) - (when (string= (buffer-name (current-buffer)) "*Bookmark List*") - (let ((bmk (bookmark-bmenu-bookmark))) - (unwind-protect - (progn - (setq bookmark-search-timer - (run-with-idle-timer - bookmark-search-delay 'repeat - #'(lambda () - (bookmark-bmenu-filter-alist-by-regexp - bookmark-search-pattern)))) - (bookmark-read-search-input)) - (progn ; [1] Stop timer. - (bookmark-bmenu-cancel-search) - (when bookmark-quit-flag ; C-g hit restore menu list. - (bookmark-bmenu-list) (bookmark-bmenu-goto-bookmark bmk)) - (setq bookmark-quit-flag nil)))))) + (let ((bmk (bookmark-bmenu-bookmark)) + (bookmark-search-pattern "") + (timer (run-with-idle-timer + bookmark-search-delay 'repeat + #'(lambda () + (bookmark-bmenu-filter-alist-by-regexp + bookmark-search-pattern))))) + (unwind-protect + (bookmark-read-search-input) + (cancel-timer timer) + (when bookmark-quit-flag ; C-g hit restore menu list. + (bookmark-bmenu-list) (bookmark-bmenu-goto-bookmark bmk)) + (setq bookmark-quit-flag nil)))) (defun bookmark-bmenu-goto-bookmark (name) "Move point to bookmark with name NAME." @@ -2172,11 +2146,6 @@ (forward-line 0)) -(defun bookmark-bmenu-cancel-search () - "Cancel timer used for searching in bookmarks." - (cancel-timer bookmark-search-timer) - (setq bookmark-search-timer nil)) - ;;; Menu bar stuff. Prefix is "bookmark-menu".