How can I write a function or keybind in emacs which simply runs the function below to…
- User
How can I write a function or keybind in emacs which simply runs the function below to get the full file path?
(defun easy-kill-on-buffer-file-name (n) "Get
buffer-file-name' ordefault-directory'. If N is zero, remove the directory part; -, remove the file name part; +, full path." (if (easy-kill-get mark) (easy-kill-echo "Not supported ineasy-mark'") (pcase (or buffer-file-name default-directory) (nil (easy-kill-echo "Nobuffer-file-name'")) (file (let* ((file (directory-file-name file)) (text (pcase n (- (file-name-directory file)) (`0 (file-name-nondirectory file)) (_ file)))) (easy-kill-adjust-candidate 'buffer-file-name text)))))) Assistant
You're looking to create a function (and possibly a keybinding) in Emacs that uses or wraps the existing
easy-kill-on-buffer-file-namefunction — specifically, to get and copy the full file path of the current buffer.From your code:
- The function
easy-kill-on-buffer-file-nametakes one argumentn, which controls what part of the file path is returned:0: just the filename-: just the directory- anything else (e.g.
+or default): full path
So, to copy the full file path, you want to call this function with an argument that causes it to return the full path — i.e., not
0or-. Looking at the function definition, any value other than0or-will do that. A common convention is to use+or1.
✅ Step 1: Create a wrapper function
We can define a simple wrapper that calls
easy-kill-on-buffer-file-namewith+as the argument (or any non-zero, non-minus symbol):(defun my/copy-full-file-path () "Copy the full file path of the current buffer using `easy-kill-on-buffer-file-name'." (interactive) (easy-kill-on-buffer-file-name '+))This uses
'+'as the argument to trigger the full path behavior.
✅ Step 2: Bind it to a key (optional)
Now, if you'd like to bind it to a convenient key combination, for example
C-c C-f, you could add:(global-set-key (kbd "C-c C-f") #'my/copy-full-file-path)Or bind it locally in some major modes only, depending on your preference.
📝 Notes
- This assumes
easy-kill-on-buffer-file-nameis already defined and available in your environment (e.g., from theeasy-killpackage). - You can install
easy-killviaM-x package-install RET easy-kill RETif needed. - The copied text will be added to the kill ring, so you can paste it with
C-y.
✅ Summary
Add the following to your Emacs config:
(defun my/copy-full-file-path () "Copy the full file path of the current buffer." (interactive) (easy-kill-on-buffer-file-name '+)) (global-set-key (kbd "C-c C-f") #'my/copy-full-file-path)Now pressing
C-c C-fwill copy the full path of the current buffer’s file.- The function
- User
Wrong type argument: overlayp, nil
Assistant
The error:
Wrong type argument: overlayp, nilmeans that somewhere in the code, Emacs expected an overlay, but instead got
nil.This typically happens if a function tries to manipulate an overlay (e.g., delete or modify it), but the overlay doesn't exist or was already deleted.
🔍 Root Cause
Looking at your original function
easy-kill-on-buffer-file-name, and the error you're seeing, this likely comes from the call to:(easy-kill-echo "Not supported in `easy-mark'")or another part of the
easy-killpackage that assumes some internal state (like overlays) exists when they actually don't.In particular,
easy-kill-echomight be trying to interact with an overlay that hasn't been created yet — hence thenilwhere an overlay is expected.
✅ Solution: Wrap Safely
To avoid this error, we should create a new, standalone function that simply copies the file path without relying on any internal
easy-killlogic that may assume overlays or other state.Here’s a safer version that does exactly what you want — copies the full file path to the kill ring:
✅ Recommended Function (Safe & Reliable)
(defun my/copy-full-file-path () "Copy the full file path of the current buffer to the kill ring." (interactive) (let ((file-path (or buffer-file-name default-directory))) (if file-path (progn (kill-new file-path) (message "Copied: %s" file-path)) (user-error "No file associated with this buffer"))))
📝 Explanation
(or buffer-file-name default-directory)gets the file path.- If there's no file associated (
file-pathisnil), it shows an error message. - Otherwise, it adds the path to the kill ring using
kill-new. - It also displays a confirmation in the echo area.
✅ Optional Keybinding
Add this to bind to
C-c C-f:(global-set-key (kbd "C-c C-f") #'my/copy-full-file-path)
✅ Summary
Use this clean and safe function instead of wrapping
easy-kill-on-buffer-file-name. It avoids theoverlayperror entirely and does exactly what you need: copy the full file path.Let me know if you'd like variations (e.g., copy only filename, directory, etc.)!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.