From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#14742: 24.3.50; enhancement request: be able to prepend stuff from buffer when search backward Date: Fri, 05 Jul 2013 02:34:18 +0300 Organization: JURTA Message-ID: <87y59lc32c.fsf@mail.jurta.org> References: <4b9029ca-1775-482f-ba9a-46a891be7405@default> <87sj01c3n2.fsf@mail.jurta.org> <7518b30b-63d2-40ea-956f-a504f40c4cfd@default> <87haggoc6r.fsf@mail.jurta.org> <8ada7269-baa9-483f-9595-d46619393aa7@default> <87y59ok18k.fsf@mail.jurta.org> <6ae1046e-e6ae-43ae-96ff-064fd01c9ec2@default> <87k3l8ik77.fsf@mail.jurta.org> <87k3l79seh.fsf@mail.jurta.org> <9fa6642c-dbcb-47aa-a8a3-29ee892bd933@default> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1372981508 5305 80.91.229.3 (4 Jul 2013 23:45:08 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 4 Jul 2013 23:45:08 +0000 (UTC) Cc: 14742@debbugs.gnu.org To: Drew Adams Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Jul 05 01:45:09 2013 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1UutD2-0000CG-BV for geb-bug-gnu-emacs@m.gmane.org; Fri, 05 Jul 2013 01:45:08 +0200 Original-Received: from localhost ([::1]:55551 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UutD1-0002wU-V0 for geb-bug-gnu-emacs@m.gmane.org; Thu, 04 Jul 2013 19:45:07 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41713) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UutCx-0002ul-WC for bug-gnu-emacs@gnu.org; Thu, 04 Jul 2013 19:45:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UutCw-0004yB-IH for bug-gnu-emacs@gnu.org; Thu, 04 Jul 2013 19:45:03 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:35765) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UutCw-0004xm-F7 for bug-gnu-emacs@gnu.org; Thu, 04 Jul 2013 19:45:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1UutCw-0004qu-40 for bug-gnu-emacs@gnu.org; Thu, 04 Jul 2013 19:45:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 04 Jul 2013 23:45:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 14742 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 14742-submit@debbugs.gnu.org id=B14742.137298148318602 (code B ref 14742); Thu, 04 Jul 2013 23:45:01 +0000 Original-Received: (at 14742) by debbugs.gnu.org; 4 Jul 2013 23:44:43 +0000 Original-Received: from localhost ([127.0.0.1]:58314 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1UutCc-0004pv-JA for submit@debbugs.gnu.org; Thu, 04 Jul 2013 19:44:43 -0400 Original-Received: from ps18281.dreamhost.com ([69.163.218.105]:37549 helo=ps18281.dreamhostps.com) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1UutCY-0004pg-WA for 14742@debbugs.gnu.org; Thu, 04 Jul 2013 19:44:40 -0400 Original-Received: from localhost (ps18281.dreamhostps.com [69.163.218.105]) by ps18281.dreamhostps.com (Postfix) with ESMTP id 00E95258B9E915; Thu, 4 Jul 2013 16:44:36 -0700 (PDT) In-Reply-To: <9fa6642c-dbcb-47aa-a8a3-29ee892bd933@default> (Drew Adams's message of "Wed, 3 Jul 2013 17:17:38 -0700 (PDT)") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (x86_64-pc-linux-gnu) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:75926 Archived-At: >> > Do you have this working already? Have you described what you have in >> > mind somewhere? Did you bring this up in emacs-devel? If not, please >> > consider it - that is the best place to toss such an idea around. >> >> Yes, it is working and I described it on emacs-devel a month ago. >> Now I'll prepare a minimal patch that implements low-level support, then >> send separate high-level code to activate it, so everyone could try it. > > Sounds good; looking forward to it. The following minimal patch implements low-level support for the motion yanking feature that could be later enabled by separate higher-level commands. It adds a new option `isearch-allow-move' with the nil default value. Like the user option `transient-mark-mode' having the certain special value of (only . OLDVAL) that enables Transient Mark mode temporarily, until any subsequent point motion command that is not shift-translated sets the value of `transient-mark-mode' back to OLDVAL, the new option `isearch-allow-move' does the same. This patch relies on the previously sent patch that adds a new argument `BEGINNING' to `isearch-yank-string' and `isearch-del-char'. === modified file 'lisp/isearch.el' --- lisp/isearch.el 2013-06-13 22:08:45 +0000 +++ lisp/isearch.el 2013-07-04 23:28:33 +0000 @@ -987,6 +1046,8 @@ (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) + (when (eq (car-safe isearch-allow-move) 'only) + (setq isearch-allow-move (cdr isearch-allow-move))) (run-hooks 'isearch-update-post-hook)) (defun isearch-done (&optional nopush edit) @@ -2267,6 +2433,77 @@ (defun isearch-lookup-scroll-key (key-se (eq (get binding 'scroll-command) t)) binding))) +(defcustom isearch-allow-move nil + "Whether cursor movement is allowed to yank text in Isearch mode. +If nil, point motion commands will exit Isearch mode immediately. +If non-nil, point motion commands extend Isearch by yanking the text +the cursor moves over in the buffer. E.g., C-f yanks the next char, +C-M-f yanks the next expression, etc. to the end of the search string +in forward search. In reverse search, C-b yanks the previous char, +C-M-b yanks the previous expression, etc. to the beginning of the +search string. And conversely, backward cursor movements, e.g., C-b +removes text from the end of the search string when searching forward. +When searching backward, forward cursor movements, e.g., C-f removes +text from the beginning of the search string. + +Lisp programs may give this variable a special value of +\(only . OLDVAL) to enable motion yanking temporarily. +After any subsequent Isearch command that is not point motion, +the value of `isearch-allow-move' is set to OLDVAL." + :type 'boolean + :version "24.4" + :group 'isearch) + +(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))) + (defalias 'isearch-other-control-char 'isearch-other-meta-char) (defun isearch-other-meta-char (&optional arg) @@ -2379,7 +2616,67 @@ (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)) + ;; Handle a motion function. + ((and isearch-allow-move + (progn (setq key (isearch-reread-key-sequence-naturally keylist)) + (setq keylist (listify-key-sequence key)) + (setq main-event (aref key 0)) + (setq move-command (or + (isearch-lookup-move-key key) + (isearch-lookup-move-key + ;; Use the last key in the sequence. + (vector (aref key (1- (length key))))))))) + (setq prefix-arg arg) + (let* ((old-point (point)) + (new-point (save-excursion + (condition-case () + (command-execute move-command) + (error nil)) + (point)))) + ;; Change search direction between forward and backward. + (when (if isearch-forward + (< new-point old-point) + (> new-point old-point)) + (setq isearch-forward (not isearch-forward)) + (setq isearch-string "" isearch-message "") + (if isearch-other-end (setq old-point isearch-other-end))) + (if (< old-point new-point) + (if isearch-forward + (isearch-yank-string + (buffer-substring-no-properties old-point new-point)) + (isearch-del-char (- new-point old-point) t)) + (if isearch-forward + (isearch-del-char (- old-point new-point)) + (isearch-yank-string + (buffer-substring-no-properties old-point new-point) t)))) + (setq isearch-allow-move (cons 'only isearch-allow-move))) ;; 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)))) > What is the emacs-devel thread? Somehow I must have missed it. The emacs-devel thread is here: http://lists.gnu.org/archive/html/emacs-devel/2013-06/msg00211.html