diff options
author | Yuchen Pei <id@ypei.org> | 2023-06-24 17:30:01 +1000 |
---|---|---|
committer | Yuchen Pei <id@ypei.org> | 2023-06-24 17:30:01 +1000 |
commit | 2f1d2fb9b87fb9ee334b646ac84468c5245eecf9 (patch) | |
tree | cd839c828ee15faec2b61d6839318637184ed373 /emacs | |
parent | ba77033a0c81952f5b9b8e140a17c4d12f4e9d05 (diff) |
copy buffer file name
Diffstat (limited to 'emacs')
-rw-r--r-- | emacs/.emacs.d/init/ycp-editing.el | 1 | ||||
-rw-r--r-- | emacs/.emacs.d/lisp/my/my-editing.el | 13 | ||||
-rw-r--r-- | emacs/.emacs.d/lisp/my/my-prog.el | 2 |
3 files changed, 16 insertions, 0 deletions
diff --git a/emacs/.emacs.d/init/ycp-editing.el b/emacs/.emacs.d/init/ycp-editing.el index b9ed48b..4b6922e 100644 --- a/emacs/.emacs.d/init/ycp-editing.el +++ b/emacs/.emacs.d/init/ycp-editing.el @@ -60,6 +60,7 @@ "C-c r <RET>" #'my-concat-lines "C-M-y" #'my-yank-primary "C-a" #'my-beginning-of-line-or-indentation + "M-c" #'my-copy-buffer-file-name ; override capitalize ) (electric-pair-mode) ) 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 ":")) |