Thank you for the bug report. I hope it is possible to fix this
undesirable behavior by using the HISTPOS argument of read-from-
minibuffer
where HISTPOS will point to the correct history position in the
search
ring. This also gives us the opportunity to rewrite isearch-edit-
string
to remove unnecessary ad-hoc minibuffer precessing tricks that
cause the
incorrect behavior you described in the second part of your bug
report.
Below is a patch that fixes all these problems. It uses
search-ring-yank-pointer and regexp-search-ring-yank-pointer
for the HISTPOS argument of read-from-minibuffer that gives
the correct initial minibuffer search history position for
isearch-edit-string.
It also gets rid of all trickery used to read the first character
typed in the minibuffer (that removes another set of problems;
see related old bug reports). It adds a new backward-compatible
command `isearch-edit-string-set-word' bound to C-w in the minibuffer
that calls `kill-region' when the mark is active, and otherwise does
word search after exiting `isearch-edit-string' (the mark is not
active
when `isearch-edit-string' just created the minibuffer, and without
the mark `kill-region' would fail anyway).
This preserves the behavior described in the Emacs manual:
`C-s <RET> C-w WORDS <RET>'
Search for WORDS, ignoring details of punctuation.
Index: lisp/isearch.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/isearch.el,v
retrieving revision 1.313
diff -c -r1.313 isearch.el
*** lisp/isearch.el 28 Feb 2008 01:57:42 -0000 1.313
--- lisp/isearch.el 9 Mar 2008 21:57:02 -0000
***************
*** 436,441 ****
--- 436,442 ----
(define-key map "\M-\t" 'isearch-complete-edit)
(define-key map "\C-s" 'isearch-forward-exit-minibuffer)
(define-key map "\C-r" 'isearch-reverse-exit-minibuffer)
+ (define-key map "\C-w" 'isearch-edit-string-set-word)
(define-key map "\C-f" 'isearch-yank-char-in-minibuffer)
(define-key map [right] 'isearch-yank-char-in-minibuffer)
map)
***************
*** 1025,1061 ****
;; that can change their values.
(setq old-point (point) old-other-end isearch-other-end)
- (isearch-message) ;; for read-char
(unwind-protect
! (let* (;; Why does following read-char echo?
! ;;(echo-keystrokes 0) ;; not needed with above message
! (e (let ((cursor-in-echo-area t))
! (read-event)))
;; Binding minibuffer-history-symbol to nil is a
work-around
;; for some incompatibility with gmhist.
! (minibuffer-history-symbol)
! (message-log-max nil))
! ;; If the first character the user types when we prompt them
! ;; for a string is the yank-word character, then go into
! ;; word-search mode. Otherwise unread that character and
! ;; read a key the normal way.
! ;; Word search does not apply (yet) to regexp searches,
! ;; no check is made here.
! (message "%s" (isearch-message-prefix nil nil t))
! (if (memq (lookup-key isearch-mode-map (vector e))
! '(isearch-yank-word
! isearch-yank-word-or-char))
! (setq isearch-word t;; so message-prefix is right
! isearch-new-word t)
! (cancel-kbd-macro-events)
! (isearch-unread e))
! (setq cursor-in-echo-area nil)
(setq isearch-new-string
(read-from-minibuffer
(isearch-message-prefix nil nil isearch-
nonincremental)
isearch-string
minibuffer-local-isearch-map nil
! (if isearch-regexp 'regexp-search-ring
'search-ring)
nil t)
isearch-new-message
(mapconcat 'isearch-text-char-description
--- 1026,1046 ----
;; that can change their values.
(setq old-point (point) old-other-end isearch-other-end)
(unwind-protect
! (let* ((message-log-max nil)
;; Binding minibuffer-history-symbol to nil is a
work-around
;; for some incompatibility with gmhist.
! (minibuffer-history-symbol))
(setq isearch-new-string
(read-from-minibuffer
(isearch-message-prefix nil nil isearch-
nonincremental)
isearch-string
minibuffer-local-isearch-map nil
! (if isearch-regexp
! (cons 'regexp-search-ring
! (1+ (or regexp-search-ring-yank-pointer -1)))
! (cons 'search-ring
! (1+ (or search-ring-yank-pointer -1))))
nil t)
isearch-new-message
(mapconcat 'isearch-text-char-description
***************
*** 1116,1121 ****
--- 1101,1116 ----
(isearch-abort) ;; outside of let to restore outside global
values
)))
+ (defun isearch-edit-string-set-word ()
+ "Do word search after exiting `isearch-edit-string'.
+ If the mark is not active in the search string editing minibuffer,
+ then after exiting `isearch-edit-string', do word search.
+ Otherwise, kill text between point and mark in the minibuffer."
+ (interactive)
+ (if mark-active
+ (kill-region (point) (mark))
+ (setq isearch-word t isearch-new-word t)))
+
(defun isearch-nonincremental-exit-minibuffer ()
(interactive)
(setq isearch-nonincremental t)
--
Juri Linkov
http://www.jurta.org/emacs/