Function: dired-move-to-end-of-filename

dired-move-to-end-of-filename is a byte-compiled function defined in dired.el.gz.

Signature

(dired-move-to-end-of-filename &optional NO-ERROR)

Source Code

;; Defined in /usr/src/emacs/lisp/dired.el.gz
(defun dired-move-to-end-of-filename (&optional no-error)
  ;; Assumes point is at beginning of filename,
  ;; thus the rwx bit re-search-backward below will succeed in *this*
  ;; line if at all.  So, it should be called only after
  ;; (dired-move-to-filename t).
  ;; On failure, signals an error (with non-nil NO-ERROR just returns nil).
  ;; This is the UNIX version.
  (if (get-text-property (point) 'dired-filename)
      (goto-char (or (next-single-property-change (point) 'dired-filename)
                     ;; No property change can happen on or before the
                     ;; last file name in the Dired listing when there
                     ;; is at least one prior file name containing a
                     ;; newline.  To prevent an error in this case we
                     ;; take the position just before the final newline
                     ;; as the end of the last file name (bug#79528).
                     (1- (point-max))))
    (let ((opoint (point))
          (used-F (dired-check-switches dired-actual-switches "F" "classify"))
          (eol (line-end-position))
          (hidden (dired--hidden-p))
          file-type executable symlink)
      (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
				  (match-string 2)
				  (match-string 3)
				  (match-string 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 -4)
		  (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, fifos 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 ?p))
		   executable)
	       (forward-char -1))))
      (or no-error
	  (not (eq opoint (point)))
	  (error "%s" (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)))))