From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Lennart Borgman (gmail)" Newsgroups: gmane.emacs.devel Subject: Re: IDE features: M-x find-grep Date: Mon, 05 May 2008 22:21:50 +0200 Message-ID: <481F6C5E.6000106@gmail.com> References: <200804272236.28969.davi@leals.com> <87skx7gea3.fsf@kfs-lx.rd.rdm> <87k5icp98o.fsf@jurta.org> <481BB15A.9080204@gmail.com> <878wyrat3s.fsf@jurta.org> <200805040116.m441GZNT016282@projectile.siege-engine.com> <481D19D6.9090206@gmail.com> <200805040237.m442btFr016801@projectile.siege-engine.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------010800000207000909000504" X-Trace: ger.gmane.org 1210018978 5014 80.91.229.12 (5 May 2008 20:22:58 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 5 May 2008 20:22:58 +0000 (UTC) Cc: juri@jurta.org, storm@cua.dk, davi@leals.com, rms@gnu.org, emacs-devel@gnu.org To: "Eric M. Ludlam" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon May 05 22:23:32 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 1Jt7DI-00037Y-Es for ged-emacs-devel@m.gmane.org; Mon, 05 May 2008 22:23:08 +0200 Original-Received: from localhost ([127.0.0.1]:49254 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Jt7Ca-0007MZ-Hm for ged-emacs-devel@m.gmane.org; Mon, 05 May 2008 16:22:24 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Jt7CV-0007J6-0S for emacs-devel@gnu.org; Mon, 05 May 2008 16:22:19 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Jt7CU-0007I7-7G for emacs-devel@gnu.org; Mon, 05 May 2008 16:22:18 -0400 Original-Received: from [199.232.76.173] (port=34279 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Jt7CU-0007Hu-4A for emacs-devel@gnu.org; Mon, 05 May 2008 16:22:18 -0400 Original-Received: from ch-smtp02.sth.basefarm.net ([80.76.149.213]) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Jt7CO-0007M1-S9; Mon, 05 May 2008 16:22:13 -0400 Original-Received: from c83-254-150-27.bredband.comhem.se ([83.254.150.27]:60691 helo=[127.0.0.1]) by ch-smtp02.sth.basefarm.net with esmtp (Exim 4.68) (envelope-from ) id 1Jt7CG-00069V-9a; Mon, 05 May 2008 22:22:08 +0200 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071031 Thunderbird/2.0.0.9 Mnenhy/0.7.5.666 In-Reply-To: <200805040237.m442btFr016801@projectile.siege-engine.com> X-Antivirus: avast! (VPS 080504-0, 2008-05-04), Outbound message X-Antivirus-Status: Clean X-Originating-IP: 83.254.150.27 X-Scan-Result: No virus found in message 1Jt7CG-00069V-9a. X-Scan-Signature: ch-smtp02.sth.basefarm.net 1Jt7CG-00069V-9a e113cb433936b30c8a1432c29d6f8451 X-detected-kernel: by monty-python.gnu.org: Linux 2.6? (barebone, rare!) 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:96531 Archived-At: This is a multi-part message in MIME format. --------------010800000207000909000504 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Eric M. Ludlam wrote: >> One drawback of this might be that it is harder to learn which commands >> there are. Maybe this can be cured by showing the command to carry out >> on that page. > > Indeed. You would have half a screen to provide as much information > as needed, such as: > > -------------- > Find: Enter string to search for: > > [-!- ] <- gray widget here > > [ occur ] - Search this buffer [more] > [ multi-occur ] - Search many buffers [more] > > Arguments and Files for Search: > > [-!- ] <- gray widget here too > > [ grep ] - use grep to search files [more] > [ lgrep ] - use grep to search for regexp [more] > [ find-grep ] - Search files specified by find [more] > > ----------------- > > Not that I've used all these functions. > > Eric I have played a bit with this idea, see the attached file. (Note that lgrep/rgrep does not work at the moment.) --------------010800000207000909000504 Content-Type: text/plain; name="search-form.el" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="search-form.el" ;;; search-form.el --- Search form ;; ;; Author: Lennart Borgman (lennart O borgman A gmail O com) ;; Created: 2008-05-05T01:50:20+0200 Sun ;; Version: 0.1 ;; Last-Updated: ;; URL: ;; Keywords: ;; Compatibility: ;; ;; Features that might be required by this library: ;; ;; None ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;;; Commentary: ;; ;; After an idea by Eric Ludlam on Emacs Devel: ;; ;; http://lists.gnu.org/archive/html/emacs-devel/2008-05/msg00152.html ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;;; Change log: ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; This program is free software; you can redistribute it and/or ;; modify it under the terms of the GNU General Public License as ;; published by the Free Software Foundation; either version 2, or ;; (at your option) any later version. ;; ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; General Public License for more details. ;; ;; You should have received a copy of the GNU General Public License ;; along with this program; see the file COPYING. If not, write to ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth ;; Floor, Boston, MA 02110-1301, USA. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;;; Code: (require 'cus-edit) (defvar search-form-sfield nil) (make-variable-buffer-local 'search-form-sfield) (defvar search-form-rfield nil) (make-variable-buffer-local 'search-form-rfield) (defun search-form-multi-occur-get-buffers () (let* ((bufs (list (read-buffer "First buffer to search: " (current-buffer) t))) (buf nil) (ido-ignore-item-temp-list bufs)) (while (not (string-equal (setq buf (read-buffer (if (eq read-buffer-function 'ido-read-buffer) "Next buffer to search (C-j to end): " "Next buffer to search (RET to end): ") nil t)) "")) (add-to-list 'bufs buf) (setq ido-ignore-item-temp-list bufs)) (nreverse (mapcar #'get-buffer bufs)))) (defun search-form-notify-1 (use-search-field use-replace-field w &rest ignore) (let ((search-string (when use-search-field (widget-value search-form-sfield))) (replace-string (when use-replace-field (widget-value search-form-rfield))) (search-form-buffer (current-buffer)) (this-search (widget-get w :do-search)) (do-it t)) (when (and use-search-field (= 0 (length search-string))) (setq do-it nil) (message "Please specify a search string")) (when (and use-replace-field (= 0 (length replace-string))) (setq do-it nil) (message "Please specify a replace string")) (when do-it (delete-window (selected-window)) (funcall this-search w) (kill-buffer search-form-buffer) ;;(message "Done.") ))) (defun search-form-notify-no-field (w &rest ignore) (search-form-notify-1 nil nil w)) (defun search-form-notify-sfield (w &rest ignore) (search-form-notify-1 t nil w)) (defun search-form-notify-both-fields (w &rest ignore) (search-form-notify-1 t t w)) (defvar search-form-current-buffer nil) (defun search-form-insert-button (title function descr do-fun) (widget-insert " ") (let ((button-title (format " %-15s " title))) (widget-create 'push-button :do-search do-search-fun :notify 'search-form-notify-no-field :current-buffer search-form-current-buffer button-title)) (widget-insert " " descr) (widget-insert "\n")) (defun search-form-insert-search (title search-fun descr do-search-fun) (widget-insert " ") (let ((button-title (format " %-15s " title))) (widget-create 'push-button :do-search do-search-fun :notify 'search-form-notify-sfield :current-buffer search-form-current-buffer button-title)) (widget-insert " " descr " ") (search-form-insert-help search-fun) (widget-insert "\n")) (defun search-form-insert-fb (descr use-sfield forward-fun do-forward-fun backward-fun do-backward-fun) (widget-insert (format " %s: " descr)) (widget-create 'push-button :do-search do-forward-fun :notify (if use-sfield 'search-form-notify-sfield 'search-form-notify-no-field) :current-buffer search-form-current-buffer " Forward ") (widget-insert " ") (search-form-insert-help forward-fun) (widget-insert " ") (widget-create 'push-button :do-search do-backward-fun :notify (if use-sfield 'search-form-notify-sfield 'search-form-notify-no-field) :current-buffer search-form-current-buffer " Backward ") (widget-insert " ") (search-form-insert-help backward-fun) (widget-insert "\n")) (defun search-form-insert-replace (title replace-fun descr do-replace-fun) (widget-insert " ") (let ((button-title (format " %-15s " title))) (widget-create 'push-button :do-search do-replace-fun :notify 'search-form-notify-both-fields :current-buffer search-form-current-buffer button-title)) (widget-insert " " descr " ") (search-form-insert-help replace-fun) (widget-insert "\n")) (defun search-form-insert-help (fun) (widget-insert "(") (widget-create 'function-link :value fun :tag "help" :button-face 'link) (widget-insert ")")) (defun search-form () (interactive) (let* ((buf-name "*Search Form*") (cur-buf (current-buffer))) (setq search-form-current-buffer (current-buffer)) (switch-to-buffer-other-window buf-name) (kill-all-local-variables) ;; why??? (let ((inhibit-read-only t)) (erase-buffer)) ;;(Custom-mode) (remove-overlays) (make-local-variable 'widget-button-face) (setq widget-button-face custom-button) (setq show-trailing-whitespace nil) (when custom-raised-buttons (set (make-local-variable 'widget-push-button-prefix) "") (set (make-local-variable 'widget-push-button-suffix) "") (set (make-local-variable 'widget-link-prefix) "") (set (make-local-variable 'widget-link-suffix) "")) (widget-insert (propertize "Emacs Search/Replace Form" 'face 'font-lock-comment-face) "\n\n") (search-form-insert-fb "Incremental String Search" nil 'isearch-forward (lambda (w) (call-interactively 'isearch-forward)) 'isearch-backward (lambda (w) (call-interactively 'isearch-backward))) (search-form-insert-fb "Incremental Regexp Search" nil 'isearch-forward-regexp (lambda (w) (call-interactively 'isearch-forward-regexp)) 'isearch-backward-regexp (lambda (w) (call-interactively 'isearch-backward-regexp))) (widget-insert (make-string (window-width) ?-) "\n") (widget-insert "Search:") (setq search-form-sfield (widget-create 'editable-field :size 60)) (widget-insert "\n\n") (widget-insert (propertize "* Buffers:" 'face 'font-lock-comment-face) "\n") (search-form-insert-fb "String Search" t 'nonincremental-search-forward (lambda (w) (call-interactively 'nonincremental-search-forward search-string)) 'nonincremental-search-backward (lambda (w) (call-interactively 'nonincremental-search-backward search-string))) (search-form-insert-fb "Regexp Search" t 'nonincremental-re-search-forward (lambda (w) (call-interactively 'nonincremental-re-search-forward search-string)) 'nonincremental-re-search-backward (lambda (w) (call-interactively 'nonincremental-re-search-backward search-string))) ;; occur (search-form-insert-search "Occur" 'occur "Lines in this buffer" (lambda (w) (with-current-buffer (widget-get w :current-buffer) (occur search-string)))) ;; multi-occur (search-form-insert-search "Multi-Occur" 'multi-occur "Lines in specified buffers" (lambda (w) (let ((bufs (search-form-multi-occur-get-buffers))) (multi-occur bufs search-string)))) ;; (widget-insert "\n") (widget-insert (propertize "* Files:" 'face 'font-lock-comment-face) "\n") (search-form-insert-search "lgrep" 'lgrep "Grep in directory" (lambda (w) (with-current-buffer (widget-get w :current-buffer) (lgrep search-string)))) (search-form-insert-search "rgrep" 'rgrep "Grep in directory tree" (lambda (w) (with-current-buffer (widget-get w :current-buffer) (rgrep search-string)))) (widget-insert "\n") (search-form-insert-search "Tagged Files" 'tags-search "Search files in tags table" (lambda (w) (with-current-buffer (widget-get w :current-buffer) (tags-search search-string)))) (widget-insert (make-string (window-width) ?-) "\n") (widget-insert "Replace:") (setq search-form-rfield (widget-create 'editable-field :size 60)) (widget-insert "\n\n") (widget-insert (propertize "* Buffers:" 'face 'font-lock-comment-face) "\n") (search-form-insert-replace "Replace String" 'query-replace "In buffer from point" (lambda (w) (query-replace search-string replace-string))) (search-form-insert-replace "Replace Regexp" 'query-replace-regexp "In buffer from point" (lambda (w) (query-replace-regexp search-string replace-string))) (widget-insert "\n" (propertize "* Files:" 'face 'font-lock-comment-face) "\n") (search-form-insert-replace "Tagged Files" 'query-replace-regexp "Replace in files in tags tables" (lambda (w) (tags-query-replace search-string replace-string))) (buffer-disable-undo) (widget-setup) (buffer-enable-undo) (use-local-map widget-keymap) (widget-forward 1) )) (provide 'search-form) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; search-form.el ends here --------------010800000207000909000504--