From 2f1d2fb9b87fb9ee334b646ac84468c5245eecf9 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Sat, 24 Jun 2023 17:30:01 +1000 Subject: copy buffer file name --- emacs/.emacs.d/lisp/my/my-editing.el | 13 +++++++++++++ emacs/.emacs.d/lisp/my/my-prog.el | 2 ++ 2 files changed, 15 insertions(+) (limited to 'emacs/.emacs.d/lisp/my') diff --git a/emacs/.emacs.d/lisp/my/my-editing.el b/emacs/.emacs.d/lisp/my/my-editing.el index a8fe822..47e33a3 100644 --- a/emacs/.emacs.d/lisp/my/my-editing.el +++ b/emacs/.emacs.d/lisp/my/my-editing.el @@ -372,5 +372,18 @@ Basically move the line up (setq beg (point))) (kill-region beg (point))))) +(defun my-copy-buffer-file-name (&optional relative) + "Copy the file name of the current buffer. + +With an prefix-arg, copy the file name relative to project root." + (interactive "P") + (let ((to-kill + (if (and relative (project-current)) + (file-relative-name (buffer-file-name) + (project-root (project-current))) + (buffer-file-name)))) + (kill-new to-kill) + (message "Copied %s" to-kill))) + (provide 'my-editing) ;;; my-editing.el ends here diff --git a/emacs/.emacs.d/lisp/my/my-prog.el b/emacs/.emacs.d/lisp/my/my-prog.el index e38a866..4794ff2 100644 --- a/emacs/.emacs.d/lisp/my/my-prog.el +++ b/emacs/.emacs.d/lisp/my/my-prog.el @@ -332,6 +332,8 @@ left and the source buffer on the right. (defun my-gud-comint-set-prompt-regexp () (setq comint-prompt-regexp "\\((rr)|(gdb)\\) ")) +;; TODO: generalise the following to common forges, including +;; savannah, cgit, gitlab etc. (defun my-file-loc-to-github (file-loc &optional revision) "Convert a file location to a github url." (pcase-let* ((`(,file ,line-no) (split-string file-loc ":")) -- cgit v1.2.3