aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--emacs/.emacs.d/init/ycp-complete.el4
m---------emacs/.emacs.d/lisp/hmm.el0
-rw-r--r--emacs/.emacs.d/lisp/my/my-cgit.el148
-rw-r--r--emacs/.emacs.d/lisp/my/my-github.el112
4 files changed, 261 insertions, 3 deletions
diff --git a/emacs/.emacs.d/init/ycp-complete.el b/emacs/.emacs.d/init/ycp-complete.el
index dec3ae3..1c9e7ef 100644
--- a/emacs/.emacs.d/init/ycp-complete.el
+++ b/emacs/.emacs.d/init/ycp-complete.el
@@ -272,7 +272,8 @@
(my-package hmm
(:delay 60)
- (my-setq-from-local hmm-web-search-engines)
+ (my-read-local-config)
+ (my-setq-from-local hmm-web-search-engines hmm-transformers hmm-handlers)
(require 'my-net)
(setq hmm-web-browsers
'((:name eww :command eww)
@@ -283,7 +284,6 @@
(:name mullvad-browser :command my-browse-url-mullvad)
(:name qutebrowser :command my-browse-url-qutebrowser)
(:name download-and-open :command my-fetch-url)))
- (my-setq-from-local hmm-handlers)
(setq hmm-external-handlers
'((:name mpv
:external-command "mpv %U"
diff --git a/emacs/.emacs.d/lisp/hmm.el b/emacs/.emacs.d/lisp/hmm.el
-Subproject 1482f0e55fafa2b2a1694adbe016eb483952532
+Subproject 2157ead39273691013c38529b14953ea839c2a5
diff --git a/emacs/.emacs.d/lisp/my/my-cgit.el b/emacs/.emacs.d/lisp/my/my-cgit.el
new file mode 100644
index 0000000..de80f20
--- /dev/null
+++ b/emacs/.emacs.d/lisp/my/my-cgit.el
@@ -0,0 +1,148 @@
+;;; my-cgit.el -- cgit helper functions -*- lexical-binding: t -*-
+
+;; Copyright (C) 2023 Free Software Foundation.
+
+;; Author: Yuchen Pei <id@ypei.org>
+;; Package-Requires: ((emacs "28.2"))
+
+;; This file is part of dotted.
+
+;; dotted is free software: you can redistribute it and/or modify it under
+;; the terms of the GNU Affero General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; dotted is distributed in the hope that it will be useful, but WITHOUT
+;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General
+;; Public License for more details.
+
+;; You should have received a copy of the GNU Affero General Public
+;; License along with dotted. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; cgit helper functions.
+
+;;; Code:
+(require 'vc-git)
+(defun my-cgit-revision-url (revision file remote)
+ "Returns the REMOTE cgit instance url of REVISION for FILE.
+
+https://g.ypei.me/dotted.git/commit/?id=851b8f5fac389364c579aabb8e8fba344a3f6929"
+ (let ((repo-url (vc-git-repository-url file remote)))
+ (format "%s/commit/?id=%s" repo-url revision)))
+
+(defun my-cgit-revision-url-default (&optional revision file remote)
+ "Returns the REMOTE cgit instance url of REVISION for FILE.
+
+Same as `my-cgit-revision-url', but all params can be nil, and
+sensible defaults are set first."
+ (setq file (or file (buffer-file-name) default-directory)
+ revision (or revision (vc-working-revision file)))
+ (my-cgit-revision-url revision file remote))
+
+(defun my-cgit-branch-url (branch file remote)
+ "Returns the REMOTE cgit instance url of BRANCH containing FILE.
+
+https://g.ypei.me/librejs.git/?h=noscript-toggle"
+ (let ((repo-url (vc-git-repository-url file remote)))
+ (format "%s/?h=%s" repo-url branch)))
+
+(defun my-cgit-branch-url-default (&optional branch file remote)
+ "Returns the REMOTE cgit instance url of BRANCH containing FILE.
+
+Same as `my-cgit-branch-url', but all params can be nil, and
+sensible defaults are set first."
+ (setq file (or file (buffer-file-name) default-directory)
+ branch (or branch (car (vc-git-branches))))
+ (my-cgit-branch-url branch file remote))
+
+(defun my-cgit-file-url (file line-no revision remote)
+ "Returns the REMOTE cgit instance url of the FILE at LINE-NO at REVISION.
+
+https://g.ypei.me/librejs.git/tree/main_background.js?id=e2230c23e4aa7a74ea34825856acf7edd8a61e04#n78"
+ (let* ((repo-root (vc-git-root file))
+ (path (file-relative-name file repo-root))
+ (repo-url (vc-git-repository-url file remote)))
+ (format "%s/tree/%s?id=%s%s" repo-url path revision
+ (if line-no (format "#n%d" line-no) ""))))
+
+(defun my-cgit-file-url-default (&optional file line-no revision remote)
+ "Returns the REMOTE cgit instance url of the FILE at LINE-NO at REVISION.
+
+Same as `my-cgit-file-url', but all params can be nil, and
+sensible defaults are set first."
+ (unless (setq file (or file (buffer-file-name)))
+ (error "Please supply a file"))
+ (setq revision (or revision (vc-working-revision file)))
+ (my-cgit-file-url file line-no revision remote))
+
+(defun my-cgit-raw-file-url (file revision remote)
+ "Returns the REMOTE cgit instance url of the raw FILE at REVISION.
+
+https://g.ypei.me/librejs.git/plain/main_background.js?id=e2230c23e4aa7a74ea34825856acf7edd8a61e04"
+ (let* ((repo-root (vc-git-root file))
+ (path (file-relative-name file repo-root))
+ (repo-url (vc-git-repository-url file remote)))
+ (format "%s/plain/%s?id=%s" repo-url path revision)))
+
+(defun my-cgit-raw-file-url-default (&optional file revision remote)
+ "Returns the REMOTE cgit instance url of the raw FILE at REVISION.
+
+Same as `my-cgit-raw-file-url', but all params can be nil, and
+sensible defaults are set first."
+ (unless (setq file (or file (buffer-file-name)))
+ (error "Please supply a file"))
+ (setq (revision (or revision (vc-working-revision file))))
+ (my-cgit-raw-file-url file revision remote))
+
+(defun my-cgit-revision-to-url (revision)
+ "Returns the remote cgit instance url of REVISION.
+
+Uses default remote."
+ (let ((file (or (buffer-file-name) default-directory)))
+ (my-cgit-revision-url revision file nil)))
+
+(defun my-cgit-branch-to-url (branch)
+ "Returns the remote cgit instance url of REVISION.
+
+Uses default remote."
+ (let ((file (or (buffer-file-name) default-directory)))
+ (my-cgit-branch-url branch file nil)))
+
+(defun my-cgit-file-to-url (file)
+ "Returns the remote cgit instance url of FILE.
+
+Uses default remote and currently checked out revision."
+ (let ((revision (vc-working-revision file)))
+ (my-cgit-file-url file nil revision nil)))
+
+(defun my-cgit-current-file-to-url ()
+ "Returns the remote cgit instance url of the current buffer file-loc.
+
+Uses default remote and currently checked out revision."
+ (let ((file (buffer-file-name))
+ (line-no (1+ (current-line)))
+ (revision (vc-working-revision file)))
+ (unless file (error "Current buffer is not associated with any file"))
+ (my-cgit-file-url file line-no revision nil)))
+
+(defun my-cgit-file-to-raw-url (file)
+ "Returns the remote cgit instance url of FILE.
+
+Uses default remote and currently checked out revision."
+ (let ((revision (vc-working-revision file)))
+ (my-cgit-raw-file-url file revision nil)))
+
+(defun my-cgit-current-file-to-raw-url ()
+ "Returns the remote cgit instance url of the current buffer file.
+
+Uses default remote and currently checked out revision."
+ (let ((file (buffer-file-name))
+ (revision (vc-working-revision file)))
+ (unless file (error "Current buffer is not associated with any file"))
+ (my-cgit-file-url file revision nil)))
+
+(provide 'my-cgit)
+;;; my-cgit.el ends here
diff --git a/emacs/.emacs.d/lisp/my/my-github.el b/emacs/.emacs.d/lisp/my/my-github.el
index 2fe90fd..dfa159a 100644
--- a/emacs/.emacs.d/lisp/my/my-github.el
+++ b/emacs/.emacs.d/lisp/my/my-github.el
@@ -66,7 +66,117 @@ License; name; description; homepage; created at"
;;; urls with github
;; TODO: generalise the following to common forges, including
-;; savannah, cgit, gitlab etc.
+;; cgit, gitlab etc.
+(defun my-github-revision-url (revision file remote)
+ "Returns the REMOTE github instance url of REVISION for FILE."
+ (let ((repo-url (vc-git-repository-url file remote)))
+ (format "%s/commit/%s" repo-url revision)))
+
+(defun my-github-revision-url-default (&optional revision file remote)
+ "Returns the REMOTE github instance url of REVISION for FILE.
+
+Same as `my-github-revision-url', but all params can be nil, and
+sensible defaults are set first."
+ (setq file (or file (buffer-file-name) default-directory)
+ revision (or revision (vc-working-revision file)))
+ (my-github-revision-url revision file remote))
+
+(defun my-github-branch-url (branch file remote)
+ "Returns the REMOTE github instance url of BRANCH containing FILE.
+
+https://github.com/MariaDB/server/commits/10.4"
+ (let ((repo-url (vc-git-repository-url file remote)))
+ (format "%s/commits/%s" repo-url branch)))
+
+(defun my-github-branch-url-default (&optional branch file remote)
+ "Returns the REMOTE github instance url of BRANCH containing FILE.
+
+Same as `my-github-branch-url', but all params can be nil, and
+sensible defaults are set first."
+ (setq file (or file (buffer-file-name) default-directory)
+ branch (or branch (car (vc-git-branches))))
+ (my-github-branch-url branch file remote))
+
+(defun my-github-file-url (file line-no revision remote)
+ "Returns the REMOTE github instance url of the FILE at LINE-NO at REVISION.
+
+https://github.com/MariaDB/server/blob/0254eb9307f58409f856517a90109d37ef9e10c4/storage/spider/mysql-test/spider/bugfix/r/mdev_31463.result"
+ (let* ((repo-root (vc-git-root file))
+ (path (file-relative-name file repo-root))
+ (repo-url (vc-git-repository-url file remote)))
+ (format "%s/blob/%s/%s" repo-url revision path
+ (if line-no (format "#L%d" line-no) ""))))
+
+(defun my-github-file-url-default (&optional file line-no revision remote)
+ "Returns the REMOTE github instance url of the FILE at LINE-NO at REVISION.
+
+Same as `my-github-file-url', but all params can be nil, and
+sensible defaults are set first."
+ (unless (setq file (or file (buffer-file-name)))
+ (error "Please supply a file"))
+ (setq revision (or revision (vc-working-revision file)))
+ (my-github-file-url file line-no revision remote))
+
+(defun my-github-raw-file-url (file revision remote)
+ "Returns the REMOTE github instance url of the raw FILE at REVISION.
+
+https://g.ypei.me/librejs.git/plain/main_background.js?id=e2230c23e4aa7a74ea34825856acf7edd8a61e04"
+ (let* ((repo-root (vc-git-root file))
+ (path (file-relative-name file repo-root))
+ (repo-url (vc-git-repository-url file remote)))
+ (format "%s/raw/%s/%s" repo-url path revision)))
+
+(defun my-github-raw-file-url-default (&optional file revision remote)
+ "Returns the REMOTE github instance url of the raw FILE at REVISION.
+
+Same as `my-github-raw-file-url', but all params can be nil, and
+sensible defaults are set first."
+ (unless (setq file (or file (buffer-file-name)))
+ (error "Please supply a file"))
+ (setq (revision (or revision (vc-working-revision file))))
+ (my-github-raw-file-url file revision remote))
+
+(defun my-github-revision-to-url (revision)
+ "Returns the remote github instance url of REVISION.
+
+Uses default remote."
+ (let ((file (or (buffer-file-name) default-directory)))
+ (my-github-revision-url revision file nil)))
+
+(defun my-github-file-to-url (file)
+ "Returns the remote github instance url of FILE.
+
+Uses default remote and currently checked out revision."
+ (let ((revision (vc-working-revision file)))
+ (my-github-file-url file nil revision nil)))
+
+(defun my-github-current-file-to-url ()
+ "Returns the remote github instance url of the current buffer file-loc.
+
+Uses default remote and currently checked out revision."
+ (let ((file (buffer-file-name))
+ (line-no (1+ (current-line)))
+ (revision (vc-working-revision file)))
+ (unless file (error "Current buffer is not associated with any file"))
+ (my-github-file-url file line-no revision nil)))
+
+(defun my-github-file-to-raw-url (file)
+ "Returns the remote github instance url of FILE.
+
+Uses default remote and currently checked out revision."
+ (let ((revision (vc-working-revision file)))
+ (my-github-raw-file-url file revision nil)))
+
+(defun my-github-current-file-to-raw-url ()
+ "Returns the remote github instance url of the current buffer file.
+
+Uses default remote and currently checked out revision."
+ (let ((file (buffer-file-name))
+ (revision (vc-working-revision file)))
+ (unless file (error "Current buffer is not associated with any file"))
+ (my-github-file-url file revision nil)))
+
+;; FIXME: remove the following redundant functions
(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))