From d52fb88582f431738994a3321614bd7ec76e7f56 Mon Sep 17 00:00:00 2001 From: Franck Cuny Date: Wed, 23 Mar 2022 19:43:46 -0700 Subject: this should be the last mass refactor --- emacs/elisp/my-buffers.el | 26 ++++++++++++++++++++++++++ emacs/elisp/my-clipboard.el | 24 ------------------------ emacs/elisp/my-git-extra.el | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 24 deletions(-) delete mode 100644 emacs/elisp/my-clipboard.el create mode 100644 emacs/elisp/my-git-extra.el (limited to 'emacs/elisp') diff --git a/emacs/elisp/my-buffers.el b/emacs/elisp/my-buffers.el index d5c07c5..8c03905 100644 --- a/emacs/elisp/my-buffers.el +++ b/emacs/elisp/my-buffers.el @@ -9,5 +9,31 @@ (mark-whole-buffer) (copy-region-as-kill 1 (buffer-size)))) +(defun my/rename-this-buffer-and-file () + "Renames current buffer and file it is visiting." + (interactive) + (let ((name (buffer-name)) + (filename (buffer-file-name)) + (read-file-name-function 'read-file-name-default)) + (if (not (and filename (file-exists-p filename))) + (error "Buffer '%s' is not visiting a file!" name) + (let ((new-name (read-file-name "New name: " filename))) + (cond ((get-buffer new-name) + (error "A buffer named '%s' already exists!" new-name)) + (t + (rename-file filename new-name 1) + (rename-buffer new-name) + (set-visited-file-name new-name) + (set-buffer-modified-p nil) + (message "File '%s' successfully renamed to '%s'" name (file-name-nondirectory new-name)))))))) + +(defun my/uniquify-region-lines (beg end) + "Remove duplicate adjacent lines in region between BEG and END." + (interactive "*r") + (save-excursion + (goto-char beg) + (while (re-search-forward "^\\(.*\n\\)\\1+" end t) + (replace-match "\\1")))) + (provide 'my-buffers) ;;; my-buffers.el ends here diff --git a/emacs/elisp/my-clipboard.el b/emacs/elisp/my-clipboard.el deleted file mode 100644 index f0f3c01..0000000 --- a/emacs/elisp/my-clipboard.el +++ /dev/null @@ -1,24 +0,0 @@ -;;; my-clipboard.el --- Functions related to clipboard -;;; Commentary: -;;; Code: - -;; https://github.com/chongchonghe/emacs-dotfile/blob/f4f9ce5f586f224e2c83b118d471652d65d38e8c/packages/simpleclip.el -(defun my/clipboard-get-contents () - "Return the contents of the system clipboard as a string." - (condition-case nil - (cond - ((fboundp 'ns-get-pasteboard) - (ns-get-pasteboard)) - ((and (featurep 'mac) - (fboundp 'gui-get-selection)) - (gui-get-selection 'CLIPBOARD 'NSStringPboardType)) - ((and (featurep 'mac) - (fboundp 'x-get-selection)) - (x-get-selection 'CLIPBOARD 'NSStringPboardType)) - ((fboundp 'gui-get-selection) - (gui-get-selection 'CLIPBOARD (or x-select-request-type 'UTF8_STRING))) - (t - (error "Clipboard support not available"))))) - -(provide 'my-clipboard) -;;; my-clipboard.el ends here diff --git a/emacs/elisp/my-git-extra.el b/emacs/elisp/my-git-extra.el new file mode 100644 index 0000000..862286a --- /dev/null +++ b/emacs/elisp/my-git-extra.el @@ -0,0 +1,42 @@ +;;; my-git-extra.el --- Extra functions to work with gitattributes +;;; Commentary: +;;; Code: + +(require 'magit) +(require 'git-link) + +(defun my/clone-repo (url) + "Clone a repository in the workspace using URL." + (interactive "sURL:") + (let* ((repo-name (magit-clone--url-to-name url)) + (target-dir (concat "~/workspace/" repo-name))) + (magit-clone-regular url target-dir nil))) + +(defun my/get-sg-remote-from-hostname (hostname) + "Create a sourcegraph URL from HOSTNAME." + (format "sourcegraph.rbx.com/%s" hostname)) + +(defun my/git-link-work-sourcegraph (hostname dirname filename _branch commit start end) + "Create a link to sourcegraph given a HOSTNAME DIRNAME FILENAME _BRANCH COMMIT START and END." + ;; Use the default branch of the repository instead of the + ;; current one (we might be on a feature branch that is not + ;; available on the remote). + (let ((sg-base-url (my/get-sg-remote-from-hostname hostname)) + (main-branch (magit-main-branch))) + (git-link-sourcegraph sg-base-url dirname filename main-branch commit start end))) + +(defun my/git-link-commit-work-sourcegraph (hostname dirname commit) + "Create the link to sourcegraph given a HOSTNAME DIRNAME and COMMIT." + (let ((sg-base-url (my/get-sg-remote-from-hostname hostname))) + (git-link-commit-sourcegraph sg-base-url dirname commit))) + +;; for work related repositories, open them in our instance of sourcegraph +(add-to-list 'git-link-remote-alist '("github\\.rbx\\.com" my/git-link-work-sourcegraph)) +(add-to-list 'git-link-commit-remote-alist '("github\\.rbx\\.com" my/git-link-commit-work-sourcegraph)) + +;; for personal code I use gitea, which is similar to codeberg +(add-to-list 'git-link-remote-alist '("git\\.my\\.net" git-link-codeberg)) +(add-to-list 'git-link-commit-remote-alist '("git\\.my\\.net" git-link-commit-codeberg)) + +(provide 'my-git-extra) +;;; my-git-extra.el ends here -- cgit 1.4.1