2

いくつかのファイル (構成ファイルなど) の複製を作成したい場合があります。最初は初期ファイルと同じ内容である必要があります。したがって、いくつかのファイルを dired でマークして「複製」できるようにしたいと思います。この複製手順は、元のディレクトリに貼り付けるときに、ほとんどのファイル マネージャーで使用される複製手順と同様に機能します。 (コピー)」を追加します (ファイル拡張子の直前)。

これを行う組み込みの dired 関数が見つからないようです。誰かが助けてくれるか、このような関数を既に作成していますか?

助けていただければ幸いです。

4

3 に答える 3

3

必要に応じて、関数の名前を変更したり (より適切な名前を思いつきませんでした)、より複雑な書式設定をしたりすることもあるでしょう...

(defcustom dired-keep-marker-version ?V
  "Controls marking of versioned files.
If t, versioned files are marked if and as the corresponding original files were.
If a character, copied files are unconditionally marked with that character."
  :type '(choice (const :tag "Keep" t)
         (character :tag "Mark"))
  :group 'dired-mark)

(defun dired-version-file (from to ok-flag)
  (dired-handle-overwrite to)
  (dired-copy-file-recursive from to ok-flag dired-copy-preserve-time t
                 dired-recursive-copies))

(defun dired-do-version (&optional arg)
  "Search for numeric pattern in file name and create a version of that file
with that number incremented by one, or, in case such file already exists,
will search for a file with the similar name, incrementing the counter each
time by one.
Additionally, if called with prefix argument, will prompt for number format.
The formatting is the same as is used with `format' function."
  (interactive "P")
  (let ((fn-list (dired-get-marked-files nil nil)))
    (dired-create-files
     (function dired-version-file) "Version" fn-list
     (function
      (lambda (from)
        (let (new-name (i 0) (fmt (if arg (read-string "Version format: " "%d") "%d")))
          (while (or (null new-name) (file-exists-p new-name))
            (setq new-name
                  (if (string-match  "^\\([^0-9]*\\)\\([0-9]+\\)\\(.*\\)$" from)
                      (concat (match-string 1 from)
                              (format fmt
                                      (+ (string-to-number (match-string 2 from)) (1+ i)))
                              (match-string 3 from))
                    (concat from (format (concat "." fmt) i)))
                  i (1+ i))) new-name)))
     dired-keep-marker-version)))

(define-key dired-mode-map (kbd "c") 'dired-do-version)

また、私は を使用vしないため、もともとこの関数をバインドするために使用していましたが、 s フックdired-view内でバインドする必要があります。just が最初の未定義キーだったので、それを使用しました。diredc

于 2013-07-02T21:06:32.283 に答える