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: isearch in Dired Date: Wed, 23 Jul 2008 23:34:07 +0300 Organization: JURTA Message-ID: <87r69k2vcw.fsf_-_@jurta.org> References: <874pjaiv45.fsf@gmail.com> <87lkclekep.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 1216849556 22963 80.91.229.12 (23 Jul 2008 21:45:56 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 23 Jul 2008 21:45:56 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Jul 23 23:46:45 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 1KLmAL-0005pK-7Q for ged-emacs-devel@m.gmane.org; Wed, 23 Jul 2008 23:46:33 +0200 Original-Received: from localhost ([127.0.0.1]:53984 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KLm9R-0001So-RO for ged-emacs-devel@m.gmane.org; Wed, 23 Jul 2008 17:45:37 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KLm9C-0001OS-0l for emacs-devel@gnu.org; Wed, 23 Jul 2008 17:45:22 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KLm9B-0001O9-BE for emacs-devel@gnu.org; Wed, 23 Jul 2008 17:45:21 -0400 Original-Received: from [199.232.76.173] (port=33515 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KLm9B-0001O2-5B for emacs-devel@gnu.org; Wed, 23 Jul 2008 17:45:21 -0400 Original-Received: from anti-4.kiev.sovam.com ([62.64.120.202]:59187) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KLm9A-0005pv-M4 for emacs-devel@gnu.org; Wed, 23 Jul 2008 17:45:21 -0400 Original-Received: from [83.170.232.243] (helo=smtp.svitonline.com) by anti-4.kiev.sovam.com with esmtp (Exim 4.67) (envelope-from ) id 1KLm8z-000Hov-3U for emacs-devel@gnu.org; Thu, 24 Jul 2008 00:45:18 +0300 In-Reply-To: <87lkclekep.fsf@jurta.org> (Juri Linkov's message of "Thu, 09 Aug 2007 01:54:38 +0300") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (x86_64-pc-linux-gnu) X-Scanner-Signature: 135131bad4241a7f2e3eac3b7218434b X-DrWeb-checked: yes X-SpamTest-Envelope-From: juri@jurta.org X-SpamTest-Group-ID: 00000000 X-SpamTest-Header: Trusted X-SpamTest-Info: Profiles 4427 [July 23 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:101339 Archived-At: Isearch in Dired limited to filenames only is a good feature, so I'd like to finish it with the patch below. The main point is that it doesn't change default Isearch key bindings C-s and C-M-s. It provides two ways to limit Isearch to filenames: 1. new user option `dired-isearch-filenames'. It is nil by default, but when custimized to non-nil, C-s and C-M-s search only in filenames. 2. new commands `'dired-do-isearch-filenames' and `dired-do-isearch-regexp-filenames' bound to the keys `M-s f C-s' and `M-s f M-C-s'. Two similar key bindings from another patch are for demonstration purposes: `M-s a C-s' and `M-s a M-C-s' are placed on the same prefix key and they start Isearch in all marked files. For this feature to work reliably it was necessary to put text properties `filename' on file name areas. Tramp already puts it in Tramp buffer, and it seems the `filename' property in all Dired buffers doesn't conflict with Tramp. Index: lisp/dired.el =================================================================== RCS file: /sources/emacs/emacs/lisp/dired.el,v retrieving revision 1.402 diff -c -r1.402 dired.el *** lisp/dired.el 19 Jul 2008 23:55:41 -0000 1.402 --- lisp/dired.el 23 Jul 2008 20:33:44 -0000 *************** *** 1068,1074 **** (dired-move-to-end-of-filename) (point)) '(mouse-face highlight ! help-echo "mouse-2: visit this file in other window"))) (error nil)) (forward-line 1)))) --- 1068,1075 ---- (dired-move-to-end-of-filename) (point)) '(mouse-face highlight ! help-echo "mouse-2: visit this file in other window" ! filename t))) (error nil)) (forward-line 1)))) *************** *** 1295,1300 **** --- 1297,1307 ---- ;; hiding (define-key map "$" 'dired-hide-subdir) (define-key map "\M-$" 'dired-hide-all) + ;; isearch + (define-key map (kbd "M-s a C-s") 'dired-do-isearch-marked-files) + (define-key map (kbd "M-s a M-C-s") 'dired-do-isearch-regexp-marked-files) + (define-key map (kbd "M-s f C-s") 'dired-do-isearch-filenames) + (define-key map (kbd "M-s f M-C-s") 'dired-do-isearch-regexp-filenames) ;; misc (define-key map "\C-x\C-q" 'dired-toggle-read-only) (define-key map "?" 'dired-summary) *************** *** 1713,1718 **** --- 1720,1726 ---- (when (featurep 'dnd) (set (make-local-variable 'dnd-protocol-alist) (append dired-dnd-protocol-alist dnd-protocol-alist))) + (add-hook 'isearch-mode-hook 'dired-isearch-filenames-setup nil t) (run-mode-hooks 'dired-mode-hook)) ;; Idiosyncratic dired commands that don't deal with marks. Index: lisp/dired-aux.el =================================================================== RCS file: /sources/emacs/emacs/lisp/dired-aux.el,v retrieving revision 1.170 diff -c -r1.170 dired-aux.el *** lisp/dired-aux.el 6 May 2008 07:57:30 -0000 1.170 --- lisp/dired-aux.el 23 Jul 2008 20:33:59 -0000 *************** *** 2273,2281 **** --- 2293,2363 ---- ;;;###end dired-ins.el + ;; Search only in file names in the Dired buffer. + + (defcustom dired-isearch-filenames nil + "*If non-nil, Isearch in Dired matches only file names." + :version "23.1" + :type '(choice (const :tag "No restrictions" nil) + (const :tag "Isearch only in file names" filename)) + :group 'dired) + + (defvar dired-isearch-orig-success-function nil) + + (defun dired-isearch-filenames-setup () + "Set up isearch to search in Dired file names. + Intended to be added to `isearch-mode-hook'." + (when dired-isearch-filenames + (setq dired-isearch-orig-success-function + (default-value 'isearch-success-function)) + (setq-default isearch-success-function 'dired-isearch-success-function) + (add-hook 'isearch-mode-end-hook 'dired-isearch-filenames-end nil t))) + + (defun dired-isearch-filenames-end () + "Clean up the Dired file name search after terminating isearch." + (setq-default isearch-success-function dired-isearch-orig-success-function) + (remove-hook 'isearch-mode-end-hook 'dired-isearch-filenames-end t)) + + (defun dired-isearch-success-function (beg end) + "Isearch only text that have a property specified in `dired-isearch-filenames'." + (and (isearch-success-function-default beg end) + (if dired-isearch-filenames + (text-property-not-all (min beg end) (max beg end) + 'filename nil) + t))) + + ;;;###autoload + (defun dired-do-isearch-filenames () + "Search for a string only in file names in the Dired buffer." + (interactive) + (let ((dired-isearch-filenames t)) + (isearch-forward))) + + ;;;###autoload + (defun dired-do-isearch-regexp-filenames () + "Search for a regexp only in file names in the Dired buffer." + (interactive) + (let ((dired-isearch-filenames t)) + (isearch-forward-regexp))) + + ;; Functions for searching in tags style among marked files. -- Juri Linkov http://www.jurta.org/emacs/