Function: vc-dir-mark-file

vc-dir-mark-file is a byte-compiled function defined in vc-dir.el.gz.

Signature

(vc-dir-mark-file &optional ARG)

Source Code

;; Defined in /usr/src/emacs/lisp/vc/vc-dir.el.gz
(defun vc-dir-mark-file (&optional arg)
  ;; Mark ARG or the current file and move to the next line.
  (let* ((crt (or arg (ewoc-locate vc-ewoc)))
         (file (ewoc-data crt))
         (to-inval (list crt)))
    ;; We do not allow a state in which a directory is marked and also
    ;; some of its files are marked.  If the user's intent is apparent,
    ;; offer to adjust things for them so that they can proceed.
    (if-let* ((_ (vc-dir-fileinfo->directory file))
              (children (vc-dir--children crt t))
              (name (vc-dir-fileinfo->name file)))
        ;; The user wants to mark a directory where some of its children
        ;; are already marked.  Although the user's intent is clear, by
        ;; default we still ask them before unmarking in order to avoid
        ;; accidental erasure of complex patterns of marks.
        (progn (when (or (not vc-dir-allow-mass-mark-changes)
                         (and (eq vc-dir-allow-mass-mark-changes 'ask)
                              (not (y-or-n-p
                                    (format "\
Replace marks on subitems with marking `%s' itself?"
                                            name)))))
                 (user-error "`%s' is already marked" name))
               (dolist (child children)
                 (setf (vc-dir-fileinfo->marked (ewoc-data child)) nil)
                 (push child to-inval)))
      (when-let* ((parent (vc-dir--parent crt t))
                  (name (vc-dir-fileinfo->name (ewoc-data parent))))
        ;; The user seems to want to mark an entry whose directory is
        ;; already marked.  As the file is already implicitly marked for
        ;; most VCS, they may not really intend this.
        (when (or (not vc-dir-allow-mass-mark-changes)
                  (and (eq vc-dir-allow-mass-mark-changes 'ask)
                       (not (y-or-n-p
                             (format "`%s' is already marked; unmark it?"
                                     name)))))
          (user-error "`%s' is already marked" name))
        (setf (vc-dir-fileinfo->marked (ewoc-data parent)) nil)
        (push parent to-inval)))
    (setf (vc-dir-fileinfo->marked file) t)
    (apply #'ewoc-invalidate vc-ewoc to-inval)
    (unless (or arg (mouse-event-p last-command-event))
      (vc-dir-next-line 1))))