[Emacs] Make hydra-yank work with non-file buffers

Add imalison:buffer-file-name-or-directory helper that falls back to
default-directory when buffer-file-name is nil. This allows the yank
hydra to work with magit buffers and other buffers associated with a
directory but not visiting a file.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-22 00:45:30 -08:00
parent 91e36cd0ba
commit 205d9528b3

View File

@@ -776,8 +776,14 @@ A macro for composing functions together to build an interactive command to copy
#+END_SRC
*** Copy portions of the buffer file name
#+BEGIN_SRC emacs-lisp
(defun imalison:buffer-file-name-or-directory ()
"Return `buffer-file-name' if available, otherwise `default-directory'.
This allows copy functions to work with buffers like magit that
aren't visiting a file but are associated with a directory."
(or buffer-file-name default-directory))
(defmacro imalison:copy-buffer-file-path-builder (&rest args)
`(imalison:compose-copy-builder ,@args buffer-file-name))
`(imalison:compose-copy-builder ,@args imalison:buffer-file-name-or-directory))
(imalison:copy-buffer-file-path-builder imalison:copy-buffer-file-path-full)
(imalison:copy-buffer-file-path-builder imalison:copy-buffer-file-name