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: Re: Yanking isearch to highlight-regexp Date: Sun, 29 Jun 2008 01:02:03 +0300 Organization: JURTA Message-ID: <878wwp1an8.fsf@jurta.org> References: <4853F884.7000609@gmail.com> <7dbe73ed0806141442h342f8ff0u83863f3980a7e229@mail.gmail.com> <48545D78.8080103@gmail.com> <4854E536.8040407@gmail.com> <87k5gql900.fsf@jurta.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1214690920 20811 80.91.229.12 (28 Jun 2008 22:08:40 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 28 Jun 2008 22:08:40 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Jun 29 00:09:25 2008 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KCibk-0003rG-Dc for ged-emacs-devel@m.gmane.org; Sun, 29 Jun 2008 00:09:24 +0200 Original-Received: from localhost ([127.0.0.1]:35156 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KCiau-0001iO-Cn for ged-emacs-devel@m.gmane.org; Sat, 28 Jun 2008 18:08:32 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KCiaq-0001i9-Pj for emacs-devel@gnu.org; Sat, 28 Jun 2008 18:08:28 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KCiap-0001hx-7b for emacs-devel@gnu.org; Sat, 28 Jun 2008 18:08:28 -0400 Original-Received: from [199.232.76.173] (port=52771 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KCiap-0001hu-4Q for emacs-devel@gnu.org; Sat, 28 Jun 2008 18:08:27 -0400 Original-Received: from relay02.kiev.sovam.com ([62.64.120.197]:61727) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KCiao-0004zI-7g for emacs-devel@gnu.org; Sat, 28 Jun 2008 18:08:26 -0400 Original-Received: from [83.170.232.243] (helo=smtp.svitonline.com) by relay02.kiev.sovam.com with esmtp (Exim 4.67) (envelope-from ) id 1KCiam-0001W7-Ci for emacs-devel@gnu.org; Sun, 29 Jun 2008 01:08:24 +0300 In-Reply-To: <87k5gql900.fsf@jurta.org> (Juri Linkov's message of "Sun, 15 Jun 2008 23:48:47 +0300") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (x86_64-pc-linux-gnu) X-Scanner-Signature: 6ad7cde3a67687f27f64865acd81e448 X-DrWeb-checked: yes X-SpamTest-Envelope-From: juri@jurta.org X-SpamTest-Group-ID: 00000000 X-SpamTest-Header: Trusted X-SpamTest-Info: Profiles 4129 [June 26 2008] X-SpamTest-Info: {received from trusted relay: common white list} X-SpamTest-Info: {HEADERS: header Content-Type found without required header Content-Transfer-Encoding} X-SpamTest-Method: white ip list X-SpamTest-Rate: 10 X-SpamTest-Status: Trusted X-SpamTest-Status-Extended: trusted X-SpamTest-Version: SMTP-Filter Version 3.0.0 [0278], KAS30/Release X-detected-kernel: by monty-python.gnu.org: FreeBSD 6.x (1) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:100104 Archived-At: Below is a patch that unifies two similar regexp-reading functions `keep-lines-read-args' and `occur-read-primary-args' into the general function `read-regexp'. It reads a regexp using the regexp history and provides some useful defaults. Like `keep-lines-read-args' it accepts the prompt as its argument, but without the trailing colon to be able to add the default value in parentheses. But now the prompt for `keep-lines' doesn't look nice since it displays parentheses twice as: Keep lines (containing match for regexp) (default regexp): maybe a better format would be: Keep lines, containing match for regexp (default regexp): This new function could be used later in other packages like hi-lock. Index: lisp/replace.el =================================================================== RCS file: /sources/emacs/emacs/lisp/replace.el,v retrieving revision 1.272 diff -c -r1.272 replace.el *** lisp/replace.el 6 Jun 2008 20:32:11 -0000 1.272 --- lisp/replace.el 28 Jun 2008 22:00:32 -0000 *************** *** 522,527 **** --- 522,559 ---- Maximum length of the history list is determined by the value of `history-length', which see.") + (defun read-regexp (prompt) + "Read regexp as a string using the regexp history and some useful defaults. + Prompt for a regular expression with PROMPT. Provide the last element + of the regexp history as the basic default, and return it on typing RET. + Additional defaults are the string under point, the last search regexp, + the last search string, and the last replacement regexp. + Return the regexp as a string." + (let* ((default (car regexp-history)) + (defaults + (list (regexp-quote + (or (funcall (or find-tag-default-function + (get major-mode 'find-tag-default-function) + 'find-tag-default)) + "")) + (car regexp-search-ring) + (regexp-quote (or (car search-ring) "")) + (car (symbol-value + query-replace-from-history-variable)))) + (defaults (delete-dups (delq nil (delete "" defaults)))) + ;; Don't add automatically the car of defaults for empty input + (history-add-new-input nil) + (input + (read-from-minibuffer + (if default + (format "%s (default %s): " prompt (query-replace-descr default)) + (format "%s: " prompt)) + nil nil nil 'regexp-history defaults t))) + (if (equal input "") + default + (prog1 input + (add-to-history 'regexp-history input))))) + (defalias 'delete-non-matching-lines 'keep-lines) (defalias 'delete-matching-lines 'flush-lines) *************** *** 532,551 **** "Read arguments for `keep-lines' and friends. Prompt for a regexp with PROMPT. Value is a list, (REGEXP)." ! (let* ((default (list ! (regexp-quote ! (or (funcall (or find-tag-default-function ! (get major-mode 'find-tag-default-function) ! 'find-tag-default)) ! "")) ! (car regexp-search-ring) ! (regexp-quote (or (car search-ring) "")) ! (car (symbol-value ! query-replace-from-history-variable)))) ! (default (delete-dups (delq nil (delete "" default))))) ! (list (read-from-minibuffer prompt nil nil nil ! 'regexp-history default t) ! nil nil t))) (defun keep-lines (regexp &optional rstart rend interactive) "Delete all lines except those containing matches for REGEXP. --- 564,570 ---- "Read arguments for `keep-lines' and friends. Prompt for a regexp with PROMPT. Value is a list, (REGEXP)." ! (list (read-regexp prompt) nil nil t)) (defun keep-lines (regexp &optional rstart rend interactive) "Delete all lines except those containing matches for REGEXP. *************** *** 574,580 **** (interactive (progn (barf-if-buffer-read-only) ! (keep-lines-read-args "Keep lines (containing match for regexp): "))) (if rstart (progn (goto-char (min rstart rend)) --- 593,599 ---- (interactive (progn (barf-if-buffer-read-only) ! (keep-lines-read-args "Keep lines (containing match for regexp)"))) (if rstart (progn (goto-char (min rstart rend)) *************** *** 649,655 **** (interactive (progn (barf-if-buffer-read-only) ! (keep-lines-read-args "Flush lines (containing match for regexp): "))) (if rstart (progn (goto-char (min rstart rend)) --- 668,674 ---- (interactive (progn (barf-if-buffer-read-only) ! (keep-lines-read-args "Flush lines (containing match for regexp)"))) (if rstart (progn (goto-char (min rstart rend)) *************** *** 695,701 **** a previously found match." (interactive ! (keep-lines-read-args "How many matches for (regexp): ")) (save-excursion (if rstart (progn --- 714,720 ---- a previously found match." (interactive ! (keep-lines-read-args "How many matches for (regexp)")) (save-excursion (if rstart (progn *************** *** 1003,1040 **** (nreverse result)))) (defun occur-read-primary-args () ! (let* ((default (car regexp-history)) ! (defaults ! (list (and transient-mark-mode mark-active ! (regexp-quote ! (buffer-substring-no-properties ! (region-beginning) (region-end)))) ! (regexp-quote ! (or (funcall ! (or find-tag-default-function ! (get major-mode 'find-tag-default-function) ! 'find-tag-default)) ! "")) ! (car regexp-search-ring) ! (regexp-quote (or (car search-ring) "")) ! (car (symbol-value ! query-replace-from-history-variable)))) ! (defaults (delete-dups (delq nil (delete "" defaults)))) ! ;; Don't add automatically the car of defaults for empty input ! (history-add-new-input nil) ! (input ! (read-from-minibuffer ! (if default ! (format "List lines matching regexp (default %s): " ! (query-replace-descr default)) ! "List lines matching regexp: ") ! nil nil nil 'regexp-history defaults))) ! (list (if (equal input "") ! default ! (prog1 input ! (add-to-history 'regexp-history input))) ! (when current-prefix-arg ! (prefix-numeric-value current-prefix-arg))))) (defun occur-rename-buffer (&optional unique-p interactive-p) "Rename the current *Occur* buffer to *Occur: original-buffer-name*. --- 1022,1030 ---- (nreverse result)))) (defun occur-read-primary-args () ! (list (read-regexp "List lines matching regexp") ! (when current-prefix-arg ! (prefix-numeric-value current-prefix-arg)))) (defun occur-rename-buffer (&optional unique-p interactive-p) "Rename the current *Occur* buffer to *Occur: original-buffer-name*. -- Juri Linkov http://www.jurta.org/emacs/