Commit 30abce25 authored by Glenn Morris's avatar Glenn Morris
Browse files

Merge dired-x's dired-add-entry modifications into the main definition.

* lisp/dired-aux.el (dired-add-entry): Give it a doc-string.
Merge dired-x's dired-omit handling here.
(dired-omit-mode, dired-omit-regexp, dired-omit-localp): Declare.

* lisp/dired-x.el (dired-omit-new-add-entry): Merge into dired-add-entry.

* doc/misc/dired-x.texi (Technical Details): No longer redefines
dired-add-entry.
parent 4d737eb2
2011-02-19 Glenn Morris <rgm@gnu.org>
* dired-x.texi (Technical Details): No longer redefines dired-add-entry.
2011-02-18 Glenn Morris <rgm@gnu.org> 2011-02-18 Glenn Morris <rgm@gnu.org>
* dired-x.texi (Optional Installation File At Point): Simplify. * dired-x.texi (Optional Installation File At Point): Simplify.
......
...@@ -190,14 +190,9 @@ from @file{dired.el} ...@@ -190,14 +190,9 @@ from @file{dired.el}
@end itemize @end itemize
@noindent @noindent
and the following functions from @file{dired-aux.el} and from @file{dired-aux.el} the function @code{dired-read-shell-command}.
In addition, once @file{dired.el} is loaded, @code{dired-add-entry}
@itemize @bullet obeys Dired Omit mode (@pxref{Omitting Files in Dired}), if it is active.
@item
@code{dired-add-entry}
@item
@code{dired-read-shell-command}
@end itemize
@node Installation, Omitting Files in Dired, Introduction, Top @node Installation, Omitting Files in Dired, Introduction, Top
@chapter Installation @chapter Installation
......
2011-02-19 Glenn Morris <rgm@gnu.org> 2011-02-19 Glenn Morris <rgm@gnu.org>
* dired-x.el (dired-omit-new-add-entry): Merge into dired-add-entry.
* dired-aux.el (dired-add-entry): Give it a doc-string.
Merge dired-x's dired-omit handling here.
(dired-omit-mode, dired-omit-regexp, dired-omit-localp): Declare.
* international/mule-diag.el (list-input-methods-1): * international/mule-diag.el (list-input-methods-1):
Indent all lines of multi-line doc-strings. (Bug#8066) Indent all lines of multi-line doc-strings. (Bug#8066)
......
...@@ -1039,92 +1039,124 @@ See Info node `(emacs)Subdir switches' for more details." ...@@ -1039,92 +1039,124 @@ See Info node `(emacs)Subdir switches' for more details."
(file-name-directory filename) (file-name-nondirectory filename) (file-name-directory filename) (file-name-nondirectory filename)
(function dired-add-entry) filename marker-char)) (function dired-add-entry) filename marker-char))
(defvar dired-omit-mode)
(declare-function dired-omit-regexp "dired-x" ())
(defvar dired-omit-localp)
(defun dired-add-entry (filename &optional marker-char relative) (defun dired-add-entry (filename &optional marker-char relative)
;; Add a new entry for FILENAME, optionally marking it "Add a new dired entry for FILENAME.
;; with MARKER-CHAR (a character, else dired-marker-char is used). Optionally mark it with MARKER-CHAR (a character, else uses
;; Note that this adds the entry `out of order' if files sorted by `dired-marker-char'). Note that this adds the entry `out of order'
;; time, etc. if files are sorted by time, etc.
;; At least this version inserts in the right subdirectory (if present). Skips files that match `dired-trivial-filenames'.
;; And it skips "." or ".." (see `dired-trivial-filenames'). Exposes hidden subdirectories if a file is added there.
;; Hidden subdirs are exposed if a file is added there.
(setq filename (directory-file-name filename)) If `dired-x' is loaded and `dired-omit-mode' is enabled, skips
;; Entry is always for files, even if they happen to also be directories files matching `dired-omit-regexp'."
(let* ((opoint (point)) (if (or (not (featurep 'dired-x))
(cur-dir (dired-current-directory)) (not dired-omit-mode)
(orig-file-name filename) ;; Avoid calling ls for files that are going to be omitted anyway.
(directory (if relative cur-dir (file-name-directory filename))) (let ((omit-re (dired-omit-regexp)))
reason) (or (string= omit-re "")
(setq filename (not (string-match omit-re
(if relative (cond
(file-relative-name filename directory) ((eq 'no-dir dired-omit-localp)
(file-name-nondirectory filename)) filename)
reason ((eq t dired-omit-localp)
(catch 'not-found (dired-make-relative filename))
(if (string= directory cur-dir) (t
(progn (dired-make-absolute
(skip-chars-forward "^\r\n") filename
(if (eq (following-char) ?\r) (file-name-directory filename)))))))))
(dired-unhide-subdir)) ;; Do it!
;; We are already where we should be, except when (progn
;; point is before the subdir line or its total line. (setq filename (directory-file-name filename))
(let ((p (dired-after-subdir-garbage cur-dir))) ;; Entry is always for files, even if they happen to also be directories
(if (< (point) p) (let* ((opoint (point))
(goto-char p)))) (cur-dir (dired-current-directory))
;; else try to find correct place to insert (orig-file-name filename)
(if (dired-goto-subdir directory) (directory (if relative cur-dir (file-name-directory filename)))
(progn ;; unhide if necessary reason)
(if (looking-at "\r") ;; point is at end of subdir line (setq filename
(dired-unhide-subdir)) (if relative
;; found - skip subdir and `total' line (file-relative-name filename directory)
;; and uninteresting files like . and .. (file-name-nondirectory filename))
;; This better not moves into the next subdir! reason
(dired-goto-next-nontrivial-file)) (catch 'not-found
;; not found (if (string= directory cur-dir)
(throw 'not-found "Subdir not found"))) (progn
(let (buffer-read-only opoint) (skip-chars-forward "^\r\n")
(beginning-of-line) (if (eq (following-char) ?\r)
(setq opoint (point)) (dired-unhide-subdir))
;; Don't expand `.'. Show just the file name within directory. ;; We are already where we should be, except when
(let ((default-directory directory)) ;; point is before the subdir line or its total line.
(dired-insert-directory directory (let ((p (dired-after-subdir-garbage cur-dir)))
(concat dired-actual-switches " -d") (if (< (point) p)
(list filename))) (goto-char p))))
(goto-char opoint) ;; else try to find correct place to insert
;; Put in desired marker char. (if (dired-goto-subdir directory)
(when marker-char (progn ;; unhide if necessary
(let ((dired-marker-char (if (looking-at "\r")
(if (integerp marker-char) marker-char dired-marker-char))) ;; Point is at end of subdir line.
(dired-mark nil))) (dired-unhide-subdir))
;; Compensate for a bug in ange-ftp. ;; found - skip subdir and `total' line
;; It inserts the file's absolute name, rather than ;; and uninteresting files like . and ..
;; the relative one. That may be hard to fix since it ;; This better not move into the next subdir!
;; is probably controlled by something in ftp. (dired-goto-next-nontrivial-file))
(goto-char opoint) ;; not found
(let ((inserted-name (dired-get-filename 'verbatim))) (throw 'not-found "Subdir not found")))
(if (file-name-directory inserted-name) (let (buffer-read-only opoint)
(let (props) (beginning-of-line)
(end-of-line) (setq opoint (point))
(forward-char (- (length inserted-name))) ;; Don't expand `.'.
(setq props (text-properties-at (point))) ;; Show just the file name within directory.
(delete-char (length inserted-name)) (let ((default-directory directory))
(let ((pt (point))) (dired-insert-directory
(insert filename) directory
(set-text-properties pt (point) props)) (concat dired-actual-switches " -d")
(forward-char 1)) (list filename)))
(forward-line 1))) (goto-char opoint)
(forward-line -1) ;; Put in desired marker char.
(if dired-after-readin-hook ;; the subdir-alist is not affected... (when marker-char
(save-excursion ;; ...so we can run it right now: (let ((dired-marker-char
(save-restriction (if (integerp marker-char) marker-char
(beginning-of-line) dired-marker-char)))
(narrow-to-region (point) (line-beginning-position 2)) (dired-mark nil)))
(run-hooks 'dired-after-readin-hook)))) ;; Compensate for a bug in ange-ftp.
(dired-move-to-filename)) ;; It inserts the file's absolute name, rather than
;; return nil if all went well ;; the relative one. That may be hard to fix since it
nil)) ;; is probably controlled by something in ftp.
(if reason ; don't move away on failure (goto-char opoint)
(goto-char opoint)) (let ((inserted-name (dired-get-filename 'verbatim)))
(not reason))) ; return t on success, nil else (if (file-name-directory inserted-name)
(let (props)
(end-of-line)
(forward-char (- (length inserted-name)))
(setq props (text-properties-at (point)))
(delete-char (length inserted-name))
(let ((pt (point)))
(insert filename)
(set-text-properties pt (point) props))
(forward-char 1))
(forward-line 1)))
(forward-line -1)
(if dired-after-readin-hook
;; The subdir-alist is not affected...
(save-excursion ; ...so we can run it right now:
(save-restriction
(beginning-of-line)
(narrow-to-region (point)
(line-beginning-position 2))
(run-hooks 'dired-after-readin-hook))))
(dired-move-to-filename))
;; return nil if all went well
nil))
(if reason ; don't move away on failure
(goto-char opoint))
(not reason))) ; return t on success, nil else
;; Don't do it (dired-omit-mode).
;; Return t for success (perhaps we should return file-exists-p).
t))
(defun dired-after-subdir-garbage (dir) (defun dired-after-subdir-garbage (dir)
;; Return pos of first file line of DIR, skipping header and total ;; Return pos of first file line of DIR, skipping header and total
......
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
;; When loaded this code redefines the following functions of GNU Emacs: ;; When loaded this code redefines the following functions of GNU Emacs:
;; From dired.el: dired-clean-up-after-deletion, dired-find-buffer-nocreate, ;; From dired.el: dired-clean-up-after-deletion, dired-find-buffer-nocreate,
;; and dired-initial-position. ;; and dired-initial-position.
;; From dired-aux.el: dired-add-entry and dired-read-shell-command. ;; From dired-aux.el: dired-read-shell-command.
;; *Please* see the `dired-x' info pages for more details. ;; *Please* see the `dired-x' info pages for more details.
...@@ -589,45 +589,6 @@ Optional fourth argument LOCALP is as in `dired-get-filename'." ...@@ -589,45 +589,6 @@ Optional fourth argument LOCALP is as in `dired-get-filename'."
(and fn (string-match regexp fn)))) (and fn (string-match regexp fn))))
msg))) msg)))
;; Compiler does not get fset.
(declare-function dired-omit-old-add-entry "dired-x")
;; REDEFINE.
;; Redefine dired-aux.el's version of `dired-add-entry'
;; Save old defun if not already done:
(or (fboundp 'dired-omit-old-add-entry)
(fset 'dired-omit-old-add-entry (symbol-function 'dired-add-entry)))
;; REDEFINE.
(defun dired-omit-new-add-entry (filename &optional marker-char relative)
;; This redefines dired-aux.el's dired-add-entry to avoid calling ls for
;; files that are going to be omitted anyway.
(if dired-omit-mode
;; perhaps return t without calling ls
(let ((omit-re (dired-omit-regexp)))
(if (or (string= omit-re "")
(not
(string-match omit-re
(cond
((eq 'no-dir dired-omit-localp)
filename)
((eq t dired-omit-localp)
(dired-make-relative filename))
(t
(dired-make-absolute
filename
(file-name-directory filename)))))))
;; if it didn't match, go ahead and add the entry
(dired-omit-old-add-entry filename marker-char relative)
;; dired-add-entry returns t for success, perhaps we should
;; return file-exists-p
t))
;; omitting is not turned on at all
(dired-omit-old-add-entry filename marker-char relative)))
;; Redefine it.
(fset 'dired-add-entry 'dired-omit-new-add-entry)
;;; VIRTUAL DIRED MODE. ;;; VIRTUAL DIRED MODE.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment