From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Augusto Stoffel Newsgroups: gmane.emacs.devel Subject: Re: Some further ideas for Isearch Date: Wed, 28 Apr 2021 23:55:35 +0200 Message-ID: <87eeeunkfc.fsf@gmail.com> References: <87pmyisrlw.fsf@gmail.com> <87h7jul2va.fsf@mail.linkov.net> <87czuh1uhg.fsf@gmail.com> <87fsza5c5e.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="11906"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cc: emacs-devel@gnu.org To: Juri Linkov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Apr 29 02:58:29 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lbv0f-0002yx-CB for ged-emacs-devel@m.gmane-mx.org; Thu, 29 Apr 2021 02:58:29 +0200 Original-Received: from localhost ([::1]:37512 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lbv0c-0002DZ-B1 for ged-emacs-devel@m.gmane-mx.org; Wed, 28 Apr 2021 20:58:26 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34678) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lbs9l-0004K2-E5 for emacs-devel@gnu.org; Wed, 28 Apr 2021 17:55:41 -0400 Original-Received: from mail-ed1-x531.google.com ([2a00:1450:4864:20::531]:39665) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lbs9j-00027L-Fp for emacs-devel@gnu.org; Wed, 28 Apr 2021 17:55:41 -0400 Original-Received: by mail-ed1-x531.google.com with SMTP id g14so16423995edy.6 for ; Wed, 28 Apr 2021 14:55:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=ZTXUgNxzFTz8lLpdrjvLTgxdqhmWmugbfzJMVo6DsnI=; b=Ya9u8ZExsPPF97hU0lHnYaePPH9xHoMYMCt1t4h/wZ5woEWUyyXX7tkJ6a57k1hTyD 7uH9IlaB3VeAJY+pV+6lqI+BY5qATk5XmzEzp32ovLuu6k6Ar8puuhyTLfakwW4sjI4U /UNnGxEWJP/bASH20TsH0e7qPcikDoRHPGoRMDCXsp5DaaCXdE85ifNRD/Cc5eJlppZD s7alXCjdMbm0Q/YFjj8P8t0QxROjJpLzSB2kepLN0a/ERm9WIiRIWuzZ5y/3SK/PkNWa jgJxutL51ncp/GDdbRhI90i6JYJ8LrtX31F4InGcOCr835WPNX3BRDn1CBMEvskXnD8E zFJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=ZTXUgNxzFTz8lLpdrjvLTgxdqhmWmugbfzJMVo6DsnI=; b=CogYNpK1B6n+52+zmJxv72t4nPEQJHUtEMLg53+SxdZp5t/aD1WcKlO92GVPcE/9Ox xf3jkU/o0LuQbsq32fC1GgBFgWDjx/xGQshhvNM5dIvc/6FSU8EB3ynHQ56CnyVm0Jqi RLa5HRPHKwrI3L+EtC8Nt/4dsmIApQl0DtkNmcrBeiMERyzWsX/LwR6p6X4y6qtLIEQr EQ5b/48KTDcZbOENlLV+GcaFiMORGi1hjkPi29As8VrDdsr9Z2PDsiTxJi9eQAq4simw 8x3gzqRaU14oLrWZmfnKTAk3xX6SGLLDBvllq0wLQAtKL7orifvlUzU6xNauhqPTdwks 9WlA== X-Gm-Message-State: AOAM532bWwuzWXT0Kp60TnSbMKnUeFa2GBg7o2LLgo4DtVK9fy5TNvfT 6PX8GCwgouqxAt0mdyC+rydj+gdoCzsGrQ== X-Google-Smtp-Source: ABdhPJxxdn89mXahkEdtRKjBOy/1A36HYRifMQ9m8D2HsKf4MP7fsqQ+Xsu2T2kizzJ340V03QyLrg== X-Received: by 2002:aa7:d3c2:: with SMTP id o2mr14199568edr.111.1619646937090; Wed, 28 Apr 2021 14:55:37 -0700 (PDT) Original-Received: from ars3 ([2a02:908:2211:8540::68a]) by smtp.gmail.com with ESMTPSA id t17sm849094edv.3.2021.04.28.14.55.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Apr 2021 14:55:36 -0700 (PDT) In-Reply-To: <87fsza5c5e.fsf@mail.linkov.net> (Juri Linkov's message of "Thu, 29 Apr 2021 00:11:41 +0300") Received-SPF: pass client-ip=2a00:1450:4864:20::531; envelope-from=arstoffel@gmail.com; helo=mail-ed1-x531.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Wed, 28 Apr 2021 20:56:38 -0400 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 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-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:268592 Archived-At: --=-=-= Content-Type: text/plain On Thu, 29 Apr 2021 at 00:11, Juri Linkov wrote: > The value of isearch-regexp is not saved as a property in the history. But it should, right? > Please elaborate. Do you rebind C-s to isearch-forward-regexp, > then after using isearch-forward-symbol, can't repeat it with C-s? Exactly. > Does something like this do the right thing for you? > > (defvaralias 'regexp-search-ring 'search-ring) Yes, I guess that would solve the problem I described, except that isearch-regexp won't be set correctly. Now, I'm not sure if a unified history is an interesting enough feature to add. But in the meanwhile something else occurred to me: `C-s C-s` is equivalent to `C-s M-p'. So how about making `C-s C-s' resume the last search, event if it was canceled on in a different mode? I have attached a patch sketching this. What do you think? --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Allow-resuming-a-canceled-isearch.patch >From 06a2afbe88a0456fb415bc082ff3150aba21656b Mon Sep 17 00:00:00 2001 From: Augusto Stoffel Date: Mon, 26 Apr 2021 18:09:47 +0200 Subject: [PATCH] Allow resuming a canceled isearch * lisp/isearch.el (isearch-always-resume-previous, isearch--previous-string): New variables * lisp/isearch.el (isearch-set-string): New function for an often repeated code snippet. * lisp/isearch.el (isearch-string-propertize): Also record the value of isearch-regexp * lisp/isearch.el (isearch-repeat): When resuming a previous search because the search string is empty, take isearch-always-resume-previous and isearch--previous-string into account --- lisp/isearch.el | 68 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 23 deletions(-) diff --git a/lisp/isearch.el b/lisp/isearch.el index 9f3cfd70fb..488517b47d 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -172,6 +172,15 @@ isearch-resume-in-command-history command history." :type 'boolean) +(defcustom isearch-resume-most-recent nil + "Whether to always resume the most recent search. +When t, attempting to search for the empty string resumes the +most recent search, even if it was canceled or in a different +search mode. When nil, use the appropriate history entry +instead." + :type 'boolean + :version "28.1") + (defcustom isearch-wrap-pause t "Define the behavior of wrapping when there are no more matches. When `t' (by default), signal an error when no more matches are found. @@ -954,6 +963,9 @@ isearch-input-method-function (defvar isearch--saved-overriding-local-map nil) +;; The previous non-empty search string, with properties +(defvar isearch--previous-string nil) + ;; Minor-mode-alist changes - kind of redundant with the ;; echo area, but if isearching in multiple windows, it can be useful. ;; Also, clicking the mode-line indicator pops up @@ -1460,9 +1472,12 @@ isearch-done (next-single-property-change (point) 'intangible) (previous-single-property-change (point) 'intangible))))) - (if (and (> (length isearch-string) 0) (not nopush)) - ;; Update the ring data. - (isearch-update-ring isearch-string isearch-regexp)) + (unless (string-empty-p isearch-string) + (when isearch-resume-most-recent + (setq isearch--previous-string (isearch-string-propertize isearch-string))) + ;; Update the ring data. + (unless nopush + (isearch-update-ring isearch-string isearch-regexp))) (let ((isearch-mode-end-hook-quit (and nopush (not edit)))) (run-hooks 'isearch-mode-end-hook)) @@ -1504,19 +1519,28 @@ isearch-update-ring (defun isearch-string-propertize (string &optional properties) "Add isearch properties to the isearch string." (unless properties - (setq properties `(isearch-case-fold-search ,isearch-case-fold-search)) - (unless isearch-regexp - (setq properties (append properties `(isearch-regexp-function ,isearch-regexp-function))))) - (apply 'propertize string properties)) + (setq properties `(isearch-case-fold-search ,isearch-case-fold-search + isearch-regexp-function ,isearch-regexp-function + isearch-regexp ,isearch-regexp)) + (apply 'propertize string properties))) (defun isearch-update-from-string-properties (string) "Update isearch properties from the isearch STRING." - (when (plist-member (text-properties-at 0 string) 'isearch-case-fold-search) - (setq isearch-case-fold-search - (get-text-property 0 'isearch-case-fold-search string))) - (when (plist-member (text-properties-at 0 string) 'isearch-regexp-function) - (setq isearch-regexp-function - (get-text-property 0 'isearch-regexp-function string)))) + (let ((props (text-properties-at 0 string))) + (when-let (prop (plist-member props 'isearch-case-fold-search)) + (setq isearch-case-fold-search (cadr prop))) + (when-let (prop (plist-member props 'isearch-regexp-function)) + (setq isearch-regexp-function (cadr prop))) + (when-let (prop (plist-member props 'isearch-regexp)) + (setq isearch-regexp (cadr prop))))) + +(defun isearch-set-string (string &optional properties) + "Set the current search string. +If PROPERTIES is non-nil, also update the search mode from the +text properties of STRING." + (when properties (isearch-update-from-string-properties string)) + (setq isearch-string string + isearch-message (mapconcat 'isearch-text-char-description string ""))) ;; The search status structure and stack. @@ -1877,16 +1901,14 @@ isearch-repeat ;; C-s in forward or C-r in reverse. (if (equal isearch-string "") ;; If search string is empty, use last one. - (if (null (if isearch-regexp regexp-search-ring search-ring)) - (setq isearch-error "No previous search string") - (setq isearch-string - (car (if isearch-regexp regexp-search-ring search-ring)) - isearch-message - (mapconcat 'isearch-text-char-description - isearch-string "") - isearch-case-fold-search isearch-last-case-fold-search) - ;; After taking the last element, adjust ring to previous one. - (isearch-ring-adjust1 nil)) + (if (and isearch-resume-most-recent isearch--previous-string) + (isearch-set-string isearch--previous-string t) + (if-let ((ring (if isearch-regexp regexp-search-ring search-ring))) + (progn + (isearch-set-string (car ring) t) + ;; After taking the last element, adjust ring to previous one. + (isearch-ring-adjust1 nil)) + (setq isearch-error "No previous search string"))) ;; If already have what to search for, repeat it. (unless (or isearch-success (null isearch-wrap-pause)) ;; Set isearch-wrapped before calling isearch-wrap-function -- 2.30.2 --=-=-=--