From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#54017: add regexp translation option to read-regexp Date: Thu, 17 Feb 2022 11:09:21 +0200 Organization: LINKOV.NET Message-ID: <86fsoheu66.fsf@mail.linkov.net> References: <8635kj2h7s.fsf@mail.linkov.net> <86pmnlew9d.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="12996"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu) Cc: 54017@debbugs.gnu.org To: emacsq Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Feb 17 10:36:03 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1nKdCk-00036c-EW for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 17 Feb 2022 10:36:02 +0100 Original-Received: from localhost ([::1]:54352 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKdCi-0000MA-Vb for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 17 Feb 2022 04:36:01 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:58372) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKcpW-00047h-QU for bug-gnu-emacs@gnu.org; Thu, 17 Feb 2022 04:12:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:56210) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nKcpW-0008CS-FN for bug-gnu-emacs@gnu.org; Thu, 17 Feb 2022 04:12:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nKcpW-0001Dy-B4 for bug-gnu-emacs@gnu.org; Thu, 17 Feb 2022 04:12:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 17 Feb 2022 09:12:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 54017 X-GNU-PR-Package: emacs Original-Received: via spool by 54017-submit@debbugs.gnu.org id=B54017.16450890724615 (code B ref 54017); Thu, 17 Feb 2022 09:12:02 +0000 Original-Received: (at 54017) by debbugs.gnu.org; 17 Feb 2022 09:11:12 +0000 Original-Received: from localhost ([127.0.0.1]:50102 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nKcoi-0001CN-2y for submit@debbugs.gnu.org; Thu, 17 Feb 2022 04:11:12 -0500 Original-Received: from relay5-d.mail.gandi.net ([217.70.183.197]:38587) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nKcog-0001C7-1M for 54017@debbugs.gnu.org; Thu, 17 Feb 2022 04:11:10 -0500 Original-Received: (Authenticated sender: juri@linkov.net) by mail.gandi.net (Postfix) with ESMTPSA id C45901C000F; Thu, 17 Feb 2022 09:11:02 +0000 (UTC) In-Reply-To: <86pmnlew9d.fsf@mail.linkov.net> (Juri Linkov's message of "Thu, 17 Feb 2022 10:24:14 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:227074 Archived-At: --=-=-= Content-Type: text/plain > It's easy to add regexp translation to the return value of read-regexp. This patch allows using Rx syntax, so for example, after running 'occur', you can type an Rx expression: List lines matching regexp: (rx (or "e.g." "i.e.") " ") --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=regexp-from-function.patch diff --git a/lisp/emacs-lisp/rx.el b/lisp/emacs-lisp/rx.el index aa2486b47e..b1e726d025 100644 --- a/lisp/emacs-lisp/rx.el +++ b/lisp/emacs-lisp/rx.el @@ -1479,6 +1479,10 @@ rx ;; Obsolete internal symbol, used in old versions of the `flycheck' package. (define-obsolete-function-alias 'rx-submatch-n 'rx-to-string "27.1") +(defun regexp-from-rx (string) + "This translation function can be used by `regexp-from-function'." + (rx--to-expr (cons 'seq (cdr (read string))))) + (provide 'rx) ;;; rx.el ends here diff --git a/lisp/replace.el b/lisp/replace.el index 06be597855..a8b850a9ed 100644 --- a/lisp/replace.el +++ b/lisp/replace.el @@ -819,6 +819,15 @@ occur-highlight-overlays (defvar occur-collect-regexp-history '("\\1") "History of regexp for occur's collect operation.") +(defcustom regexp-from-function nil + "Function to translate from a custom regexp to the default regexp syntax." + :type '(choice + (const :tag "No translation" nil) + (function-item :tag "RX" regexp-from-rx) + (function :tag "Your choice of function")) + :group 'matching + :version "29.1") + (defcustom read-regexp-defaults-function nil "Function that provides default regexp(s) for `read-regexp'. This function should take no arguments and return one of: nil, a @@ -923,7 +932,9 @@ read-regexp (when default (add-to-history (or history 'regexp-history) default))) ;; Otherwise, add non-empty input to the history and return input. - (prog1 input + (prog1 (if (functionp regexp-from-function) + (funcall regexp-from-function input) + input) (add-to-history (or history 'regexp-history) input))))) --=-=-=--