Function: dired-get-filename
dired-get-filename is a byte-compiled function defined in dired.el.gz.
Signature
(dired-get-filename &optional LOCALP NO-ERROR-IF-NOT-FILEP)
Documentation
In Dired, return name of file mentioned on this line.
Value returned normally includes the directory name.
Optional arg LOCALP with value no-dir means don't include directory
name in result. A value of verbatim means to return the name exactly as
it occurs in the buffer, and a value of t means construct name relative to
default-directory, which still may contain slashes if in a subdirectory.
Optional arg NO-ERROR-IF-NOT-FILEP means treat . and .. as
regular filenames and return nil if no filename on this line.
Otherwise, an error occurs in these cases.
Source Code
;; Defined in /usr/src/emacs/lisp/dired.el.gz
(defun dired-get-filename (&optional localp no-error-if-not-filep)
"In Dired, return name of file mentioned on this line.
Value returned normally includes the directory name.
Optional arg LOCALP with value `no-dir' means don't include directory
name in result. A value of `verbatim' means to return the name exactly as
it occurs in the buffer, and a value of t means construct name relative to
`default-directory', which still may contain slashes if in a subdirectory.
Optional arg NO-ERROR-IF-NOT-FILEP means treat `.' and `..' as
regular filenames and return nil if no filename on this line.
Otherwise, an error occurs in these cases."
(let ((hidden (and dired-subdir-alist
(dired-subdir-hidden-p
(dired-current-directory))))
case-fold-search file p1 p2 already-absolute)
(when hidden
(dired-unhide-subdir))
(save-excursion
(if (setq p1 (dired-move-to-filename (not no-error-if-not-filep)))
(setq p2 (dired-move-to-end-of-filename no-error-if-not-filep))))
(when hidden
(dired-hide-subdir 1))
;; nil if no file on this line, but no-error-if-not-filep is t:
(if (setq file (and p1 p2 (buffer-substring p1 p2)))
(progn
;; Get rid of the mouse-face property that file names have.
(set-text-properties 0 (length file) nil file)
;; Unquote names quoted by ls or by dired-insert-directory.
;; This code was written using `read' to unquote, because
;; it's faster than substituting \007 (4 chars) -> ^G (1
;; char) etc. in a lisp loop. Unfortunately, this decision
;; has necessitated hacks such as dealing with filenames
;; with quotation marks in their names.
(while (string-match "\\(?:[^\\]\\|\\`\\)\\(\"\\)" file)
(setq file (replace-match "\\\"" nil t file 1)))
;; Unescape any spaces escaped by ls -b (bug#10469).
;; Other -b quotes, eg \t, \n, work transparently.
(if (dired-switches-escape-p dired-actual-switches)
(let ((start 0)
(rep "")
(shift -1))
(if (eq localp 'verbatim)
(setq rep "\\\\"
shift +1))
(while (string-match "\\(\\\\\\) " file start)
(setq file (replace-match rep nil t file 1)
start (+ shift (match-end 0))))))
(when (eq system-type 'windows-nt)
(save-match-data
(let ((start 0))
(while (string-match "\\\\" file start)
(aset file (match-beginning 0) ?/)
(setq start (match-end 0))))))
;; Hence we don't need to worry about converting `\\' back to `\'.
(setq file (read (concat "\"" file "\"")))))
(and file (files--name-absolute-system-p file)
(setq already-absolute t))
(cond
((null file)
nil)
((eq localp 'verbatim)
file)
((and (not no-error-if-not-filep)
(member file '("." "..")))
(error "Cannot operate on `.' or `..'"))
((and (eq localp 'no-dir) already-absolute)
(file-name-nondirectory file))
(already-absolute
(let ((handler (find-file-name-handler file nil)))
;; check for safe-magic property so that we won't
;; put /: for names that don't really need them.
;; For instance, .gz files when auto-compression-mode is on.
(if (and handler (not (get handler 'safe-magic)))
(concat "/:" file)
file)))
((eq localp 'no-dir)
file)
((equal (dired-current-directory) "/")
(setq file (concat (dired-current-directory localp) file))
(let ((handler (find-file-name-handler file nil)))
;; check for safe-magic property so that we won't
;; put /: for names that don't really need them.
;; For instance, .gz files when auto-compression-mode is on.
(if (and handler (not (get handler 'safe-magic)))
(concat "/:" file)
file)))
(t
(concat (dired-current-directory localp) file)))))