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, 15 Jun 2008 23:48:47 +0300 Organization: JURTA Message-ID: <87k5gql900.fsf@jurta.org> References: <4853F884.7000609@gmail.com> <7dbe73ed0806141442h342f8ff0u83863f3980a7e229@mail.gmail.com> <48545D78.8080103@gmail.com> <4854E536.8040407@gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1213563425 30815 80.91.229.12 (15 Jun 2008 20:57:05 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 15 Jun 2008 20:57:05 +0000 (UTC) Cc: David Koppelman , emacs-devel@gnu.org To: "Lennart Borgman \(gmail\)" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Jun 15 22:57:48 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 1K7zII-0004Vk-Hh for ged-emacs-devel@m.gmane.org; Sun, 15 Jun 2008 22:57:46 +0200 Original-Received: from localhost ([127.0.0.1]:59459 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K7zHU-00027V-H0 for ged-emacs-devel@m.gmane.org; Sun, 15 Jun 2008 16:56:56 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1K7zHR-00027Q-5Z for emacs-devel@gnu.org; Sun, 15 Jun 2008 16:56:53 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1K7zHP-00027E-Lm for emacs-devel@gnu.org; Sun, 15 Jun 2008 16:56:51 -0400 Original-Received: from [199.232.76.173] (port=37893 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K7zHP-00027B-Fc for emacs-devel@gnu.org; Sun, 15 Jun 2008 16:56:51 -0400 Original-Received: from relay03.kiev.sovam.com ([62.64.120.201]:53581) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1K7zHO-0005Th-QR for emacs-devel@gnu.org; Sun, 15 Jun 2008 16:56:51 -0400 Original-Received: from [83.170.232.243] (helo=smtp.svitonline.com) by relay03.kiev.sovam.com with esmtp (Exim 4.67) (envelope-from ) id 1K7zHM-000O1o-4y; Sun, 15 Jun 2008 23:56:48 +0300 In-Reply-To: <4854E536.8040407@gmail.com> (Lennart Borgman's message of "Sun, 15 Jun 2008 11:47:34 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (x86_64-pc-linux-gnu) X-Scanner-Signature: 4f9c99cd45f50e7ebb0f86cc5c3dce24 X-DrWeb-checked: yes X-SpamTest-Envelope-From: juri@jurta.org X-SpamTest-Group-ID: 00000000 X-SpamTest-Header: Trusted X-SpamTest-Info: Profiles 3140 [June 15 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:99270 Archived-At: > Why is not C-x w h always bound to higlight-regexp? I think the key `C-x w' by its mnemonics would be more suitable for a command that writes to the file like `C-x C-w'. As the comment in hi-lock.el suggests to bind it rather to `C-z h', below is a patch for isearch.el with a new command `isearch-highlight-regexp' bound to `M-s h'. It is equivalent to the previously implemented `isearch-occur' in regard to calling the command with the last isearch string/regexp. `isearch-highlight-regexp' is a useful command, and it is much better than setting `lazy-highlight-cleanup' to nil, because `lazy-highlight-cleanup' leaves highlighting limited only to the current window boundaries, whereas `highlight-regexp' highlights the entire buffer. As for the separate case of running `highlight-regexp' after isearch is finished, I suggest using the same default values as already provided by `occur-read-primary-args' and `keep-lines-read-args' that collect a list of useful regexps from different places including the last isearch string and put them to the list of default values. This also suggests to get rid of `hi-lock-regexp-history' in favor of the single regexp history variable `regexp-history' shared among all regexp-reading commands (perhaps `keep-lines-read-args' should be renamed to more general name like `read-regexp'). Another improvement I propose is to put a list of default faces to the minibuffer's list of default values accessible via M-n instead of putting default values to the history list where the user expects to find the history list of previous input. Index: lisp/isearch.el =================================================================== RCS file: /sources/emacs/emacs/lisp/isearch.el,v retrieving revision 1.321 diff -u -r1.321 isearch.el --- lisp/isearch.el 11 May 2008 20:30:27 -0000 1.321 +++ lisp/isearch.el 15 Jun 2008 20:43:00 -0000 @@ -494,6 +494,7 @@ (define-key map [?\M-%] 'isearch-query-replace) (define-key map [?\C-\M-%] 'isearch-query-replace-regexp) (define-key map "\M-so" 'isearch-occur) + (define-key map "\M-sh" 'isearch-highlight-regexp) map) "Keymap for `isearch-mode'.") @@ -1364,6 +1365,21 @@ (search-upper-case nil)) (occur regexp nlines))) +(defun isearch-highlight-regexp (regexp &optional face) + "Run `highlight-regexp' with regexp from the current search string. +Interactively, REGEXP is the current search regexp or a quoted search +string. FACE has the same meaning as in `highlight-regexp'." + (interactive + (list + (hi-lock-regexp-okay + (if isearch-regexp isearch-string (regexp-quote isearch-string))) + (hi-lock-read-face-name))) + (isearch-done) + (isearch-clean-overlays) + (let ((case-fold-search isearch-case-fold-search)) + (hi-lock-face-buffer regexp face))) + (defun isearch-delete-char () "Discard last input item and move point back. Index: lisp/hi-lock.el =================================================================== RCS file: /sources/emacs/emacs/lisp/hi-lock.el,v retrieving revision 1.51 diff -u -r1.51 hi-lock.el --- lisp/hi-lock.el 6 May 2008 07:57:38 -0000 1.51 +++ lisp/hi-lock.el 15 Jun 2008 20:43:34 -0000 @@ -206,12 +206,12 @@ (defvar hi-lock-interactive-patterns nil "Patterns provided to hi-lock by user. Should not be changed.") -(defvar hi-lock-face-history +(defvar hi-lock-face-defaults (list "hi-yellow" "hi-pink" "hi-green" "hi-blue" "hi-black-b" "hi-blue-b" "hi-red-b" "hi-green-b" "hi-black-hb") - "History list of faces for hi-lock interactive functions.") + "A list of default faces for hi-lock interactive functions.") -;(dolist (f hi-lock-face-history) (unless (facep f) (error "%s not a face" f))) +;(dolist (f hi-lock-face-defaults) (unless (facep f) (error "%s not a face" f))) (defvar hi-lock-regexp-history nil "History of regexps used for interactive fontification.") @@ -390,14 +390,13 @@ Interactively, prompt for REGEXP then FACE. Buffer-local history list maintained for regexps, global history maintained for faces. -\\Use \\[next-history-element] and \\[previous-history-element] to retrieve next or previous history item. +\\Use \\[previous-history-element] to retrieve previous history items, +and \\[next-history-element] to retrieve default values. \(See info node `Minibuffer History'.)" (interactive (list (hi-lock-regexp-okay - (read-from-minibuffer "Regexp to highlight line: " - (cons (or (car hi-lock-regexp-history) "") 1 ) - nil nil 'hi-lock-regexp-history)) + (keep-lines-read-args "Regexp to highlight line: ")) (hi-lock-read-face-name))) (or (facep face) (setq face 'hi-yellow)) (unless hi-lock-mode (hi-lock-mode 1)) @@ -415,14 +414,13 @@ Interactively, prompt for REGEXP then FACE. Buffer-local history list maintained for regexps, global history maintained for faces. -\\Use \\[next-history-element] and \\[previous-history-element] to retrieve next or previous history item. +\\Use \\[previous-history-element] to retrieve previous history items, +and \\[next-history-element] to retrieve default values. \(See info node `Minibuffer History'.)" (interactive (list (hi-lock-regexp-okay - (read-from-minibuffer "Regexp to highlight: " - (cons (or (car hi-lock-regexp-history) "") 1 ) - nil nil 'hi-lock-regexp-history)) + (keep-lines-read-args "Regexp to highlight: ")) (hi-lock-read-face-name))) (or (facep face) (setq face 'hi-yellow)) (unless hi-lock-mode (hi-lock-mode 1)) @@ -440,9 +438,7 @@ (list (hi-lock-regexp-okay (hi-lock-process-phrase - (read-from-minibuffer "Phrase to highlight: " - (cons (or (car hi-lock-regexp-history) "") 1 ) - nil nil 'hi-lock-regexp-history))) + (keep-lines-read-args "Phrase to highlight: "))) (hi-lock-read-face-name))) (or (facep face) (setq face 'hi-yellow)) (unless hi-lock-mode (hi-lock-mode 1)) @@ -457,7 +453,8 @@ Interactively, prompt for REGEXP. Buffer-local history of inserted regexp's maintained. Will accept only regexps inserted by hi-lock interactive functions. \(See `hi-lock-interactive-patterns'.\) -\\Use \\[minibuffer-complete] to complete a partially typed regexp. +\\Use \\[previous-history-element] to retrieve previous history items, +and \\[next-history-element] to retrieve default values. \(See info node `Minibuffer History'.\)" (interactive (if (and (display-popup-menus-p) (not last-nonmenu-event)) @@ -552,16 +549,18 @@ (intern (completing-read "Highlight using face: " obarray 'facep t - (cons (car hi-lock-face-history) + (cons (car hi-lock-face-defaults) (let ((prefix (try-completion - (substring (car hi-lock-face-history) 0 1) + (substring (car hi-lock-face-defaults) 0 1) (mapcar (lambda (f) (cons f f)) - hi-lock-face-history)))) + hi-lock-face-defaults)))) (if (and (stringp prefix) - (not (equal prefix (car hi-lock-face-history)))) + (not (equal prefix (car hi-lock-face-defaults)))) (length prefix) 0))) - '(hi-lock-face-history . 0)))) + nil + hi-lock-face-defaults + ))) (defun hi-lock-set-pattern (regexp face) "Highlight REGEXP with face FACE." -- Juri Linkov http://www.jurta.org/emacs/