From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Luc Teirlinck Newsgroups: gmane.emacs.devel Subject: Re: insert-directory Date: Wed, 26 May 2004 15:26:28 -0500 (CDT) Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <200405262026.i4QKQSq13079@raven.dms.auburn.edu> References: <200405232218.i4NMIw307789@raven.dms.auburn.edu> <200405240000.i4O00ck07917@raven.dms.auburn.edu> <200405240329.i4O3T4B08005@raven.dms.auburn.edu> <200405240416.i4O4GBX08071@raven.dms.auburn.edu> <200405250011.i4P0BtV17183@raven.dms.auburn.edu> <200405250216.i4P2GO717266@raven.dms.auburn.edu> NNTP-Posting-Host: deer.gmane.org X-Trace: sea.gmane.org 1085604264 22885 80.91.224.253 (26 May 2004 20:44:24 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 26 May 2004 20:44:24 +0000 (UTC) Cc: peter_breton@yahoo.com, pete_lee@swbell.net, eliz@gnu.org Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Wed May 26 22:43:56 2004 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1BT5Fk-0001Q5-00 for ; Wed, 26 May 2004 22:43:56 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1BT5Fj-0000YU-00 for ; Wed, 26 May 2004 22:43:55 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.34) id 1BT50D-0000Ib-4F for emacs-devel@quimby.gnus.org; Wed, 26 May 2004 16:27:53 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.34) id 1BT501-0000IF-Mj for emacs-devel@gnu.org; Wed, 26 May 2004 16:27:41 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.34) id 1BT4zV-0000Cw-NL for emacs-devel@gnu.org; Wed, 26 May 2004 16:27:40 -0400 Original-Received: from [131.204.53.104] (helo=manatee.dms.auburn.edu) by monty-python.gnu.org with esmtp (Exim 4.34) id 1BT4zV-0000Cq-B5; Wed, 26 May 2004 16:27:09 -0400 Original-Received: from raven.dms.auburn.edu (raven.dms.auburn.edu [131.204.53.29]) by manatee.dms.auburn.edu (8.12.10/8.12.10) with ESMTP id i4QKR8uE001909; Wed, 26 May 2004 15:27:08 -0500 (CDT) Original-Received: (from teirllm@localhost) by raven.dms.auburn.edu (8.11.6+Sun/8.11.6) id i4QKQSq13079; Wed, 26 May 2004 15:26:28 -0500 (CDT) X-Authentication-Warning: raven.dms.auburn.edu: teirllm set sender to teirllm@dms.auburn.edu using -f Original-To: emacs-devel@gnu.org In-reply-to: <200405250216.i4P2GO717266@raven.dms.auburn.edu> (message from Luc Teirlinck on Mon, 24 May 2004 21:16:24 -0500 (CDT)) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:23978 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:23978 Below is the latest version of my patch to make `i' in *Locate* buffers work. Before installing it I want to point out the following: 1. Making `i' work requires making the *Locate* buffer read-only. Otherwise, with inserted directories, trying to use `undo' and similar commands will result in complete confusion. Is there any reason for the *Locate* buffer _not_ to be read-only? 2. It rebinds mouse-2 to the usual dired binding, to avoid confusion. It binds locate-mouse-view-file (the current mouse-2 binding) to M-mouse-2, because the usual binding for M-mouse-2, yanking the secondary selection, becomes meaningless if the *Locate* buffer is made read-only. Are the two above changes OK? 3. Making `i' work _absolutely perfectly_ in _every possible aspect_ seems theoretically impossible, because the buffer is not in dired-mode. 4. It is not completely clear whether `i' was ever really intended to work in *Locate* buffers. Several other dired commands like `<' and `>' do not seem to work either. (After my patch they do work inside subdirectories, but still not in the main listing.) In spite of (3), all commands I tried out (and I tried many) seem to work perfectly in subdirectories (after applying my latest patch below). However, I somehow have the feeling that, even though I could not find any, there must be _some_ commands that malfunction, since dired commands expect the buffer to be in dired-mode. _Without_ my patch, `i' correctly lists the subdirectory, even on GNU/Linux (since I installed my patch to files.el), but dired commands do not work in it. ===File ~/locate-diff======================================= *** locate.el 20 May 2004 17:14:36 -0500 1.22 --- locate.el 26 May 2004 13:19:04 -0500 *************** *** 223,241 **** (save-window-excursion (set-buffer (get-buffer-create locate-buffer-name)) (locate-mode) ! (erase-buffer) ! (setq locate-current-filter filter) ! (if run-locate-command ! (shell-command search-string locate-buffer-name) ! (apply 'call-process locate-cmd nil t nil locate-cmd-args)) ! (and filter ! (locate-filter-output filter)) ! (locate-do-setup search-string) ! ) (and (not (string-equal (buffer-name) locate-buffer-name)) (switch-to-buffer-other-window locate-buffer-name)) --- 223,242 ---- (save-window-excursion (set-buffer (get-buffer-create locate-buffer-name)) (locate-mode) ! (let ((inhibit-read-only t)) ! (erase-buffer) ! (setq locate-current-filter filter) ! (if run-locate-command ! (shell-command search-string locate-buffer-name) ! (apply 'call-process locate-cmd nil t nil locate-cmd-args)) ! (and filter ! (locate-filter-output filter)) ! (locate-do-setup search-string) ! )) (and (not (string-equal (buffer-name) locate-buffer-name)) (switch-to-buffer-other-window locate-buffer-name)) *************** *** 281,287 **** (define-key locate-mode-map [menu-bar mark directories] 'undefined) (define-key locate-mode-map [menu-bar mark symlinks] 'undefined) ! (define-key locate-mode-map [mouse-2] 'locate-mouse-view-file) (define-key locate-mode-map "\C-c\C-t" 'locate-tags) (define-key locate-mode-map "U" 'dired-unmark-all-files) --- 282,289 ---- (define-key locate-mode-map [menu-bar mark directories] 'undefined) (define-key locate-mode-map [menu-bar mark symlinks] 'undefined) ! (define-key locate-mode-map [M-mouse-2] 'locate-mouse-view-file) ! (define-key locate-mode-map "i" 'locate-maybe-insert-subdir) (define-key locate-mode-map "\C-c\C-t" 'locate-tags) (define-key locate-mode-map "U" 'dired-unmark-all-files) *************** *** 318,329 **** (not (eq lineno 2)) (buffer-substring (elt pos 0) (elt pos 1))))) (defun locate-mouse-view-file (event) "In Locate mode, view a file, using the mouse." (interactive "@e") (save-excursion (goto-char (posn-point (event-start event))) ! (view-file (locate-get-filename)))) ;; Define a mode for locate ;; Default directory is set to "/" so that dired commands, which --- 320,359 ---- (not (eq lineno 2)) (buffer-substring (elt pos 0) (elt pos 1))))) + (defun locate-main-listing-line-p () + "Return t if current line contains a file name listed by locate. + This function returns nil if the current line either contains no + file name or is inside a subdirectory." + (save-excursion + (forward-line 0) + (looking-at (concat "." + (make-string (1- locate-filename-indentation) ?\ ) + "\\(/\\|[A-Za-z]:\\)")))) + (defun locate-mouse-view-file (event) "In Locate mode, view a file, using the mouse." (interactive "@e") (save-excursion (goto-char (posn-point (event-start event))) ! (if (locate-main-listing-line-p) ! (view-file (locate-get-filename)) ! (message "This command only works inside main listing.")))) ! ! (defun locate-maybe-insert-subdir (dirname &optional ! switches no-error-if-not-dir-p) ! "Like `dired-maybe-insert-subdir', but works in `locate-mode'. ! `locate-mode' needs a special command for this to replace its own ! binding of `dired-actual-switches' with \"-al\", when called ! interactively. As with `dired-maybe-insert-subdir', you can ! specify your own switches by providing a numeric prefix argument, ! but you can not specify the \"-F\" switch. For proper ! functioning, you should specify the \"-l\" switch." ! (interactive ! (list (dired-get-filename) ! (if current-prefix-arg ! (read-string "Switches for listing: " "-al") ! "-al"))) ! (dired-maybe-insert-subdir dirname switches no-error-if-not-dir-p)) ;; Define a mode for locate ;; Default directory is set to "/" so that dired commands, which *************** *** 345,362 **** (make-local-variable 'dired-move-to-filename-regexp) ;; This should support both Unix and Windoze style names (setq dired-move-to-filename-regexp ! (concat "." (make-string (1- locate-filename-indentation) ?\ ) ! "\\(/\\|[A-Za-z]:\\)")) (make-local-variable 'dired-actual-switches) (setq dired-actual-switches "") (make-local-variable 'dired-permission-flags-regexp) (setq dired-permission-flags-regexp (concat "^.\\(" (make-string (1- locate-filename-indentation) ?\ ) ! "\\)")) (make-local-variable 'revert-buffer-function) (setq revert-buffer-function 'locate-update) (run-hooks 'locate-mode-hook)) (defun locate-do-setup (search-string) --- 375,395 ---- (make-local-variable 'dired-move-to-filename-regexp) ;; This should support both Unix and Windoze style names (setq dired-move-to-filename-regexp ! (concat "^." (make-string (1- locate-filename-indentation) ?\ ) ! "\\(/\\|[A-Za-z]:\\)\\|" ! (default-value 'dired-move-to-filename-regexp))) (make-local-variable 'dired-actual-switches) (setq dired-actual-switches "") (make-local-variable 'dired-permission-flags-regexp) (setq dired-permission-flags-regexp (concat "^.\\(" (make-string (1- locate-filename-indentation) ?\ ) ! "\\)\\|" ! (default-value 'dired-permission-flags-regexp))) (make-local-variable 'revert-buffer-function) (setq revert-buffer-function 'locate-update) + (setq buffer-read-only t) (run-hooks 'locate-mode-hook)) (defun locate-do-setup (search-string) *************** *** 386,392 **** (dired-insert-set-properties (elt pos 0) (elt pos 1))))) (defun locate-insert-header (search-string) ! (let ((locate-format-string "Matches for %s") (locate-regexp-match (concat " *Matches for \\(" (regexp-quote search-string) "\\)")) (locate-format-args (list search-string)) --- 419,425 ---- (dired-insert-set-properties (elt pos 0) (elt pos 1))))) (defun locate-insert-header (search-string) ! (let ((locate-format-string " Matches for %s") (locate-regexp-match (concat " *Matches for \\(" (regexp-quote search-string) "\\)")) (locate-format-args (list search-string)) *************** *** 439,447 **** (defun locate-tags () "Visit a tags table in `*Locate*' mode." (interactive) ! (let ((tags-table (locate-get-filename))) ! (and (y-or-n-p (format "Visit tags table %s? " tags-table)) ! (visit-tags-table tags-table)))) ;; From Stephen Eglen (defun locate-update (ignore1 ignore2) --- 472,482 ---- (defun locate-tags () "Visit a tags table in `*Locate*' mode." (interactive) ! (if (locate-main-listing-line-p) ! (let ((tags-table (locate-get-filename))) ! (and (y-or-n-p (format "Visit tags table %s? " tags-table)) ! (visit-tags-table tags-table))) ! (message "This command only works inside main listing."))) ;; From Stephen Eglen (defun locate-update (ignore1 ignore2) *************** *** 460,471 **** (defun locate-find-directory () "Visit the directory of the file mentioned on this line." (interactive) ! (let ((directory-name (locate-get-dirname))) ! (if (file-directory-p directory-name) ! (find-file directory-name) ! (if (file-symlink-p directory-name) ! (error "Directory is a symlink to a nonexistent target") ! (error "Directory no longer exists; run `updatedb' to update database"))))) (defun locate-find-directory-other-window () "Visit the directory of the file named on this line in other window." --- 495,508 ---- (defun locate-find-directory () "Visit the directory of the file mentioned on this line." (interactive) ! (if (locate-main-listing-line-p) ! (let ((directory-name (locate-get-dirname))) ! (if (file-directory-p directory-name) ! (find-file directory-name) ! (if (file-symlink-p directory-name) ! (error "Directory is a symlink to a nonexistent target") ! (error "Directory no longer exists; run `updatedb' to update database")))) ! (message "This command only works inside main listing."))) (defun locate-find-directory-other-window () "Visit the directory of the file named on this line in other window." ============================================================