From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.devel Subject: Dired patch for `i' - bounce between subdir line and its inserted listing Date: Sat, 8 Mar 2008 15:14:30 -0800 Message-ID: <002601c88172$2a0dc720$0600a8c0@us.oracle.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0027_01C8812F.1BEA8720" X-Trace: ger.gmane.org 1205018113 16777 80.91.229.12 (8 Mar 2008 23:15:13 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 8 Mar 2008 23:15:13 +0000 (UTC) To: Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Mar 09 00:15:39 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 1JY8GN-0002t4-2B for ged-emacs-devel@m.gmane.org; Sun, 09 Mar 2008 00:15:36 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JY8Fo-0003ch-WF for ged-emacs-devel@m.gmane.org; Sat, 08 Mar 2008 18:15:01 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JY8Fk-0003cZ-6y for emacs-devel@gnu.org; Sat, 08 Mar 2008 18:14:56 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JY8Fi-0003cN-8c for emacs-devel@gnu.org; Sat, 08 Mar 2008 18:14:55 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JY8Fi-0003cK-2W for emacs-devel@gnu.org; Sat, 08 Mar 2008 18:14:54 -0500 Original-Received: from agminet01.oracle.com ([141.146.126.228]) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1JY8Fh-0000El-I1 for emacs-devel@gnu.org; Sat, 08 Mar 2008 18:14:53 -0500 Original-Received: from rgmgw2.us.oracle.com (rgmgw2.us.oracle.com [138.1.186.111]) by agminet01.oracle.com (Switch-3.2.4/Switch-3.1.7) with ESMTP id m28NEo5d024986 for ; Sat, 8 Mar 2008 17:14:50 -0600 Original-Received: from acsmt351.oracle.com (acsmt351.oracle.com [141.146.40.151]) by rgmgw2.us.oracle.com (Switch-3.2.4/Switch-3.2.4) with ESMTP id m28LpxEJ007299 for ; Sat, 8 Mar 2008 16:14:49 -0700 Original-Received: from inet-141-146-46-1.oracle.com by acsmt350.oracle.com with ESMTP id 3605236121205018087; Sat, 08 Mar 2008 15:14:47 -0800 Original-Received: from dradamslap1 (/141.144.88.217) by bhmail.oracle.com (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 08 Mar 2008 15:14:47 -0800 X-Mailer: Microsoft Office Outlook 11 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 Thread-Index: AciBcims0WWnIblVRaCw4NTu+MoBxw== X-Brightmail-Tracker: AAAAAQAAAAI= X-Brightmail-Tracker: AAAAAQAAAAI= X-Whitelist: TRUE X-Whitelist: TRUE X-detected-kernel: by monty-python.gnu.org: Linux 2.4-2.6 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:91797 Archived-At: This is a multi-part message in MIME format. ------=_NextPart_000_0027_01C8812F.1BEA8720 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Attached is a patch for Dired (dired.el and dired-aux.el). It extends `i', giving it behavior on a non-directory line and on subdir header lines, where it currently just raises a wrong-line error. This provides a handy go-back behavior, letting you bounce back and forth between a subdirectory line and its inserted listing. `i' on a non-directory file within a subdir listing acts the same as it does on the subdir's header line, so you need not be on the header line to bounce back: anywhere within the subdir listing will do. More precisely - Currently: * If you hit `i' on a directory line, it goes to the corresponding subdirectory listing header line. If the subdirectory listing has not yet been inserted, `i' first inserts it and then goes to it. * If you hit `i' anywhere else, it raises an error: either "No file on this line" (for a header line) or "Attempt to insert a non-directory: c:/foobar". This is not useful. With the patch: * `i' on a directory line does the same thing as before: insert and goto. * `i' on a non-directory line in the top-level directory also does the same thing as before: nothing. * (NEW) `i' on a subdir header line or a non-directory file in a subdir listing goes to the line for that subdir in the parent directory listing. Please try the patch. It should work in all contexts, including with hidden subdirs. The patch also fixes a bug that occurs in `dired-get-filename' if you use the `ls' switch `F', as in `ls -alF'. In that case, the test for a dot file `.' or `..' fails, because with switch `F' the names appear as `./' and `../'. BTW, I'm surprised that bug wasn't reported before. Don't you all use `F'? And shouldn't `ls -alF' be the default switches value? ------=_NextPart_000_0027_01C8812F.1BEA8720 Content-Type: application/octet-stream; name="dired-aux-2008-03-07.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="dired-aux-2008-03-07.patch" diff -c -w dired-aux-CVS-2008-03-07.el dired-aux-patched-2008-03-07.el=0A= *** dired-aux-CVS-2008-03-07.el Sat Mar 8 00:00:02 2008=0A= --- dired-aux-patched-2008-03-07.el Sat Mar 8 00:07:24 2008=0A= ***************=0A= *** 1858,1895 ****=0A= ;;;###begin dired-ins.el=0A= =0A= ;;;###autoload=0A= ! (defun dired-maybe-insert-subdir (dirname &optional=0A= ! switches no-error-if-not-dir-p)=0A= ! "Insert this subdirectory into the same dired buffer.=0A= ! If it is already present, just move to it (type \\[dired-do-redisplay] = to refresh),=0A= ! else inserts it at its natural place (as `ls -lR' would have done).=0A= ! With a prefix arg, you may edit the ls switches used for this listing.=0A= ! You can add `R' to the switches to expand the whole tree starting at=0A= ! this subdirectory.=0A= ! This function takes some pains to conform to `ls -lR' output.=0A= ! =0A= ! Dired remembers switches specified with a prefix arg, so that reverting=0A= ! the buffer will not reset them. However, using `dired-undo' to = re-insert=0A= ! or delete subdirectories can bypass this machinery. Hence, you = sometimes=0A= ! may have to reset some subdirectory switches after a `dired-undo'.=0A= ! You can reset all subdirectory switches to the default using=0A= ! \\\\[dired-reset-subdir-switches].=0A= ! See Info node `(emacs)Subdir switches' for more details."=0A= ! (interactive=0A= ! (list (dired-get-filename)=0A= ! (if current-prefix-arg=0A= (read-string "Switches for listing: "=0A= (or dired-subdir-switches dired-actual-switches)))))=0A= ! (let ((opoint (point)))=0A= ;; We don't need a marker for opoint as the subdir is always=0A= ;; inserted *after* opoint.=0A= (setq dirname (file-name-as-directory dirname))=0A= (or (and (not switches)=0A= (dired-goto-subdir dirname))=0A= (dired-insert-subdir dirname switches no-error-if-not-dir-p))=0A= ! ;; Push mark so that it's easy to find back. Do this after the=0A= ! ;; insert message so that the user sees the `Mark set' message.=0A= ! (push-mark opoint)))=0A= =0A= ;;;###autoload=0A= (defun dired-insert-subdir (dirname &optional switches = no-error-if-not-dir-p)=0A= --- 1858,1928 ----=0A= ;;;###begin dired-ins.el=0A= =0A= ;;;###autoload=0A= ! (defun dired-maybe-insert-subdir (dirname &optional switches = no-error-if-not-dir-p)=0A= ! "Move to Dired subdirectory line or subdirectory listing.=0A= ! This bounces you back and forth between a subdirectory line and its=0A= ! inserted listing header line. Using it on a non-directory line in a=0A= ! subdirectory listing acts the same as using it on the subdirectory=0A= ! header line.=0A= ! =0A= ! * If on a subdirectory line, then go to the subdirectory's listing,=0A= ! creating it if not yet present.=0A= ! =0A= ! * If on a subdirectory listing header line or a non-directory file in=0A= ! a subdirectory listing, then go to the line for the subdirectory in=0A= ! the parent directory listing.=0A= ! =0A= ! * If on a non-directory file in the top Dired directory listing, do=0A= ! nothing.=0A= ! =0A= ! Subdirectories are listed in the same position as for `ls -lR' output.=0A= ! =0A= ! With a prefix arg, you can edit the `ls' switches used for this=0A= ! listing. Add `R' to the switches to expand the directory tree under a=0A= ! subdirectory.=0A= ! =0A= ! Dired remembers the switches you specify with a prefix arg, so=0A= ! reverting the buffer does not reset them. However, you might=0A= ! sometimes need to reset some subdirectory switches after a=0A= ! `dired-undo'. You can reset all subdirectory switches to the=0A= ! default value using \\\\[dired-reset-subdir-switches]. = See \=0A= ! Info node=0A= ! `(emacs)Subdir switches' for more details."=0A= ! (interactive (list (dired-this-subdir)=0A= ! (and current-prefix-arg=0A= (read-string "Switches for listing: "=0A= (or dired-subdir-switches = dired-actual-switches)))))=0A= ! (let ((opoint (point))=0A= ! (filename dirname))=0A= ! (if (consp filename) ; Subdir header line or = non-directory file.=0A= ! (progn (setq filename (car filename))=0A= ! (if (assoc filename dired-subdir-alist)=0A= ! (dired-goto-file filename) ; Subdir header line.=0A= ! (dired-insert-subdir=0A= ! (substring (file-name-directory filename) 0 -1))))=0A= ;; We don't need a marker for opoint as the subdir is always=0A= ;; inserted *after* opoint.=0A= (setq dirname (file-name-as-directory dirname))=0A= (or (and (not switches)=0A= (dired-goto-subdir dirname))=0A= (dired-insert-subdir dirname switches no-error-if-not-dir-p))=0A= ! ;; Push mark so that it's easy to go back. Do this after the=0A= ! ;; insertion message so that the user sees the `Mark set' = message.=0A= ! (push-mark opoint))))=0A= ! =0A= ! (defun dired-this-subdir ()=0A= ! "This line's filename, if directory, or `dired-current-directory' = list.=0A= ! If on a directory line, then return the directory name.=0A= ! Else return a singleton list of a directory name, which is as follows:=0A= ! If on a subdirectory header line (either of the two lines), then use=0A= ! that subdirectory name. Else use the parent directory name."=0A= ! (or (let ((file (dired-get-filename nil t)))=0A= ! (and file (file-directory-p file)=0A= ! (not (member (file-relative-name file (file-name-directory=0A= ! = (directory-file-name file)))=0A= ! '("." ".." "./" "../")))=0A= ! file))=0A= ! (list (dired-current-directory))))=0A= =0A= ;;;###autoload=0A= (defun dired-insert-subdir (dirname &optional switches = no-error-if-not-dir-p)=0A= =0A= Diff finished. Sat Mar 08 00:15:25 2008=0A= ------=_NextPart_000_0027_01C8812F.1BEA8720 Content-Type: application/octet-stream; name="dired-2008-03-07.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="dired-2008-03-07.patch" diff -c -w dired-CVS-2008-03-07.el dired-patched-2008-03-07.el=0A= *** dired-CVS-2008-03-07.el Fri Mar 7 23:59:44 2008=0A= --- dired-patched-2008-03-07.el Sat Mar 8 00:13:40 2008=0A= ***************=0A= *** 1823,1837 ****=0A= (if (setq p1 (dired-move-to-filename (not = no-error-if-not-filep)))=0A= (setq p2 (dired-move-to-end-of-filename no-error-if-not-filep))))=0A= ;; nil if no file on this line, but no-error-if-not-filep is t:=0A= ! (if (setq file (and p1 p2 (buffer-substring p1 p2)))=0A= ! (progn=0A= ;; Get rid of the mouse-face property that file names have.=0A= (set-text-properties 0 (length file) nil file)=0A= ;; Unquote names quoted by ls or by dired-insert-directory.=0A= ;; Using read to unquote is much faster than substituting=0A= ;; \007 (4 chars) -> ^G (1 char) etc. in a lisp loop.=0A= ! (setq file=0A= ! (read=0A= (concat "\""=0A= ;; Some ls -b don't escape quotes, argh!=0A= ;; This is not needed for GNU ls, though.=0A= --- 1823,1835 ----=0A= (if (setq p1 (dired-move-to-filename (not = no-error-if-not-filep)))=0A= (setq p2 (dired-move-to-end-of-filename = no-error-if-not-filep))))=0A= ;; nil if no file on this line, but no-error-if-not-filep is t:=0A= ! (when (setq file (and p1 p2 (buffer-substring p1 p2)))=0A= ;; Get rid of the mouse-face property that file names have.=0A= (set-text-properties 0 (length file) nil file)=0A= ;; Unquote names quoted by ls or by dired-insert-directory.=0A= ;; Using read to unquote is much faster than substituting=0A= ;; \007 (4 chars) -> ^G (1 char) etc. in a lisp loop.=0A= ! (setq file (read=0A= (concat "\""=0A= ;; Some ls -b don't escape quotes, argh!=0A= ;; This is not needed for GNU ls, though.=0A= ***************=0A= *** 1841,1861 ****=0A= "\"")))=0A= ;; The above `read' will return a unibyte string if FILE=0A= ;; contains eight-bit-control/graphic characters.=0A= ! (if (and enable-multibyte-characters=0A= (not (multibyte-string-p file)))=0A= ! (setq file (string-to-multibyte file)))))=0A= (and file (file-name-absolute-p file)=0A= ;; A relative file name can start with ~.=0A= ;; Don't treat it as absolute in this context.=0A= (not (eq (aref file 0) ?~))=0A= (setq already-absolute t))=0A= ! (cond=0A= ! ((null file)=0A= ! nil)=0A= ! ((eq localp 'verbatim)=0A= ! file)=0A= ! ((and (not no-error-if-not-filep)=0A= ! (member file '("." "..")))=0A= (error "Cannot operate on `.' or `..'"))=0A= ((and (eq localp 'no-dir) already-absolute)=0A= (file-name-nondirectory file))=0A= --- 1839,1855 ----=0A= "\"")))=0A= ;; The above `read' will return a unibyte string if FILE=0A= ;; contains eight-bit-control/graphic characters.=0A= ! (when (and enable-multibyte-characters=0A= (not (multibyte-string-p file)))=0A= ! (setq file (string-to-multibyte file))))=0A= (and file (file-name-absolute-p file)=0A= ;; A relative file name can start with ~.=0A= ;; Don't treat it as absolute in this context.=0A= (not (eq (aref file 0) ?~))=0A= (setq already-absolute t))=0A= ! (cond ((null file) nil)=0A= ! ((eq localp 'verbatim) file)=0A= ! ((and (not no-error-if-not-filep) (member file '("." ".." = "./" "../")))=0A= (error "Cannot operate on `.' or `..'"))=0A= ((and (eq localp 'no-dir) already-absolute)=0A= (file-name-nondirectory file))=0A= ***************=0A= *** 1867,1874 ****=0A= (if (and handler (not (get handler 'safe-magic)))=0A= (concat "/:" file)=0A= file)))=0A= ! ((eq localp 'no-dir)=0A= ! file)=0A= ((equal (dired-current-directory) "/")=0A= (setq file (concat (dired-current-directory localp) file))=0A= (let ((handler (find-file-name-handler file nil)))=0A= --- 1861,1867 ----=0A= (if (and handler (not (get handler 'safe-magic)))=0A= (concat "/:" file)=0A= file)))=0A= ! ((eq localp 'no-dir) file)=0A= ((equal (dired-current-directory) "/")=0A= (setq file (concat (dired-current-directory localp) file))=0A= (let ((handler (find-file-name-handler file nil)))=0A= ***************=0A= *** 1878,1885 ****=0A= (if (and handler (not (get handler 'safe-magic)))=0A= (concat "/:" file)=0A= file)))=0A= ! (t=0A= ! (concat (dired-current-directory localp) file)))))=0A= =0A= (defun dired-string-replace-match (regexp string newtext=0A= &optional literal global)=0A= --- 1871,1877 ----=0A= (if (and handler (not (get handler 'safe-magic)))=0A= (concat "/:" file)=0A= file)))=0A= ! (t (concat (dired-current-directory localp) file)))))=0A= =0A= (defun dired-string-replace-match (regexp string newtext=0A= &optional literal global)=0A= ***************=0A= *** 2324,2333 ****=0A= ;; the search faster (e.g. for the filename "-"!).=0A= (search-forward (concat " " search-string)=0A= boundary 'move))=0A= ;; Match could have BASE just as initial substring or=0A= ;; or in permission bits or date or=0A= ;; not be a proper filename at all:=0A= ! (if (equal base (dired-get-filename 'no-dir t))=0A= ;; Must move to filename since an (actually=0A= ;; correct) match could have been elsewhere on the=0A= ;; ;; line (e.g. "-" would match somewhere in the=0A= --- 2316,2326 ----=0A= ;; the search faster (e.g. for the filename = "-"!).=0A= (search-forward (concat " " search-string)=0A= boundary 'move))=0A= + ;; Remove / from filename, then compare with BASE.=0A= ;; Match could have BASE just as initial substring or=0A= ;; or in permission bits or date or=0A= ;; not be a proper filename at all:=0A= ! (if (equal base (directory-file-name (dired-get-filename = 'no-dir t)))=0A= ;; Must move to filename since an (actually=0A= ;; correct) match could have been elsewhere on the=0A= ;; ;; line (e.g. "-" would match somewhere in the=0A= =0A= Diff finished. Sat Mar 08 00:14:02 2008=0A= ------=_NextPart_000_0027_01C8812F.1BEA8720--