Create command to copy the buffer's file name #24

Open
opened 2026-03-26 13:20:51 -07:00 by wmedrano · 2 comments
Owner
No description provided.
Author
Owner

There seems to be an implementation that doesn't play well with the ~. Fix:

  •     (root (and project (project-root project)))
    
  •     (root (expand-file-name (and project (project-root project))))
    
There seems to be an implementation that doesn't play well with the `~`. Fix: - (root (and project (project-root project))) + (root (expand-file-name (and project (project-root project))))
Author
Owner

Full implementation

(defun copy-filename ()
  "Copy the current file name to `kill-new'.
If `project-current' returns a project, make the path relative to
the project root."
  (interactive)
  (let* ((file (buffer-file-name))
         (project (and (fboundp 'project-current)
                       (project-current)))
         (root (expand-file-name (and project (project-root project))))
         (name (if (and root (string-prefix-p root file))
                   (file-relative-name file root)
                 file)))
    (unless file
      (user-error "No file name for current buffer"))
    (kill-new name)
    (message "Copied: %s" name)))
Full implementation ```lisp (defun copy-filename () "Copy the current file name to `kill-new'. If `project-current' returns a project, make the path relative to the project root." (interactive) (let* ((file (buffer-file-name)) (project (and (fboundp 'project-current) (project-current))) (root (expand-file-name (and project (project-root project)))) (name (if (and root (string-prefix-p root file)) (file-relative-name file root) file))) (unless file (user-error "No file name for current buffer")) (kill-new name) (message "Copied: %s" name))) ```
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
wmedrano/emacs-config#24
No description provided.