Bind SPC f Y to yank path relative to project

Also, both commands now announce "Copied path to clipboard: ..." to make
it clear it worked (and what is being copied).
This commit is contained in:
Henrik Lissner 2021-02-15 14:54:13 -05:00
parent 5e8a668311
commit be9b3ff352
2 changed files with 16 additions and 4 deletions

View file

@ -32,13 +32,24 @@
((error "No kill-ring search backend available. Enable ivy or helm!")))))
;;;###autoload
(defun +default/yank-buffer-filename ()
(defun +default/yank-buffer-path (&optional root)
"Copy the current buffer's path to the kill ring."
(interactive)
(if-let (filename (or buffer-file-name (bound-and-true-p list-buffers-directory)))
(message (kill-new (abbreviate-file-name filename)))
(if-let (filename (or (buffer-file-name (buffer-base-buffer))
(bound-and-true-p list-buffers-directory)))
(message "Copied path to clipboard: %s"
(kill-new (abbreviate-file-name
(if root
(file-relative-name filename root)
filename))))
(error "Couldn't find filename in current buffer")))
;;;###autoload
(defun +default/yank-buffer-path-relative-to-project ()
"Copy the current buffer's path to the kill ring."
(interactive)
(+default/yank-buffer-path (doom-project-root)))
;;;###autoload
(defun +default/insert-file-path (arg)
"Insert the file name (absolute path if prefix ARG).