From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: wrap-search 3.3.5 Date: Thu, 25 Aug 2022 16:26:15 -0400 Message-ID: References: <87sflkyy81.fsf@dataswamp.org> <87edx4p3xo.fsf@posteo.net> <87o7w8yx71.fsf@dataswamp.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="1060"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Aug 25 22:29:34 2022 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 1oRJTp-0000AC-Cn for ged-emacs-devel@m.gmane-mx.org; Thu, 25 Aug 2022 22:29:33 +0200 Original-Received: from localhost ([::1]:54528 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oRJTn-0000sA-UU for ged-emacs-devel@m.gmane-mx.org; Thu, 25 Aug 2022 16:29:31 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50820) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oRJQo-0007tQ-RP for emacs-devel@gnu.org; Thu, 25 Aug 2022 16:26:34 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:16121) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oRJQl-0002Rt-7s for emacs-devel@gnu.org; Thu, 25 Aug 2022 16:26:25 -0400 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 708D1100178; Thu, 25 Aug 2022 16:26:20 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id D017D100084; Thu, 25 Aug 2022 16:26:18 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1661459178; bh=YK49OP/3aiyF+Ue3wq63yxRYuLJ/mLeZhXOdVzINfis=; h=From:To:Subject:In-Reply-To:References:Date:From; b=ebpmsC5Nr4TDYBabJpoKgSoeXeEuG6516xfdooEKBa5YskCeOY4Qsu43vk9Z3y4VM MIjiguSi0Xk9UVqrPqcqarGYJEqtZombtH1B1PZOMeSUqQ910uCdF2sA8X7dBaiPux xNO+HfDYNNoPj2Lqky9PaVymjnF2KEEB/veizqTsFSW3eJwZYsPU4Epou9n+L+Awb7 ybCMWKz+jFTD41fildRCX8o9QpMgr+iFGy62PtRhLWzaafSpq5BbPaFfASwTJBZRUz m+lLh+LWocTFRQ8o9xf6lD/MRsVzB4qYAUFhAEsKXDncdyJa9htK6MmisUhHD0/DW2 fUdROELgjz55A== Original-Received: from alfajor (66-163-28-139.ip.tor.radiant.net [66.163.28.139]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 74B9B12060B; Thu, 25 Aug 2022 16:26:18 -0400 (EDT) In-Reply-To: <87o7w8yx71.fsf@dataswamp.org> (Emanuel Berg's message of "Thu, 25 Aug 2022 20:50:26 +0200") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -9 X-Spam_score: -1.0 X-Spam_bar: - X-Spam_report: (-1.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 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:294107 Archived-At: Emanuel Berg [2022-08-25 20:50:26] wrote: > Philip Kaludercic wrote: >> Could you elaborate what you meant to say with this message. >> Should it be added to ELPA? > Sure! For GNU ELPA, you'd first need to sign the relevant paperwork (see further down). For NonGNU ELPA, you'd need to put this in a public Git repository. (I think for MELPA, the same would apply). Some comments about your code: > ;; `wrap-search' searches forward by default, but it wraps > ;; and continues up and until the search start position if > ;; necessary. This is so one doesn't have to wonder if the > ;; target is north or south in the buffer. You might want to mention `isearch-wrap-pause` and explain the advantage of your package over what we get with (setq isearch-wrap-pause 'no). > (defun wrap-string-data-p (str) > "Return STR if it is a string but not the empty string, \"\"." > (and (stringp str) > (not (string= str "")) > str) ) Since you package is small, I'd prefer it doesn't use up the whole `wrap-` namespace, so I'd recommend you rename this function `wrap-search-string-data-p`. Also, in all the places where you use this function, you use the return value as a boolean, so you could simplify it to (defun wrap-search-string-data-p (str) "Return non-nil if it is a string but not the empty string, \"\"." (and (stringp str) (not (string= str ""))) ) But in addition, I notice that it's only ever called with `prev-str` as argument and that variable can never hold anything else than nil or a non-empty string (because we test (string= "") before setting it). So you can just remove the function altogether and just test `prev-str` instead. Also that var is global and it's never set back to nil, so so the nil case should only occur once per Emacs session, and I'd simplify the code by initializing the var not to nil but to some dummy default like "unspecified search string" so you don't even need to handle the nil case. > (let ((prev-str) > (prev-case) > (prev-rev) > (prev-beg) > (prev-end) ) > (defun wrap-search-again () > (interactive) > (if (wrap-string-data-p prev-str) > (wrap-search prev-str prev-case prev-rev prev-beg prev-end) > (message "no search has been done") )) > (declare-function wrap-search-again nil) Yeah, I'd welcome patches to `bytecomp.el` to handle such code better so you don't need `declare-function`. > (defun show-prev-str () > (if (wrap-string-data-p prev-str) > (let*((len (length prev-str)) > (max 10) > (short (when (< max len) > (substring prev-str 0 max) ))) > (format "[%s] " (if short > (format "%s..." short) > prev-str) )) > "")) You can use `truncate-string-to-width` here. > (interactive > `(,(read-string (format "search: %s" (show-prev-str))) The convention is to put the default before the `:` and wrapped in "(default ...)" rather than "[...]". Since Emacs-28 you can use `format-prompt` to do that. If (like me) you prefer the "[...]" format, you might like to use `minibuffer-electric-default-mode` and (setq minibuffer-eldef-shorten-default t). > ,(or (equal current-prefix-arg '( 4)) > (equal current-prefix-arg '(64)) ) AKA ,(member current-prefix-arg '((4) (64))) > ,(or (equal current-prefix-arg '(16)) > (equal current-prefix-arg '(64)) ) AKA ,(member current-prefix-arg '((16) (64))) > (let*((case-fold-search (not case)) > (pos (point)) > (data (if rev (list #'search-backward end beg) > (list #'search-forward beg end) )) > (search-f (car data)) > (search-beg (cadr data)) > (search-end (caddr data)) ) You can also write this as (pcase-let* ((case-fold-search (not case)) (pos (point)) (`(,search-f ,search-beg ,search-end) (if rev (list #'search-backward end beg) (list #'search-forward beg end)))) > (if (apply (list search-f str search-end t)) AKA (if (funcall search-f str search-end t) which is not just shorter but also more efficient. > (if (apply (list search-f str (+ pos (if rev 0 (length str))) t)) Same here. As for the paperwork, you'd want to fill the form below and send it as instructed so the FSF can send you the relevant paperwork to sign. Stefan