[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: insert-directory
From: |
Luc Teirlinck |
Subject: |
Re: insert-directory |
Date: |
Wed, 26 May 2004 15:26:28 -0500 (CDT) |
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 <address@hidden>
(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 <address@hidden>
(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."
============================================================
- insert-directory, Luc Teirlinck, 2004/05/23
- Re: insert-directory, Luc Teirlinck, 2004/05/23
- Re: insert-directory, Luc Teirlinck, 2004/05/23
- Re: insert-directory, Luc Teirlinck, 2004/05/24
- Re: insert-directory, Luc Teirlinck, 2004/05/24
- Re: insert-directory, Luc Teirlinck, 2004/05/24
- Re: insert-directory, Luc Teirlinck, 2004/05/24
- Re: insert-directory, Luc Teirlinck, 2004/05/24
- Re: insert-directory,
Luc Teirlinck <=
- Re: insert-directory, David Kastrup, 2004/05/26
- Re: insert-directory, Luc Teirlinck, 2004/05/26
- Re: insert-directory, Kai Grossjohann, 2004/05/27
- Re: insert-directory, Luc Teirlinck, 2004/05/27
Re: insert-directory, Richard Stallman, 2004/05/25