summary refs log tree commit diff
path: root/emacs/elisp
diff options
context:
space:
mode:
authorFranck Cuny <franck@fcuny.net>2022-03-23 19:43:46 -0700
committerFranck Cuny <franck@fcuny.net>2022-03-23 19:43:46 -0700
commitd52fb88582f431738994a3321614bd7ec76e7f56 (patch)
treeca3dfc64107cb9e06e47c4edcd69f4d79a63bde3 /emacs/elisp
parentfunctions: move custom functions to libraries (diff)
downloademacs.d-d52fb88582f431738994a3321614bd7ec76e7f56.tar.gz
this should be the last mass refactor
Diffstat (limited to '')
-rw-r--r--emacs/elisp/my-buffers.el26
-rw-r--r--emacs/elisp/my-clipboard.el24
-rw-r--r--emacs/elisp/my-git-extra.el42
3 files changed, 68 insertions, 24 deletions
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