emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: isearch-allow-move [Was: isearch-allow-prefix]


From: Juri Linkov
Subject: Re: isearch-allow-move [Was: isearch-allow-prefix]
Date: Fri, 07 Jun 2013 09:59:49 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (x86_64-pc-linux-gnu)

> But what does it mean to C-f with a prefix arg of -1?  Does it mean
> "remove the last char from the search string"?  If not, why not?
> Or maybe a negative prefix argument would cause the command to be ignored.
>
> Or maybe C-b would be allowed here to remove the last char from the
> search string.

Good idea.  This is implemented now by this patch (cumulative to
the previously sent one) where `C-b' or `C-u -1 C-f' removes the
last char from the search string (`M-b' removes the last word,
`C-M-b' removes the last expression, etc. allowing key sequences like
`M-s C-b M-b C-M-b'), and eventually stops removing characters at the
beginning of the current match when the search string becomes empty.
Is this approach simple enough and intuitive?

=== modified file 'lisp/isearch.el'
--- lisp/isearch.el     2013-06-07 04:57:40 +0000
+++ lisp/isearch.el     2013-06-07 06:51:29 +0000
@@ -2367,11 +2370,17 @@ (defvar isearch-allow-move-temporarily n
 the value of this variable is set to nil.")
 
 (put 'right-char 'isearch-move t)
+(put 'left-char 'isearch-move t)
 (put 'forward-char 'isearch-move t)
+(put 'backward-char 'isearch-move t)
 (put 'forward-word 'isearch-move t)
+(put 'backward-word 'isearch-move t)
 (put 'forward-sexp 'isearch-move t)
+(put 'backward-sexp 'isearch-move t)
 (put 'forward-paragraph 'isearch-move t)
+(put 'backward-paragraph 'isearch-move t)
 (put 'move-end-of-line 'isearch-move t)
+(put 'move-beginning-of-line 'isearch-move t)
 
 ;; Handle universal argument for motion commands when both
 ;; `isearch-allow-scroll' and `isearch-allow-prefix' are nil.
@@ -2546,9 +2549,25 @@ (defun isearch-other-meta-char (&optiona
                                           ;; Use the last key in the sequence.
                                           (vector (aref key (1- (length 
key))))))))
           (setq prefix-arg arg)
-          (isearch-yank-internal
-           (lambda () (command-execute move-command) (point)))
-          (isearch-update)
+          (let* ((old-point (or (and (not isearch-forward) isearch-other-end)
+                                (point)))
+                 (new-point (save-excursion
+                              (goto-char old-point)
+                              (command-execute move-command)
+                              (point))))
+            (if (< old-point new-point)
+                ;; Add text to the search string.
+                (isearch-yank-string
+                 (buffer-substring-no-properties old-point new-point))
+              ;; Remove text from the search string.
+              (setq isearch-string (substring isearch-string 0
+                                              (max (- (length isearch-string)
+                                                      (- old-point new-point)) 
0))
+                    isearch-message (mapconcat 'isearch-text-char-description
+                                               isearch-string ""))
+              ;; Don't move cursor in reverse search.
+              (setq isearch-yank-flag t)
+              (isearch-search-and-update)))
           (setq isearch-allow-move-temporarily t))
          ;; A mouse click on the isearch message starts editing the search 
string
          ((and (eq (car-safe main-event) 'down-mouse-1)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]