unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* insert-directory
@ 2004-05-23 22:18 Luc Teirlinck
  2004-05-24  0:00 ` insert-directory Luc Teirlinck
  0 siblings, 1 reply; 17+ messages in thread
From: Luc Teirlinck @ 2004-05-23 22:18 UTC (permalink / raw)
  Cc: Peter Breton, pete_lee, Eli Zaretskii

Using the 'i' command in the *Locate* buffer one gets after `m-x locate'
currently does not work, because `insert-directory' mistakenly
believes that the last two lines of the buffer are:

//DIRED// 69 75 134 141 200 207 266 273 332 335
//DIRED-OPTIONS// --quoting-style=(null)

They are not, because locate.el sets dired-actual-switches to "".
`insert-directory' at present is not able to handle values of
dired-actual-switches that do not contain "-l".  The patch below tries
to support modes like locate-mode that, for some reason or another
need to set dired-actual-switches to a value not containing "-l".
I have the impression that it actually makes `insert-directory' safer
anyway, because, if for some reason these last two lines are not what
they are supposed to be, they should probably not be erased.  This is
what the patch does: check whether the last two lines are what we
think they are and not erase them otherwise.

After applying my patch, `i' in the *Locate* buffer seems to work
perfectly.

I will wait for a couple of days before installing the patch, to see
whether there are any objections and to check for possible problems in
my own usage.

===File ~/files-diff========================================
*** files.el	22 May 2004 14:29:26 -0500	1.695
--- files.el	23 May 2004 16:40:13 -0500	
***************
*** 4336,4356 ****
              (when (looking-at "//SUBDIRED//")
                (delete-region (point) (progn (forward-line 1) (point)))
                (forward-line -1))
