From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: isearch-allow-move [Was: isearch-allow-prefix] Date: Thu, 06 Jun 2013 09:07:34 +0300 Organization: JURTA Message-ID: <8761xr93h5.fsf_-_@mail.jurta.org> References: <87txlts7so.fsf@mail.jurta.org> <20130524093858.GA2754@acm.acm> <87hahstd47.fsf@mail.jurta.org> <20130525200103.GA3451@acm.acm> <878v32aj3c.fsf@mail.jurta.org> <20130602210512.GC2765@acm.acm> <87sj0xn484.fsf@mail.jurta.org> <20130604212400.GB2492@acm.acm> <87d2s1otjb.fsf@mail.jurta.org> <20130605210241.GA3730@acm.acm> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1370499501 24932 80.91.229.3 (6 Jun 2013 06:18:21 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 6 Jun 2013 06:18:21 +0000 (UTC) Cc: Stefan Monnier , Drew Adams , emacs-devel@gnu.org To: Alan Mackenzie Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jun 06 08:18:20 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UkTWd-0007xO-D6 for ged-emacs-devel@m.gmane.org; Thu, 06 Jun 2013 08:18:19 +0200 Original-Received: from localhost ([::1]:57192 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UkTWc-00083B-US for ged-emacs-devel@m.gmane.org; Thu, 06 Jun 2013 02:18:18 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39617) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UkTWU-00081I-LA for emacs-devel@gnu.org; Thu, 06 Jun 2013 02:18:16 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UkTWP-0001ct-IO for emacs-devel@gnu.org; Thu, 06 Jun 2013 02:18:10 -0400 Original-Received: from ps18281.dreamhost.com ([69.163.218.105]:36560 helo=ps18281.dreamhostps.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UkTWP-0001bm-9p for emacs-devel@gnu.org; Thu, 06 Jun 2013 02:18:05 -0400 Original-Received: from localhost (ps18281.dreamhostps.com [69.163.218.105]) by ps18281.dreamhostps.com (Postfix) with ESMTP id 7DE22258B9E91C; Wed, 5 Jun 2013 23:18:02 -0700 (PDT) In-Reply-To: <20130605210241.GA3730@acm.acm> (Alan Mackenzie's message of "Wed, 5 Jun 2013 21:02:41 +0000") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (x86_64-pc-linux-gnu) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-Received-From: 69.163.218.105 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:160155 Archived-At: > OK, I've committed it. Thank you, Alan. Let me reuse your excellent design and create a similar option `isearch-allow-move' that is like `isearch-allow-scroll' but instead of scrolling commands it affects point motion commands to yank text as you go. So typing `C-f' will pull the next char from the buffer and add it to the search string, `M-f' - next word, `C-M-f' - next expression, `M-}' - next paragraph, `C-e' - next line, and so on. Definitely `isearch-allow-move' should be nil by default, and I doubt that many users might want to enable it since it's more useful when motion commands exit Isearch. But to make this feature available regardless of the value of `isearch-allow-move' it could be activated temporarily by the keymap `M-s' to allow key sequences like `M-s C-f M-f C-M-f C-e' that is implemented by this patch: === modified file 'lisp/isearch.el' --- lisp/isearch.el 2013-06-05 20:57:09 +0000 +++ lisp/isearch.el 2013-06-06 06:04:35 +0000 @@ -513,6 +550,10 @@ (defvar isearch-mode-map (define-key map "\M-r" 'isearch-toggle-regexp) (define-key map "\M-e" 'isearch-edit-string) + (let ((s-map (make-sparse-keymap))) + (define-key map "\M-s" s-map) + (define-key s-map [t] 'isearch-other-move-char)) + (define-key map "\M-sc" 'isearch-toggle-case-fold) (define-key map "\M-si" 'isearch-toggle-invisible) (define-key map "\M-sr" 'isearch-toggle-regexp) @@ -668,6 +732,7 @@ (define-key esc-map "\C-r" 'isearch-back (define-key search-map "w" 'isearch-forward-word) (define-key search-map "_" 'isearch-forward-symbol) (define-key search-map "." 'isearch-forward-symbol-at-point) +(define-key search-map [t] 'isearch-forward-other-move-char) ;; Entry points to isearch-mode. @@ -987,6 +1057,7 @@ (defun isearch-update () ;; We must prevent the point moving to the end of composition when a ;; part of the composition has just been searched. (setq disable-point-adjustment t) + (setq isearch-allow-move-temporarily nil) (run-hooks 'isearch-update-post-hook)) (defun isearch-done (&optional nopush edit) @@ -2160,6 +2287,42 @@ (defcustom isearch-allow-prefix t :type 'boolean :group 'isearch) +(defcustom isearch-allow-move nil + "Whether cursor movement is allowed during incremental search. +If non-nil, point motion commands can be used in Isearch mode. +They add the passed text to the search string. +If nil, motion commands will first cancel Isearch mode." + :type 'boolean + :version "24.4" + :group 'isearch) + +(defvar isearch-allow-move-temporarily nil + "Enable yanking text by point motion commands temporarily. +It is enabled on `M-s' and a subsequent point motion command and allows +any subsequent point motion command to add the passed text to the +search string as they go allowing key sequences like `M-s C-f M-f C-M-f' +to add next character, next word, and next expression to the search string. +Any subsequent isearch command that is not a point motion command, +the value of this variable is set to nil.") + +(put 'right-char 'isearch-move t) +(put 'forward-char 'isearch-move t) +(put 'forward-word 'isearch-move t) +(put 'forward-sexp 'isearch-move t) +(put 'forward-paragraph 'isearch-move t) +(put 'move-end-of-line 'isearch-move t) + +;; Handle universal argument for motion commands when both +;; `isearch-allow-scroll' and `isearch-allow-prefix' are nil. +(put 'universal-argument 'isearch-move t) +(put 'negative-argument 'isearch-move t) +(put 'digit-argument 'isearch-move t) + (defun isearch-string-out-of-window (isearch-point) "Test whether the search string is currently outside of the window. Return nil if it's completely visible, or if point is visible, @@ -2224,6 +2388,26 @@ (defun isearch-lookup-scroll-key (key-se (eq (get binding 'scroll-command) t)) binding))) +(defun isearch-lookup-move-key (key-seq) + "If KEY-SEQ is bound to a motion command, return it as a symbol. +Otherwise return nil." + (let* ((overriding-terminal-local-map nil) + (binding (key-binding key-seq))) + (and binding (symbolp binding) (commandp binding) + (eq (get binding 'isearch-move) t) + binding))) + +(defun isearch-other-move-char (&optional arg) + (interactive "P") + (setq isearch-allow-move-temporarily t) + (isearch-other-meta-char arg)) + +(defun isearch-forward-other-move-char (&optional arg) + "Do incremental search starting with a motion command that yanks text." + (interactive "P") + (isearch-forward nil 1) + (isearch-other-move-char arg)) + (defalias 'isearch-other-control-char 'isearch-other-meta-char) (defun isearch-other-meta-char (&optional arg) @@ -2336,7 +2525,22 @@ (defun isearch-other-meta-char (&optiona (if ab-bel (isearch-back-into-window (eq ab-bel 'above) isearch-point) (goto-char isearch-point))) - (isearch-update)) + (isearch-update) + ;; Allow prefix arg for the next motion command. + (setq isearch-allow-move-temporarily t)) + ;; Handle a motion function. + ((and (or isearch-allow-move isearch-allow-move-temporarily) + (progn (setq key (isearch-reread-key-sequence-naturally keylist)) + (setq keylist (listify-key-sequence key)) + (setq main-event (aref key 0)) + (setq move-command (isearch-lookup-move-key + ;; 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) + (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) (window-minibuffer-p (posn-window (event-start main-event))))