diff options
-rw-r--r-- | emacs/.emacs.d/init/ycp-org.el | 2 | ||||
-rw-r--r-- | emacs/.emacs.d/lisp/my/my-buffer.el | 5 | ||||
-rw-r--r-- | emacs/.emacs.d/lisp/my/my-github.el | 67 | ||||
-rw-r--r-- | emacs/.emacs.d/lisp/my/my-prog.el | 56 |
4 files changed, 71 insertions, 59 deletions
diff --git a/emacs/.emacs.d/init/ycp-org.el b/emacs/.emacs.d/init/ycp-org.el index f13fb0f..e57466a 100644 --- a/emacs/.emacs.d/init/ycp-org.el +++ b/emacs/.emacs.d/init/ycp-org.el @@ -60,6 +60,8 @@ (add-hook 'org-mode-hook (lambda () (electric-indent-local-mode -1))) (add-hook 'org-mode-hook (lambda () (setq-local tab-width 2))) + ;; The world does not end by 2038 (hopefully) + (setq org-read-date-force-compatible-dates nil) (setq org-adapt-indentation 'headline-data) (setq org-special-ctrl-a/e t) (setq org-special-ctrl-k t) diff --git a/emacs/.emacs.d/lisp/my/my-buffer.el b/emacs/.emacs.d/lisp/my/my-buffer.el index 98fd548..11d869d 100644 --- a/emacs/.emacs.d/lisp/my/my-buffer.el +++ b/emacs/.emacs.d/lisp/my/my-buffer.el @@ -111,9 +111,8 @@ With two prefixes: create a buffer of the chosen major mode." ;; we would like to include all modes (provided-mode-derived-p sym - 'text-mode 'prog-mode - 'comint-mode 'special-mode - 'diff-mode)) + 'text-mode 'prog-mode 'comint-mode 'special-mode + 'diff-mode 'conf-mode)) collect sym)))) (defun my-buffer-create-major-mode (mode) diff --git a/emacs/.emacs.d/lisp/my/my-github.el b/emacs/.emacs.d/lisp/my/my-github.el index 7dc2248..2fe90fd 100644 --- a/emacs/.emacs.d/lisp/my/my-github.el +++ b/emacs/.emacs.d/lisp/my/my-github.el @@ -64,5 +64,72 @@ License; name; description; homepage; created at" (my-delete-http-header) (alist-get 'name (json-read)))) +;;; urls with github +;; TODO: generalise the following to common forges, including +;; savannah, cgit, gitlab etc. +(defun my-github-revision-url (file revision) + "Returns the github url of the upstream repo containing FILE at REVISION." + (let ((repo-url (vc-git-repository-url file)) + (revision (or revision (vc-working-revision default-directory)))) + (format "%s/commit/%s" repo-url revision))) + +(defun my-github-kill-revision-url (revision) + "Kill the github revision url for REVISION." + (kill-new (my-github-revision-url revision))) + +(defun my-github-file-loc-url (file-loc &optional revision) + "Convert a file location to a github url." + (pcase-let* ((`(,file ,line-no) (split-string file-loc ":")) + (revision (or revision (vc-working-revision file)))) + (my-github-file-loc-url-internal file line-no revision))) + +(defun my-github-file-loc-url-internal (file line-no revision) + "Convert a FILE location at LINE-NO to a github url. + +REVISION is the commit hash." + (let* ((repo-url (vc-git-repository-url file)) + (repo-root (vc-git-root file)) + (path (file-relative-name file repo-root))) + (format "%s/blob/%s/%s#L%s" repo-url revision path line-no))) + +(defun my-github-kill-current-file-loc-url () + "Kill the github url from where the point is at." + (interactive) + (kill-new (my-github-file-loc-url-internal + (buffer-file-name) + (1+ (current-line)) + (vc-working-revision (buffer-file-name))))) + +(defun my-org-backtrace-to-github (bt &optional revision) + (string-join + (mapcar + (lambda (link) + (string-match "\\[\\[\\(.*\\)\\]\\[\\(.*\\)\\]\\]" link) + (let ((target (match-string 1 link)) + (label (match-string 2 link))) + (format "[[%s][%s]]" + (my-github-file-loc-url target revision) + label))) + (split-string bt " > ")) + " > ")) + +(defun my-org-backtrace-to-github-region (beg end) + (interactive "r") + (kill-new + (my-org-backtrace-to-github (buffer-substring-no-properties beg end)))) + +(defun my-org-backtrace-to-github-slack (beg end) + (interactive "r") + (let ((bt (buffer-substring-no-properties beg end)) + (revision (when current-prefix-arg + (read-string "Rrevision: "))) + ) + (with-temp-buffer + (insert "#+options: ^:nil +") + (goto-char (point-max)) + (insert (my-org-backtrace-to-github bt revision)) + (org-md-export-as-markdown)))) + (provide 'my-github) ;;; my-github.el ends here diff --git a/emacs/.emacs.d/lisp/my/my-prog.el b/emacs/.emacs.d/lisp/my/my-prog.el index e84478d..6309f70 100644 --- a/emacs/.emacs.d/lisp/my/my-prog.el +++ b/emacs/.emacs.d/lisp/my/my-prog.el @@ -309,62 +309,6 @@ 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 ":")) - (revision (or revision (vc-working-revision file)))) - (my-file-loc-to-github-internal file line-no revision))) - -(defun my-file-loc-to-github-internal (file line-no revision) - "Convert a FILE location at LINE-NO to a github url. - -REVISION is the commit hash." - (let* ((repo-url (vc-git-repository-url file)) - (repo-root (vc-git-root file)) - (path (file-relative-name file repo-root))) - (format "%s/blob/%s/%s#L%s" repo-url revision path line-no))) - -(defun my-kill-github-url-current-file-loc () - "Kill the github url from where the point is at." - (interactive) - (kill-new (my-file-loc-to-github-internal - (buffer-file-name) - (1+ (current-line)) - (vc-working-revision (buffer-file-name))))) - -(defun my-org-backtrace-to-github (bt &optional revision) - (string-join - (mapcar - (lambda (link) - (string-match "\\[\\[\\(.*\\)\\]\\[\\(.*\\)\\]\\]" link) - (let ((target (match-string 1 link)) - (label (match-string 2 link))) - (format "[[%s][%s]]" - (my-file-loc-to-github target revision) - label))) - (split-string bt " > ")) - " > ")) - -(defun my-org-backtrace-to-github-region (beg end) - (interactive "r") - (kill-new - (my-org-backtrace-to-github (buffer-substring-no-properties beg end)))) - -(defun my-org-backtrace-to-github-slack (beg end) - (interactive "r") - (let ((bt (buffer-substring-no-properties beg end)) - (revision (when current-prefix-arg - (read-string "Rrevision: "))) - ) - (with-temp-buffer - (insert "#+options: ^:nil -") - (goto-char (point-max)) - (insert (my-org-backtrace-to-github bt revision)) - (org-md-export-as-markdown)))) - ;;; which-func (defun my-copy-which-func () (interactive) |