! 	    (let ((end (line-end-position)))
! 	      (forward-word 1)
! 	      (forward-char 3)
! 	      (while (< (point) end)
! 		(let ((start (+ beg (read (current-buffer))))
! 		      (end (+ beg (read (current-buffer)))))
! 		  (if (= (char-after end) ?\n)
! 		      (put-text-property start end 'dired-filename t)
! 		    ;; It seems that we can't trust ls's output as to
! 		    ;; byte positions of filenames.
! 		    (put-text-property beg (point) 'dired-filename nil)
! 		    (end-of-line))))
! 	      (goto-char end)
! 	      (beginning-of-line)
! 	      (delete-region (point) (progn (forward-line 2) (point)))))
  
  	  ;; Now decode what read if necessary.
  	  (let ((coding (or coding-system-for-read
--- 4336,4358 ----
              (when (looking-at "//SUBDIRED//")
                (delete-region (point) (progn (forward-line 1) (point)))
                (forward-line -1))
! 	    (if (looking-at "//DIRED//")
! 		(let ((end (line-end-position)))
! 		  (forward-word 1)
! 		  (forward-char 3)
! 		  (while (< (point) end)
! 		    (let ((start (+ beg (read (current-buffer))))
! 			  (end (+ beg (read (current-buffer)))))
! 		      (if (= (char-after end) ?\n)
! 			  (put-text-property start end 'dired-filename t)
! 			;; It seems that we can't trust ls's output as to
! 			;; byte positions of filenames.
! 			(put-text-property beg (point) 'dired-filename nil)
! 			(end-of-line))))
! 		  (goto-char end)
! 		  (beginning-of-line)
! 		  (delete-region (point) (progn (forward-line 2) (point))))
! 	      (forward-line 2)))
  
  	  ;; Now decode what read if necessary.
  	  (let ((coding (or coding-system-for-read
============================================================

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: insert-directory
  2004-05-23 22:18 insert-directory Luc Teirlinck
@ 2004-05-24  0:00 ` Luc Teirlinck
  2004-05-24  3:29   ` insert-directory Luc Teirlinck
  2004-05-25 16:06   ` insert-directory Richard Stallman
  0 siblings, 2 replies; 17+ messages in thread
From: Luc Teirlinck @ 2004-05-24  0:00 UTC (permalink / raw)
  Cc: peter_breton, pete_lee, eliz, emacs-devel

I have to change my proposed patch to files.el to the new patch
included below.  There was a bug in my prior patch.  The new patch
changes the way empty directories are displayed if the "-a" switch is
not provided, in my opinion for the better.

Prior to my new patch, without -a switch, such directories were listed as:

  /home/teirllm/compdir/goodCVS:

After my new patch that becomes:

  /home/teirllm/compdir/goodCVS:
  total used in directory 0 available 21963572

I personally use the "-A" instead of the "-a" switch and I like the
new behavior a lot better.  It makes empty dired buffers stand out a
lot more clearly as being empty dired buffers.  A dired buffer with just:

  /home/teirllm/compdir/goodCVS:

looks weird and confusing/

The reason for the change is:

[bash2.05b.0 ~ 3 6] ls /home/teirllm/compdir/gogoCVS -Al --dired
  total 0
//DIRED-OPTIONS// --quoting-style=(null)
[bash2.05b.0 ~ 3 7] ls /home/teirllm/compdir/gogoCVS -al --dired
  total 8
  drwxrwxr-x    2 teirllm  teirllm      4096 Apr  5 21:42 .
  drwxrwxr-x    5 teirllm  teirllm      4096 Apr 11 21:13 ..
//DIRED// 68 69 128 130
//DIRED-OPTIONS// --quoting-style=(null)
[bash2.05b.0 ~ 3 8] 

New patch:

===File ~/files-diff-2======================================
*** files.el	22 May 2004 14:29:26 -0500	1.695
--- files.el	23 May 2004 18:11:03 -0500	
***************
*** 4336,4356 ****
              (when (looking-at "//SUBDIRED//")
                (delete-region (point) (progn (forward-line 1) (point)))
                (forward-line -1))
! 	    (let ((end (line-end-position)))
! 	      (forward-word 1)
! 	      (forward-char 3)
! 	      (while (< (point) end)
! 		(let ((start (+ beg (read (current-buffer))))
! 		      (end (+ beg (read (current-buffer)))))
! 		  (if (= (char-after end) ?\n)
! 		      (put-text-property start end 'dired-filename t)
! 		    ;; It seems that we can't trust ls's output as to
! 		    ;; byte positions of filenames.
! 		    (put-text-property beg (point) 'dired-filename nil)
! 		    (end-of-line))))
! 	      (goto-char end)
! 	      (beginning-of-line)
! 	      (delete-region (point) (progn (forward-line 2) (point)))))
  
  	  ;; Now decode what read if necessary.
  	  (let ((coding (or coding-system-for-read
--- 4336,4361 ----
              (when (looking-at "//SUBDIRED//")
                (delete-region (point) (progn (forward-line 1) (point)))
                (forward-line -1))
! 	    (if (looking-at "//DIRED//")
! 		(let ((end (line-end-position)))
! 		  (forward-word 1)
! 		  (forward-char 3)
! 		  (while (< (point) end)
! 		    (let ((start (+ beg (read (current-buffer))))
! 			  (end (+ beg (read (current-buffer)))))
! 		      (if (= (char-after end) ?\n)
! 			  (put-text-property start end 'dired-filename t)
! 			;; It seems that we can't trust ls's output as to
! 			;; byte positions of filenames.
! 			(put-text-property beg (point) 'dired-filename nil)
! 			(end-of-line))))
! 		  (goto-char end)
! 		  (beginning-of-line)
! 		  (delete-region (point) (progn (forward-line 2) (point))))
! 	      (forward-line 1)
! 	      (if (looking-at "//DIRED-OPTIONS//")
! 		  (delete-region (point) (progn (forward-line 1) (point)))	
! 		(forward-line 1))))
  
  	  ;; Now decode what read if necessary.
  	  (let ((coding (or coding-system-for-read
============================================================

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: insert-directory
  2004-05-24  0:00 ` insert-directory Luc Teirlinck
@ 2004-05-24  3:29   ` Luc Teirlinck
  2004-05-24  3:55     ` insert-directory Luc Teirlinck
                       ` (2 more replies)
  2004-05-25 16:06   ` insert-directory Richard Stallman
  1 sibling, 3 replies; 17+ messages in thread
From: Luc Teirlinck @ 2004-05-24  3:29 UTC (permalink / raw)
  Cc: peter_breton, pete_lee, eliz, emacs-devel

With my latest patch, `i' inserts subdirectories correctly, but the
file names are not correctly recognized.  That is, one can see what
the files are, but one can not operate on them.  To fix that, one
needs a much more liberal definition of `dired-move-to-filename-regexp'
in *Locate* buffers.  (See the patch below.)  Essentially, the new
regexp first tries to recognize the file names as before.  If this does
not work, anything after the first two spaces is treated as the filename,
except if it starts with `/', in which case there is no file on the line.
Seems to work well.  Are there any situations where this could give trouble?

===File ~/locate-diff=======================================
*** locate.el	20 May 2004 17:14:36 -0500	1.22
--- locate.el	23 May 2004 21:58:54 -0500	
***************
*** 345,353 ****
    (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)
--- 345,353 ----
    (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)
============================================================

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: insert-directory
  2004-05-24  3:29   ` insert-directory Luc Teirlinck
@ 2004-05-24  3:55     ` Luc Teirlinck
  2004-05-24  3:55     ` insert-directory Luc Teirlinck
  2004-05-24  4:16     ` insert-directory Luc Teirlinck
  2 siblings, 0 replies; 17+ messages in thread
From: Luc Teirlinck @ 2004-05-24  3:55 UTC (permalink / raw)
  Cc: peter_breton, pete_lee, eliz, emacs-devel

>From my previous message:

   Are there any situations where this could give trouble?

Well, the proposed value of `dired-move-to-filename-regexp' (like the
old one) is going to loose for file names that start with exactly two
spaces, then a letter, then a colon.  A file named "  c:myfile" in a
subdirectory inserted with `i' is going to be mistaken for a file
named "myfile" on drive c: of an MS Windows system.  That _already_ is
the case with the current regexp.  I would guess the risk of actually
encountering such file names is small enough not to worry about.

Sincerely,

Luc.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: insert-directory
  2004-05-24  3:29   ` insert-directory Luc Teirlinck
  2004-05-24  3:55     ` insert-directory Luc Teirlinck
@ 2004-05-24  3:55     ` Luc Teirlinck
  2004-05-24  4:16     ` insert-directory Luc Teirlinck
  2 siblings, 0 replies; 17+ messages in thread
From: Luc Teirlinck @ 2004-05-24  3:55 UTC (permalink / raw)
  Cc: peter_breton, pete_lee, eliz, emacs-devel

>From my previous message:

   Are there any situations where this could give trouble?

Well, the proposed value of `dired-move-to-filename-regexp' (like the
old one) is going to loose for file names that start with exactly two
spaces, then a letter, then a colon.  A file named "  c:myfile" in a
subdirectory inserted with `i' is going to be mistaken for a file
named "myfile" on drive c: of an MS Windows system.  That _already_ is
the case with the current regexp.  I would guess the risk of actually
encountering such file names is small enough not to worry about.

Sincerely,

Luc.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: insert-directory
  2004-05-24  3:29   ` insert-directory Luc Teirlinck
  2004-05-24  3:55     ` insert-directory Luc Teirlinck
  2004-05-24  3:55     ` insert-directory Luc Teirlinck
@ 2004-05-24  4:16     ` Luc Teirlinck
  2004-05-25  0:11       ` insert-directory Luc Teirlinck
  2 siblings, 1 reply; 17+ messages in thread
From: Luc Teirlinck @ 2004-05-24  4:16 UTC (permalink / raw)
  Cc: peter_breton, pete_lee, eliz, emacs-devel

Sorry for accidentally sending my prior message twice.  I should point
out that the new dired-move-to-filename-regexp value will make dired
commands work properly in the inserted subdirectory, but not the
locate commands mouse-2 and V.  In the case of V, I guess that users
would not find this very surprising, as the relative file name looks
so differently from the absolute file names locate uses.  Fixing
mouse-2 seems easy, but I will wait to see whether there are
objections against the new regexp.

Sincerely,

Luc.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: insert-directory
  2004-05-24  4:16     ` insert-directory Luc Teirlinck
@ 2004-05-25  0:11       ` Luc Teirlinck
  2004-05-25  2:16         ` insert-directory Luc Teirlinck
  0 siblings, 1 reply; 17+ messages in thread
From: Luc Teirlinck @ 2004-05-25  0:11 UTC (permalink / raw)
  Cc: peter_breton, pete_lee, eliz, emacs-devel

Below is my latest corrected version of
`dired-move-to-filename-regexp'.  There are actually two regular
expressions.  One for MS Windows and one for Unix style names.  I
believe that the non-MS Windows one one works for all GNU-Unix style
file names, even if they mimic MS style names.  I have tested it quite
a bit on GNU/Linux and it seems to work fine.

Remaining issues with `dired-move-to-filename-regexp':

I do not know anything about VMS, but I believe that the old value
_already_ made no attempt to deal with VMS.

Actually, apart from what I have read in the Elisp manual or learned
from reading emacs-devel, I do not know anything about MS Windows
either.  Based on what Eli told me I _believe_ that the value I chose
should work, even after a bunch of recursive `i' 's.  However, I have
no way to check and maybe my regexp for MS Windows might contain the
most obvious stupidities.  Somebody with access to MS Windows and
interested in using `i' in *Locate* buffers will have to check (and
possibly correct or replace) my regexp.

Other issues:

I propose to replace the first line "Matches for..." with " Matches
for..."  Putting one space at the beginning fixes a bug: with the
current first line, doing *! erases the `M", after which the first
line looks weird.  Using two instead of one space would interfere with
the new value of `dired-move-to-filename-regexp'.

Mouse-2 currently does not work on the part inserted by `i'.
Moreover, anybody used to dired, or find-dired or similar, will expect
mouse-2 to visit the file in another window.  Is there any reason for
doing anything different in locate-mode, especially since the dired
commamd `v' will view the file.  Is there any substantial difference
between `dired-view-file' (`v') and `locate-mouse-view-file'?
The patch below just erases the current mouse-2 binding, thereby making
the dired binding visible again.  But that part of the patch can, of
course, easily be taken out again if there is disagreement.

I do not know what `dired-permission-flags-regexp' is used for in
locate-mode, but I did not detect any problems resulting from leaving
it unchanged after doing `i'.

I will wait a couple of days before committing, to see whether there
are objections to any of the proposed changes, as well as to think
them over myself.

===File ~/locate-diff=======================================
*** locate.el	20 May 2004 17:14:36 -0500	1.22
--- locate.el	24 May 2004 16:36:07 -0500	
***************
*** 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)
--- 281,286 ----
***************
*** 345,353 ****
    (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)
--- 344,357 ----
    (make-local-variable 'dired-move-to-filename-regexp)
    ;; This should support both Unix and Windoze style names
    (setq dired-move-to-filename-regexp
! 	(if (memq system-type '(ms-dos windows-nt))
! 	    (concat "^."
! 		    (make-string (1- locate-filename-indentation) ?\ )
! 		    "\\(/\\|[A-Za-z]:\\)\\|"
! 		    (default-value 'dired-move-to-filename-regexp))
! 	  (concat "^.\\("
! 		  (make-string (1- locate-filename-indentation) ?\ )
! 		  "/\\| /.*\\| \\)")))
    (make-local-variable 'dired-actual-switches)
    (setq dired-actual-switches "")
    (make-local-variable 'dired-permission-flags-regexp)
***************
*** 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))
--- 390,396 ----
        (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))
============================================================

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: insert-directory
  2004-05-25  0:11       ` insert-directory Luc Teirlinck
@ 2004-05-25  2:16         ` Luc Teirlinck
  2004-05-26 20:26           ` insert-directory Luc Teirlinck
  0 siblings, 1 reply; 17+ messages in thread
From: Luc Teirlinck @ 2004-05-25  2:16 UTC (permalink / raw)
  Cc: peter_breton, pete_lee, eliz, emacs-devel

Actually, my previous patch could not handle `C-u i', and had some
other problems.  I now changed my mind.  I believe that `i' should, by
default, use the "-al" switches, like on MS Windows.  Certain dired
functionality gets problematic if the "-l" switch is not used.  I
would have preferred to use `dired-listing-switches' instead of "-al",
but that yields real problems if dired-listing-switches contains "-F".
As in dired, one can specify one's own switches with `C-u i'.

As a byproduct, all operating systems have once more the same value
for `dired-move-to-filename-regexp'.  It is the value I originally
used for MS Windows.

Everything seems to work a lot better than with my previous patch.

===File ~/locate-diff=======================================
*** locate.el	20 May 2004 17:14:36 -0500	1.22
--- locate.el	24 May 2004 20:53:29 -0500	
***************
*** 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)
--- 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 "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)
***************
*** 325,330 ****
--- 325,346 ----
      (goto-char (posn-point (event-start event)))
      (view-file (locate-get-filename))))
  
+ (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
  ;; expect to be in a tree, will work properly
***************
*** 345,353 ****
    (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)
--- 361,370 ----
    (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)
***************
*** 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))
--- 403,409 ----
        (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))
============================================================

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: insert-directory
  2004-05-24  0:00 ` insert-directory Luc Teirlinck
  2004-05-24  3:29   ` insert-directory Luc Teirlinck
@ 2004-05-25 16:06   ` Richard Stallman
  1 sibling, 0 replies; 17+ messages in thread
From: Richard Stallman @ 2004-05-25 16:06 UTC (permalink / raw)
  Cc: pete_lee, peter_breton, teirllm, eliz, emacs-devel

    --- 4336,4361 ----
		  (when (looking-at "//SUBDIRED//")
		    (delete-region (point) (progn (forward-line 1) (point)))
		    (forward-line -1))
    ! 	    (if (looking-at "//DIRED//")
    ! 		(let ((end (line-end-position)))
    ! 		  (forward-word 1)
    ! 		  (forward-char 3)
    ! 		  (while (< (point) end)
    ! 		    (let ((start (+ beg (read (current-buffer))))
    ! 			  (end (+ beg (read (current-buffer)))))
    ! 		      (if (= (char-after end) ?\n)
    ! 			  (put-text-property start end 'dired-filename t)
    ! 			;; It seems that we can't trust ls's output as to
    ! 			;; byte positions of filenames.
    ! 			(put-text-property beg (point) 'dired-filename nil)
    ! 			(end-of-line))))
    ! 		  (goto-char end)
    ! 		  (beginning-of-line)
    ! 		  (delete-region (point) (progn (forward-line 2) (point))))
    ! 	      (forward-line 1)
    ! 	      (if (looking-at "//DIRED-OPTIONS//")
    ! 		  (delete-region (point) (progn (forward-line 1) (point)))	
    ! 		(forward-line 1))))

I don't see any harm in that patch, so please install it
if you want to.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: insert-directory
  2004-05-25  2:16         ` insert-directory Luc Teirlinck
@ 2004-05-26 20:26           ` Luc Teirlinck
  2004-05-26 20:35             ` insert-directory David Kastrup
  2004-05-27  7:01             ` insert-directory Kai Grossjohann
  0 siblings, 2 replies; 17+ messages in thread
From: Luc Teirlinck @ 2004-05-26 20:26 UTC (permalink / raw)
  Cc: peter_breton, pete_lee, eliz

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 <stephen@cns.ed.ac.uk>
  (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 <stephen@cns.ed.ac.uk>
  (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."
============================================================

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: insert-directory
  2004-05-26 20:26           ` insert-directory Luc Teirlinck
@ 2004-05-26 20:35             ` David Kastrup
  2004-05-26 20:42               ` insert-directory Luc Teirlinck
  2004-05-27  7:01             ` insert-directory Kai Grossjohann
  1 sibling, 1 reply; 17+ messages in thread
From: David Kastrup @ 2004-05-26 20:35 UTC (permalink / raw)
  Cc: peter_breton, pete_lee, eliz, emacs-devel

Luc Teirlinck <teirllm@dms.auburn.edu> writes:

> 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?

While the locate process is still running, you are adding to the
buffer.  Could it be something like that?

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: insert-directory
  2004-05-26 20:35             ` insert-directory David Kastrup
@ 2004-05-26 20:42               ` Luc Teirlinck
  0 siblings, 0 replies; 17+ messages in thread
From: Luc Teirlinck @ 2004-05-26 20:42 UTC (permalink / raw)
  Cc: peter_breton, pete_lee, eliz, emacs-devel

David Kastrup wrote:

   Luc Teirlinck <teirllm@dms.auburn.edu> writes:

   > 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?

   While the locate process is still running, you are adding to the
   buffer.  Could it be something like that?

Yes, but I believe that my patch binds inhibit-read-only to t around
the one place in `locate' that does all the inserting.  Did you try it
out and did you find some place I forgot about?

Sincerely,

Luc.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: insert-directory
  2004-05-26 20:26           ` insert-directory Luc Teirlinck
  2004-05-26 20:35             ` insert-directory David Kastrup
@ 2004-05-27  7:01             ` Kai Grossjohann
  2004-05-27 15:51               ` insert-directory Luc Teirlinck
  2004-06-07  9:59               ` locate and find-dired (was: insert-directory) Juri Linkov
  1 sibling, 2 replies; 17+ messages in thread
From: Kai Grossjohann @ 2004-05-27  7:01 UTC (permalink / raw)


Luc Teirlinck <teirllm@dms.auburn.edu> writes:

> 3.  Making `i' work _absolutely perfectly_ in _every possible aspect_
>     seems theoretically impossible, because the buffer is not in
>     dired-mode.

I wonder if it makes sense to have the locate output look more like
the find-dired output?  Then the buffer could be in dired mode
normally.  (One could call file-attributes on each filename returned
by locate and construct "ls -l" like output from that.)

Isn't there a new feature of hiding parts of the "ls -l" output for
dired?  That could then be conveniently used to display less than the
filenames.

Kai

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: insert-directory
  2004-05-27  7:01             ` insert-directory Kai Grossjohann
@ 2004-05-27 15:51               ` Luc Teirlinck
  2004-06-07  9:59               ` locate and find-dired (was: insert-directory) Juri Linkov
  1 sibling, 0 replies; 17+ messages in thread
From: Luc Teirlinck @ 2004-05-27 15:51 UTC (permalink / raw)
  Cc: emacs-devel

Kai Grossjohann wrote:

   Luc Teirlinck <teirllm@dms.auburn.edu> writes:

   > 3.  Making `i' work _absolutely perfectly_ in _every possible aspect_
   >     seems theoretically impossible, because the buffer is not in
   >     dired-mode.

   I wonder if it makes sense to have the locate output look more like
   the find-dired output?  Then the buffer could be in dired mode
   normally.  (One could call file-attributes on each filename returned
   by locate and construct "ls -l" like output from that.)

I am afraid that would force a complete rewrite of locate.el.

In spite of my theoretical concerns above, things seem to work well in
practice.  I am a little bit reluctant to post a new patch each time a
make a further minor change but I added:

(setq selective-display t)
(set (make-local-variable 'page-delimiter) "\n\n")

and after that, the parts inserted by `i' are pretty much in
dired-mode.  The reason why those parts can be while the main listing
is not are the "\\|" in the regular expressions.

That leaves us with the one problem we can not get around:
parts of the dired-code that do:
(if (eq major-mode 'dired-mode)
and the like.

There are several places like that in dired-aux and dired-x, but at
first sight they do not seem applicable.  The one place in dired.el
itself is `dired-sort-other':

  (if (eq major-mode 'dired-mode) (dired-sort-set-modeline))

But (dired-sort-set-modeline) _really_ only makes sense if the buffer is
in dired-mode.

After adding the two lines above, the only dired commands that seem to
produce problems are the updating commands `g' and `l' (on a directory
header line).  `g' in locate-mode will produce problems anyway, unless
you are running as root.  If you are not you get:

fatal error: updatedb: You are not authorized to create a default
slocate database!

Actually, the trouble with `l' (or the remaining problem with `g', if
you are root) are a dired problem.  Dired does not store the switches
used for a subdirectory.  (I believe that, sooner or later, this
should be fixed.)  As a result, not only does `l' on a directory
header line give problems in *Locate* and (after applying the patch
for find-dired I posted) in *Find* buffers, but it gives problems in
ordinary dired buffers as well if `C-u i' was used.  In particular,
`C-u i' does not work in a dired buffer in which auto-revert-mode is
enabled.  The switches get overridden after 0 to 5 seconds.
Auto-reverting does not work in *Locate* or *Find* buffers anyway.

Sincerely,

Luc.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* locate and find-dired (was: insert-directory)
  2004-05-27  7:01             ` insert-directory Kai Grossjohann
  2004-05-27 15:51               ` insert-directory Luc Teirlinck
@ 2004-06-07  9:59               ` Juri Linkov
  2004-06-07 11:17                 ` locate and find-dired Kai Grossjohann
  1 sibling, 1 reply; 17+ messages in thread
From: Juri Linkov @ 2004-06-07  9:59 UTC (permalink / raw)
  Cc: Luc Teirlinck, emacs-devel

Kai Grossjohann <kai@emptydomain.de> writes:
> I wonder if it makes sense to have the locate output look more like
> the find-dired output?  Then the buffer could be in dired mode
> normally.  (One could call file-attributes on each filename returned
> by locate and construct "ls -l" like output from that.)

This would be very useful, because often there is a need to look at
file attributes of files returned by locate, and also it will allow
dired operations on files.

There are at least two solutions.  One doesn't require any
modification and can be simply invoked as:

C-u M-x locate RET locate filename | xargs ls -alG RET

This produces interesting results with recent Luc's changes: it
automatically inserts found subdirectories into *Locate* buffer.

Another solution is to extend find-dired.el to allow arbitrary
command lines.  For example, a new variable `find-dired-program'
could be set to "locate %s | xargs ls ", so results of `locate'
are put into dired mode.  [Note that the code below is NOT a finished
patch for installing into CVS, this is simply an example of possible
extension of find-dired.el]

--- lisp/find-dired.el	6 Jun 2004 02:30:21 -0000	1.48
+++ lisp/find-dired.el	7 Jun 2004 09:48:43 -0000
@@ -40,6 +40,11 @@
   :group 'dired
   :type 'file)
 
+(defcustom find-dired-program nil
+  "Command line used to find files."
+  :group 'dired
+  :type 'string)
+
 ;; find's -ls corresponds to these switches.
 ;; Note -b, at least GNU find quotes spaces etc. in filenames
 ;;;###autoload
@@ -125,11 +130,14 @@
     (erase-buffer)
     (setq default-directory dir
 	  find-args args	      ; save for next interactive call
-	  args (concat find-dired-find-program " . "
+	  args (if find-dired-program
+                   (concat (format find-dired-program args)
+                           (cdr find-ls-option))
+                 (concat find-dired-find-program " . "
 		       (if (string= args "")
 			   ""
 			 (concat "\\( " args " \\) "))
-		       (car find-ls-option)))
+		       (car find-ls-option))))
     ;; Start the find process.
     (shell-command (concat args "&") (current-buffer))
     ;; The next statement will bomb in classic dired (no optional arg allowed)

-- 
Juri Linkov
http://www.jurta.org/emacs/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: locate and find-dired
  2004-06-07  9:59               ` locate and find-dired (was: insert-directory) Juri Linkov
@ 2004-06-07 11:17                 ` Kai Grossjohann
  2004-06-07 11:59                   ` Juri Linkov
  0 siblings, 1 reply; 17+ messages in thread
From: Kai Grossjohann @ 2004-06-07 11:17 UTC (permalink / raw)


Juri Linkov <juri@jurta.org> writes:

> C-u M-x locate RET locate filename | xargs ls -alG RET
>
> This produces interesting results with recent Luc's changes: it
> automatically inserts found subdirectories into *Locate* buffer.

Slightly off-topic remark: I guess that "ls -alGd" instead of "ls
-alG" would prevent the auto-insertions.

It's a cool trick.

Kai

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: locate and find-dired
  2004-06-07 11:17                 ` locate and find-dired Kai Grossjohann
@ 2004-06-07 11:59                   ` Juri Linkov
  0 siblings, 0 replies; 17+ messages in thread
From: Juri Linkov @ 2004-06-07 11:59 UTC (permalink / raw)
  Cc: emacs-devel

Kai Grossjohann <kai@emptydomain.de> writes:
> Juri Linkov <juri@jurta.org> writes:
>
>> C-u M-x locate RET locate filename | xargs ls -alG RET
>>
>> This produces interesting results with recent Luc's changes: it
>> automatically inserts found subdirectories into *Locate* buffer.
>
> Slightly off-topic remark: I guess that "ls -alGd" instead of "ls
> -alG" would prevent the auto-insertions.

Right!

And while talking about keys, I want also to note that it's better to add
`-e' key to `locate' to not produce lines with "No such file or directory".

-- 
Juri Linkov
http://www.jurta.org/emacs/

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2004-06-07 11:59 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-05-23 22:18 insert-directory Luc Teirlinck
2004-05-24  0:00 ` insert-directory Luc Teirlinck
2004-05-24  3:29   ` insert-directory Luc Teirlinck
2004-05-24  3:55     ` insert-directory Luc Teirlinck
2004-05-24  3:55     ` insert-directory Luc Teirlinck
2004-05-24  4:16     ` insert-directory Luc Teirlinck
2004-05-25  0:11       ` insert-directory Luc Teirlinck
2004-05-25  2:16         ` insert-directory Luc Teirlinck
2004-05-26 20:26           ` insert-directory Luc Teirlinck
2004-05-26 20:35             ` insert-directory David Kastrup
2004-05-26 20:42               ` insert-directory Luc Teirlinck
2004-05-27  7:01             ` insert-directory Kai Grossjohann
2004-05-27 15:51               ` insert-directory Luc Teirlinck
2004-06-07  9:59               ` locate and find-dired (was: insert-directory) Juri Linkov
2004-06-07 11:17                 ` locate and find-dired Kai Grossjohann
2004-06-07 11:59                   ` Juri Linkov
2004-05-25 16:06   ` insert-directory Richard Stallman

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).