- (let (opoint file-type executable symlink hidden case-fold-search used-F eol)
- ;; case-fold-search is nil now, so we can test for capital F:
- (setq used-F (string-match "F" dired-actual-switches)
- opoint (point)
- eol (save-excursion (end-of-line) (point))
- hidden (and selective-display
- (save-excursion (search-forward "\r" eol t))))
- (if hidden
- nil
- (save-excursion;; Find out what kind of file this is:
- ;; Restrict perm bits to be non-blank,
- ;; otherwise this matches one char to early (looking backward):
- ;; "l---------" (some systems make symlinks that way)
- ;; "----------" (plain file with zero perms)
- (if (re-search-backward
- dired-permission-flags-regexp nil t)
- (setq file-type (char-after (match-beginning 1))
- symlink (eq file-type ?l)
- ;; Only with -F we need to know whether it's an executable
- executable (and
- used-F
- (string-match
- "[xst]";; execute bit set anywhere?
- (concat
- (buffer-substring (match-beginning 2)
- (match-end 2))
- (buffer-substring (match-beginning 3)
- (match-end 3))
- (buffer-substring (match-beginning 4)
- (match-end 4))))))
- (or no-error (error "No file on this line"))))
- ;; Move point to end of name:
- (if symlink
- (if (search-forward " ->" eol t)
- (progn
- (forward-char -3)
- (and used-F
- dired-ls-F-marks-symlinks
- (eq (preceding-char) ?@);; did ls really mark the link?
- (forward-char -1))))
- (goto-char eol);; else not a symbolic link
- ;; ls -lF marks dirs, sockets and executables with exactly one
- ;; trailing character. (Executable bits on symlinks ain't mean
- ;; a thing, even to ls, but we know it's not a symlink.)
- (and used-F
- (or (memq file-type '(?d ?s))
- executable)
- (forward-char -1))))
- (or no-error
- (not (eq opoint (point)))
- (error (if hidden
- (substitute-command-keys
- "File line is hidden, type \\[dired-hide-subdir] to unhide")
- "No file on this line")))
- (if (eq opoint (point))
- nil
- (point))))
+ (if (get-text-property (point) 'dired-filename)
+ (goto-char (next-single-property-change (point) 'dired-filename))
+ (let (opoint file-type executable symlink hidden case-fold-search used-F eol)
+ ;; case-fold-search is nil now, so we can test for capital F:
+ (setq used-F (string-match "F" dired-actual-switches)
+ opoint (point)
+ eol (save-excursion (end-of-line) (point))
+ hidden (and selective-display
+ (save-excursion (search-forward "\r" eol t))))
+ (if hidden
+ nil
+ (save-excursion ;; Find out what kind of file this is:
+ ;; Restrict perm bits to be non-blank,
+ ;; otherwise this matches one char to early (looking backward):
+ ;; "l---------" (some systems make symlinks that way)
+ ;; "----------" (plain file with zero perms)
+ (if (re-search-backward
+ dired-permission-flags-regexp nil t)
+ (setq file-type (char-after (match-beginning 1))
+ symlink (eq file-type ?l)
+ ;; Only with -F we need to know whether it's an executable
+ executable (and
+ used-F
+ (string-match
+ "[xst]" ;; execute bit set anywhere?
+ (concat
+ (buffer-substring (match-beginning 2)
+ (match-end 2))
+ (buffer-substring (match-beginning 3)
+ (match-end 3))
+ (buffer-substring (match-beginning 4)
+ (match-end 4))))))
+ (or no-error (error "No file on this line"))))
+ ;; Move point to end of name:
+ (if symlink
+ (if (search-forward " ->" eol t)
+ (progn
+ (forward-char -3)
+ (and used-F
+ dired-ls-F-marks-symlinks
+ (eq (preceding-char) ?@) ;; did ls really mark the link?
+ (forward-char -1))))
+ (goto-char eol) ;; else not a symbolic link
+ ;; ls -lF marks dirs, sockets and executables with exactly one
+ ;; trailing character. (Executable bits on symlinks ain't mean
+ ;; a thing, even to ls, but we know it's not a symlink.)
+ (and used-F
+ (or (memq file-type '(?d ?s))
+ executable)
+ (forward-char -1))))
+ (or no-error
+ (not (eq opoint (point)))
+ (error (if hidden
+ (substitute-command-keys
+ "File line is hidden, type \\[dired-hide-subdir] to unhide")
+ "No file on this line")))
+ (if (eq opoint (point))
+ nil
+ (point)))))
+
+\f
+;;; COPY NAMES OF MARKED FILES INTO KILL-RING.
+
+(defun dired-copy-filename-as-kill (&optional arg)
+ "Copy names of marked (or next ARG) files into the kill ring.
+The names are separated by a space.
+With a zero prefix arg, use the complete pathname of each marked file.
+With \\[universal-argument], use the relative pathname of each marked file.
+
+If on a subdir headerline, use subdirname instead; prefix arg is ignored
+in this case.
+
+You can then feed the file name(s) to other commands with \\[yank]."
+ (interactive "P")
+ (let ((string
+ (or (dired-get-subdir)
+ (mapconcat (function identity)
+ (if arg
+ (cond ((zerop (prefix-numeric-value arg))
+ (dired-get-marked-files))
+ ((integerp arg)
+ (dired-get-marked-files 'no-dir arg))
+ (t ; else a raw arg
+ (dired-get-marked-files t)))
+ (dired-get-marked-files 'no-dir))
+ " "))))
+ (if (eq last-command 'kill-region)
+ (kill-append string nil)
+ (kill-new string))
+ (message "%s" string)))