Function: ibuffer-copy-filename-as-kill

ibuffer-copy-filename-as-kill is an autoloaded, interactive and byte-compiled function defined in ibuf-ext.el.gz.

Signature

(ibuffer-copy-filename-as-kill &optional ARG)

Documentation

Copy filenames of marked (or next ARG) buffers into the kill ring.

The names are separated by a space. If a buffer has no filename, it is ignored.

With no prefix arg, use the filename sans its directory of each marked file. With a zero prefix arg, use the complete filename of each marked file. With C-u (universal-argument), use the filename of each marked file relative to ibuffer-default-directory if non-nil, otherwise default-directory.

You can then feed the file name(s) to other commands with C-y (yank).

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/ibuf-ext.el.gz
;;;###autoload
(defun ibuffer-copy-filename-as-kill (&optional arg)
  "Copy filenames of marked (or next ARG) buffers into the kill ring.

The names are separated by a space.
If a buffer has no filename, it is ignored.

With no prefix arg, use the filename sans its directory of each marked file.
With a zero prefix arg, use the complete filename of each marked file.
With \\[universal-argument], use the filename of each marked file relative
to `ibuffer-default-directory' if non-nil, otherwise `default-directory'.

You can then feed the file name(s) to other commands with \\[yank]."
  (interactive "P")
  (let* ((buffers (cond ((and (integerp arg) (not (zerop arg)))
                         (ibuffer--near-buffers arg))
                        (t
                         (or (ibuffer-get-marked-buffers)
                             (list (ibuffer-current-buffer))))))
         (file-names
          (mapcar
           (lambda (buf)
             (let ((name (with-current-buffer buf
                           (ibuffer-buffer-file-name))))
               (if (null name)
                   ""
                 (cond ((and (integerp arg) (zerop arg)) name)
                       ((consp arg)
                        (file-relative-name
                         name (or ibuffer-default-directory
                                  default-directory)))
                       (t (file-name-nondirectory name))))))
           buffers))
         (string
          (mapconcat #'identity (delete "" file-names) " ")))
    (unless (string= string "")
      (if (eq last-command 'kill-region)
          (kill-append string nil)
        (kill-new string))
      (message "%s" string))))